File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,28 +11,7 @@ public function groupBy($fields)
1111 /**
1212 * @var $this IStatement
1313 */
14-
15- $ groupClause = new GroupByClause ();
16- if (func_num_args () > 1 )
17- {
18- foreach (func_get_args () as $ field )
19- {
20- $ groupClause ->addField ($ field );
21- }
22- }
23- else if (is_array ($ fields ))
24- {
25- foreach ($ fields as $ field )
26- {
27- $ groupClause ->addField ($ field );
28- }
29- }
30- else
31- {
32- $ groupClause ->addField ($ fields );
33- }
34-
35- $ this ->addClause ($ groupClause );
14+ $ this ->addClause (GroupByClause::create (...func_get_args ()));
3615 return $ this ;
3716 }
3817}
Original file line number Diff line number Diff line change @@ -10,4 +10,28 @@ public function getAction()
1010 {
1111 return 'GROUP BY ' ;
1212 }
13+
14+ public static function create ($ fields )
15+ {
16+ $ groupClause = new static ();
17+ if (func_num_args () > 1 )
18+ {
19+ foreach (func_get_args () as $ field )
20+ {
21+ $ groupClause ->addField ($ field );
22+ }
23+ }
24+ else if (is_array ($ fields ))
25+ {
26+ foreach ($ fields as $ field )
27+ {
28+ $ groupClause ->addField ($ field );
29+ }
30+ }
31+ else
32+ {
33+ $ groupClause ->addField ($ fields );
34+ }
35+ return $ groupClause ;
36+ }
1337}
Original file line number Diff line number Diff line change @@ -12,6 +12,16 @@ class SelectClause implements IClause
1212 protected $ _expressions = [];
1313 protected $ _distinct = false ;
1414
15+ public static function create (...$ fields )
16+ {
17+ $ select = new static ();
18+ foreach ($ fields as $ field )
19+ {
20+ $ select ->addField ($ field );
21+ }
22+ return $ select ;
23+ }
24+
1525 public function setDistinct ($ distinct = true )
1626 {
1727 $ this ->_distinct = $ distinct ;
Original file line number Diff line number Diff line change @@ -96,4 +96,13 @@ public function testGettersAndSetters()
9696 $ this ->setExpectedException ("InvalidArgumentException " );
9797 $ clause ->setExpressions ([$ field , $ now , 'abc ' ]);
9898 }
99+
100+ public function testStatic ()
101+ {
102+ $ clause = SelectClause::create ('first ' );
103+ $ clause ->setDistinct (true );
104+ $ this ->assertEquals ('SELECT DISTINCT first ' , QueryAssembler::stringify ($ clause ));
105+
106+ $ this ->assertEquals ('SELECT * ' , QueryAssembler::stringify (SelectClause::create ()));
107+ }
99108}
You can’t perform that action at this time.
0 commit comments