File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 66use Kir \MySQL \Builder \DBExpr ;
77use Kir \MySQL \Builder \Expr \OptionalExpression ;
88use Kir \MySQL \Builder \Select ;
9+ use Kir \MySQL \Common \SpecialTable ;
910use Kir \MySQL \Tools \VirtualTable ;
1011use Stringable ;
1112
1213/**
13- * @phpstan-type DBTableNameType string|array<int, null|scalar|array<string, null|scalar>>|Select|VirtualTable
14+ * @phpstan-type DBTableNameType string|array<int, null|scalar|array<string, null|scalar>>|Select|VirtualTable|SpecialTable
1415 * @phpstan-type DBFetchRowsCallableReturnType string|array<int, array<string, null|scalar>>|Select|VirtualTable
1516 *
1617 * @phpstan-type DBParameterValueType null|scalar|Stringable|DBExpr|Select|DateTimeInterface|array<null|scalar|Stringable>
Original file line number Diff line number Diff line change 22namespace Kir \MySQL \Builder \Traits ;
33
44use Kir \MySQL \Builder \Internal \Types ;
5+ use Kir \MySQL \Common \SpecialTable ;
56use Kir \MySQL \Database ;
67use Kir \MySQL \Tools \VirtualTable ;
78
@@ -17,14 +18,15 @@ trait TableNameBuilder {
1718 * @return string
1819 */
1920 protected function buildTableName (?string $ alias , $ name ): string {
20- if (is_object ($ name ) && !($ name instanceof VirtualTable) && method_exists ($ name , '__toString ' )) {
21+ if ($ name instanceof SpecialTable) {
22+ $ name = $ name ->asString ($ this ->db ());
23+ } elseif (is_object ($ name ) && !($ name instanceof VirtualTable) && method_exists ($ name , '__toString ' )) {
2124 $ name = (string ) $ name ;
2225 $ lines = explode ("\n" , $ name );
2326 $ lines = array_map (static fn (string $ line ) => "\t{$ line }" , $ lines );
2427 $ name = implode ("\n" , $ lines );
2528 $ name = '( ' . trim (rtrim (trim ($ name ), '; ' )) . ') ' ;
26- }
27- if (is_array ($ name )) {
29+ } elseif (is_array ($ name )) {
2830 $ parts = [];
2931 foreach ($ name as /*$index => */ $ bucket ) {
3032 if (is_scalar ($ bucket )/* && ctype_digit((string) $index)*/ ) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Kir \MySQL \Common ;
4+
5+ use Kir \MySQL \Database ;
6+
7+ interface SpecialTable {
8+ public function asString (Database $ db ): string ;
9+ }
You can’t perform that action at this time.
0 commit comments