-
Notifications
You must be signed in to change notification settings - Fork 1
/
MostDataClient.php
1450 lines (1327 loc) · 38.3 KB
/
MostDataClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* MOST Web Framework
* A JavaScript Web Framework
* http://themost.io
*
* Copyright (c) 2015, Kyriakos Barbounakis [email protected], Anthi Oikonomou [email protected]
*
* Released under the BSD3-Clause license
* Date: 2015-02-19
*/
require_once 'HTTP/Request2.php';
require_once 'HTTP/Request2/Adapter/Curl.php';
class Args {
/**
* @param * $arg
* @param string $name
* @throws Exception
*/
public static function notNull($arg, $name) {
if (is_null($arg)) {
throw new Exception($name." may not be null");
}
}
/**
* @param * $arg
* @param string $name
* @throws Exception
*/
public static function notString($arg, $name) {
if (!is_string($arg)) {
throw new Exception($name." must be a string");
}
}
/**
* @param * $arg
* @param string $name
* @throws Exception
*/
public static function notEmpty($arg, $name) {
Args::notNull($arg,$name);
Args::notString($arg,$name);
if (strlen($arg)==0) {
throw new Exception($name." may not be empty");
}
}
/**
* @param * $arg
* @param string $message
* @throws Exception
*/
public static function check($arg, $message) {
if (!$arg) {
throw new Exception($message);
}
}
}
/**
* Represents a common HTTP exception
* Class HttpClientException
*/
class HttpClientException extends Exception {
// Redefine the exception so message isn't optional
public function __construct($message = null, $code = 500, Exception $previous = null) {
// make sure everything is assigned properly
if (is_null($message))
$message = 'Internal Server Error';
parent::__construct($message, $code, $previous);
}
public function __toString() {
return "[{$this->code}] {$this->message}";
}
}
class DynamicObject {
/**
* @param null|array|stdClass|DynamicObject $args
* @throws Exception
*/
public function __construct($args = null) {
if (is_null($args))
return;
if (is_array($args)) {
foreach ($args as $property => $argument) {
$this->{$property} = $argument;
}
}
else if (is_a($args, 'stdClass')) {
DynamicObject::object_to_dynamic($args, $this);
}
else if (is_a($args, 'DynamicObject')) {
$vars = get_object_vars($args);
foreach ($vars AS $property => $value) {
$this->{$property} = $value;
}
}
else {
throw new Exception('Invalid argument');
}
}
/**
* @param stdClass|null|DynamicObject $object
* @param DynamicObject|null $target
* @return array|DynamicObject|null
*/
public static function object_to_dynamic($object, $target = null) {
if (is_null($object))
return null;
if (is_array($object)) {
$arr = array();
foreach ($object as $item) {
array_push($arr,DynamicObject::object_to_dynamic($item));
}
return $arr;
}
if (is_null($target))
$target = new DynamicObject();
$vars = get_object_vars($object);
foreach ($vars AS $key => $value) {
if (is_array($value)) {
$arr = array();
foreach ($value as $item) {
if (is_a($item, 'stdClass'))
array_push($arr,DynamicObject::object_to_dynamic($item));
else
array_push($arr,$item);
}
$target->{$key} = $arr;
}
else if (is_a($value, 'stdClass')) {
$target->{$key} = DynamicObject::object_to_dynamic($value);
}
else {
$target->{$key} = $value;
}
}
return $target;
}
public function __call($method, $arguments) {
$arguments = array_merge(array("DynamicObject" => $this), $arguments); // Note: method argument 0 will always referred to the main class ($this).
if (isset($this->{$method}) && is_callable($this->{$method})) {
return call_user_func_array($this->{$method}, $arguments);
} else {
throw new Exception("Fatal error: Call to undefined method DynamicObject::{$method}()");
}
}
}
/**
* Class ClientDataService
*/
class ClientDataService
{
protected $ssl_verify_host = FALSE;
protected $ssl_verify_peer = FALSE;
private $cookies;
private $url;
/**
* ClientDataService class constructor.
* @param string $url - A string that represents a remote URL that is going to be the target application.
*/
public function __construct($url = null) {
//set model
$this->url = $url;
//init cookies
$this->cookies = array();
}
public function getBase() {
return $this->url;
}
/**
* Sets ClientDataService cookies.
* @param $cookies
*/
public function setCookie($cookies) {
$this->cookies = $cookies;
}
public function authenticate($username, $password) {
//init cookies
$this->cookies = array();
//init request
$request = new HTTP_Request2($this->url, HTTP_Request2::METHOD_HEAD);
try {
$request->setAuth($username, $password);
$response = $request->send();
if (200 == $response->getStatus()) {
//get cookie
$cookies = $response->getCookies();
//add cookie
foreach($cookies as $cookie) {
$this->cookies[$cookie['name']] = $cookie['value'];
}
return true;
} else {
throw new HttpClientException($response->getReasonPhrase(),$response->getStatus());
}
} catch (HTTP_Request2_Exception $e) {
throw new HttpClientException($e->getMessage(),$e->getCode());
}
}
/**
* @param string $relativeUrl - A string that represents the relative URL of the target application.
* @return array|stdClass|*
* @throws Exception
*/
public function get($relativeUrl) {
return $this->execute('GET',$relativeUrl, null);
}
/**
* @param string $relativeUrl - A string that represents the relative URL of the target application.
* @param array|stdClass|* $data
* @return array|stdClass|*
* @throws Exception
*/
public function post($relativeUrl, $data) {
return $this->execute('POST',$relativeUrl, $data);
}
/**
* @param string $relativeUrl - A string that represents the relative URL of the target application.
* @param array|* $data
* @return array|stdClass|*
* @throws Exception
*/
public function put($relativeUrl, $data) {
return $this->execute('PUT',$relativeUrl, $data);
}
/**
* @param string $relativeUrl - A string that represents the relative URL of the target application.
* @param array|* $data
* @return array|stdClass|*
* @throws Exception
*/
public function remove($relativeUrl, $data) {
return $this->execute('DELETE',$relativeUrl, $data);
}
/**
* @param string $relativeUrl - A string that represents the relative URL of the target application.
* @param string $method
* @param array|* $data
* @return array|stdClass|*
* @throws Exception
*/
public function execute($method, $relativeUrl, $data) {
try {
if (is_null($this->url)) {
throw new Exception('Target application base URL cannot be empty at this context.');
}
if (is_null($relativeUrl)) {
throw new Exception('URL cannot be empty at this context.');
}
//build target url
$url = $this->url . $relativeUrl;
//initialize request
$request = new HTTP_Request2($url, $method);
//append cookies
foreach(array_keys($this->cookies) as $key) {
$request->addCookie($key, $this->cookies[$key]);
}
try {
$request->setHeader('Content-Type','application/json');
if (!is_null($data))
$request->setBody(json_encode($data));
$response = $request->send();
if (200 == $response->getStatus()) {
//validate content type
$contentType = $response->getHeader('content-type');
if (strpos($contentType,'application/json')!=-1) {
//try to decode json
$res = json_decode($response->getBody());
return $res;
}
else {
return new DynamicObject();
}
} else {
throw new HttpClientException($response->getReasonPhrase(),$response->getStatus());
}
} catch (HTTP_Request2_Exception $e) {
throw new HttpClientException($e->getMessage(),$e->getCode());
}
}
catch(HttpException $e) {
throw $e;
}
catch(Exception $e) {
print $e;
throw new HttpClientException('Internal Server Error',500);
}
}
}
class ClientDataContext {
private $url;
private $service;
/**
* ClientDataService class constructor.
* @param string $url - A string that represents a remote URL that is going to be the target application.
*/
public function __construct($url) {
//set model
$this->url = $url;
$this->service = new ClientDataService($this->url);
}
/**
* @param string $username
* @param string $password
* @return ClientDataContext
* @throws Exception
*/
public function authenticate($username, $password) {
if (is_null($this->service))
$this->service = new ClientDataService($this->url);
$this->service->authenticate($username, $password);
return $this;
}
/**
* Gets an instance of ClientDataModel class based on the specified model name
* @param string $name
* @throws Exception
* @return ClientDataModel
*/
function model($name) {
Args::notNull($name, "Model name");
return new ClientDataModel($name,$this->service);
}
/**
* Gets the instance of ClientDataService which is associated with this data context.
* @return ClientDataService
*/
public function getService() {
return $this->service;
}
}
class ClientDataModel {
private $name_;
private $url_;
private $service_;
/**
* ClientDataModel class constructor.
* @param string $name - A string which represents the name of this model.
* @param ClientDataService $service - An instance of ClientDataService that is going to be used in data requests.
*/
public function __construct($name, $service) {
Args::notNull($name, "Model name");
$this->name_ = $name;
$this->url_ = "/$name/index.json";
$this->service_ = $service;
}
/**
* Gets the name of this data model
* @return string
*/
public function getName() {
return $this->name_;
}
/**
* Gets the URL which is associated with this data model
* @return string
*/
public function getUrl() {
return $this->url_;
}
/**
* Sets the URL for this data model
* @param string $url
* @return string
*/
public function setUrl($url) {
Args::notNull($url,"Model URL");
Args::check(preg_match("/^https?:\\/\\//i",$url),"Request URL may not be an absolute URI");
if (preg_match("/^\\//i", $url))
$this->url_ = $url;
else
{
$this->url_ = "/".$this->getName()."/".$url;
}
}
/**
* Gets the instance of ClientDataService which is associated with this data model.
* @return ClientDataService
*/
public function getService() {
return $this->service_;
}
/**
* Gets the schema of this data model
* @return stdClass
* @throws HttpClientException
* @throws HttpException
*/
public function getSchema() {
$model = $this->getName();
return $this->getService()->execute("GET", "/$model/schema.json", null);
}
/**
* @param string $field
* @return ClientDataQueryable
*/
public function where($field) {
Args::notNull($field,"Field");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return $res->where($field);
}
/**
* @param ...string $field
* @return ClientDataQueryable
*/
public function select($field) {
Args::notNull($field,"Field");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return call_user_func_array(array($res, "select"), func_get_args());
}
/**
* @param ...string $field
* @return ClientDataQueryable
*/
public function expand($field) {
Args::notNull($field,"Field");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return call_user_func_array(array($res, "expand"), func_get_args());
}
/**
* @param ...string $field
* @return ClientDataQueryable
*/
public function orderBy($field) {
Args::notNull($field,"Field");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return call_user_func_array(array($res, "orderBy"), func_get_args());
}
/**
* @param ...string $field
* @return ClientDataQueryable
*/
public function orderByDescending($field) {
Args::notNull($field,"Field");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return call_user_func_array(array($res, "orderByDescending"), func_get_args());
}
/**
* @param int $num
* @return ClientDataQueryable
*/
public function skip($num) {
Args::notNull($num,"Skip argument");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return $res->skip($num);
}
/**
* @param int $num
* @return ClientDataQueryable
*/
public function take($num) {
Args::notNull($num,"Skip argument");
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return $res->take($num);
}
/**
* @return stdClass[]
*/
public function getItems() {
$res = new ClientDataQueryable($this->getName());
$res->setService($this->getService());
return $res->getItems();
}
/**
* @param * $data
* @return array|stdClass|DynamicObject
* @throws Exception
* @throws HttpClientException
* @throws HttpException
*/
public function save($data) {
Args::notNull($this->getService(),"Client service");
return $this->getService()->execute("POST", $this->getUrl(), $data);
}
/**
* @param * $data
* @return array|stdClass|DynamicObject
* @throws Exception
* @throws HttpClientException
* @throws HttpException
*/
public function remove($data) {
Args::notNull($this->getService(),"Client service");
return $this->getService()->execute("DELETE", $this->getUrl(), $data);
}
}
class DataQueryableOptions
{
/**
* Gets or set a string that contains an open data formatted filter statement, if any.
* @var string
*/
public $filter;
/**
* Gets or sets a comma delimited string that contains the fields to be retrieved.
* @var string
*/
public $select;
/**
* Gets or sets a comma delimited string that contains the fields to be used for ordering the result set.
* @var string
*/
public $order;
/**
* Gets or sets a number that indicates the number of records to retrieve.
* @var int
*/
public $top;
/**
* Gets or sets a number that indicates the number of records to be skipped.
* @var int
*/
public $skip;
/**
* Gets or sets a comma delimited string that contains the fields to be used for grouping the result set.
* @var string
*/
public $group;
/**
* Gets or sets a comma delimited string that contains the models to be expanded.
* @var string
*/
public $expand;
/**
* Gets or sets a boolean that indicates whether paging parameters will be included in the result set.
* @var boolean
*/
public $inlinecount;
/**
* Gets or sets a boolean which indicates whether the result will contain only the first item of the result set.
* @var boolean
*/
public $first;
/**
* Gets or set a string that contains an open data formatted filter statement that is going to be joined with the underlying filter statement, if any.
* @var string
*/
public $prepared;
}
/**
* A FilterExpression instance that is going to be used in open data filter statements
* Class FilterExpression
*/
class FilterExpression {
public $expr;
/**
* @param string $expr
*/
public function __construct($expr) {
$this->expr = $expr;
}
public function __toString(){
return $this->expr;
}
}
/**
* Represents a common HTTP exception
* Class HttpClientException
*/
class MeExpression extends FilterExpression {
public function __construct() {
parent::__construct('me()');
}
}
/**
* Class ClientDataQueryable
*/
class ClientDataQueryable
{
/**
* Gets or sets the underlying ClientDataService instance
* @var null|ClientDataService
*/
public $service;
/**
* @var null|string
*/
protected $model;
/**
* Gets or sets in-process operator
* @var null|string
*/
private $left;
/**
* Gets or sets in-process operator
* @var null|string
*/
private $op;
/**
* Gets or sets in-process operator
* @var null|string
*/
private $lop;
/**
* Gets or sets in-process prepared operator
* @var null|string
*/
private $prepared_lop;
/**
* Gets or sets in-process operator
* @var *
*/
private $right;
/**
* @var null|DataQueryableOptions
*/
protected $options;
/**
* Gets or sets the target URL based on the current model
* @var *
*/
protected $get_url;
/**
* Gets or sets the target URL for POST operations based on the current model
* @var *
*/
protected $post_url;
/**
* Gets or sets the key of the related item if any
* @var *
*/
private $key;
/**
* ClientDataQueryable class constructor.
* @param string $model - A string that represents the target model for this object.
*/
public function __construct($model) {
//set model
$this->model = $model;
//set get url
$this->get_url = "/$model/index.json";
//set post url
$this->post_url = "/$model/edit.json";
//init options
$this->options = new DataQueryableOptions();
//set inline count to true
$this->options->inlinecount=true;
}
/**
* Gets the name of the associated data model.
* @return ClientDataService
*/
public function getModel() {
return $this->model;
}
/**
* Gets the instance of ClientDataService which is associated with this data queryable.
* @return ClientDataService
*/
public function getService() {
return $this->service;
}
/**
* Sets the instance of ClientDataService which is associated with this data queryable.
* @param ClientDataService $service
* @return ClientDataQueryable
*/
public function setService($service) {
$this->service = $service;
return $this;
}
const EXCEPTION_INVALID_RIGHT_OP = 'Invalid right operand assignment. Left operand cannot be empty at this context.';
const EXCEPTION_NOT_NULL = 'Value cannot be null at this context.';
/**
* @param int $num
* @return ClientDataQueryable
* @throws Exception
* @throws HttpException
*/
public function take($num) {
$this->options->top = $num;
$this->options->first = false;
$this->options->inlinecount=false;
return $this;
}
/**
* @return stdClass
* @throws Exception
* @throws HttpException
*/
public function first() {
$this->options->skip = 0;
$this->options->top = 0;
$this->options->inlinecount = false;
$this->options->first = true;
return $this->service->execute("GET", $this->get_url.$this->build_options_query(), null);
}
/**
* @return stdClass
* @throws Exception
* @throws HttpException
*/
public function getItem() {
return $this->first();
}
/**
* @return stdClass
* @deprecated Use ClientDataQueryable.getItem() instead
* @throws Exception
* @throws HttpException
*/
public function item() {
return $this->getItem();
}
/**
* @return stdClass[]
* @throws Exception
* @throws HttpException
*/
public function getItems() {
$this->options->inlinecount = false;
return $this->service->execute("GET", $this->get_url.$this->build_options_query(), null);
}
/**
* @throws Exception
* @throws HttpException
*/
public function getList() {
$this->options->first = false;
$this->options->inlinecount = true;
return $this->service->execute("GET", $this->get_url.$this->build_options_query(), null);
}
/**
* @return stdClass[]
* @deprecated Use ClientDataQueryable.getItems() instead
* @throws Exception
* @throws HttpException
*/
public function items() {
return $this->getItems();
}
private function join_filters($filter1=null, $filter2=null)
{
if (is_string($filter1)) {
if (is_null($this->prepared_lop))
$this->prepared_lop='and';
if (is_string($filter2)) {
return '('.$filter1.') '.$this->prepared_lop.' ('.$filter2.')';
}
else {
return $filter1;
}
}
else {
return $filter2;
}
}
private function build_options_query() {
if (is_null($this->options))
return '';
//enumerate options
$vars = get_object_vars($this->options);
if (is_string($vars['prepared'])) {
$vars['filter'] = $this->join_filters($vars['prepared'], $vars['filter']);
$vars['prepared']=null;
}
$query = array();
while (list($key, $val) = each($vars)) {
if (!is_null($val)) {
if (is_bool($val))
array_push($query, '$'.$key.'='.($val ? 'true' : 'false'));
else
array_push($query, '$'.$key.'='.$val);
}
}
if (count($query)>0) {
return "?".implode('&',$query);
}
else {
return '';
}
}
/**
* @param int $num
* @return ClientDataQueryable
*/
public function skip($num = 0) {
$this->options->skip = $num;
return $this;
}
/**
* @param int $num
* @return ClientDataQueryable
*/
public function top($num = 25) {
if ($num<0)
return $this;
$this->options->top = $num;
return $this;
}
/**
* @return ClientDataQueryable
*/
public function prepare() {
if (is_null($this->options->filter))
return $this;
//append filter statement
$this->options->prepared = $this->join_filters($this->options->prepared, $this->options->filter);
//destroy filter statement
$this->options->filter=null;
return $this;
}
/**
* Prepares a logical OR query expression.
* Note: The common ClientDataQueryable.or() method cannot be used because and is a reserved word for PHP.
* @param string $field
* @return ClientDataQueryable
*/
public function either($field = null) {
Args::notNull($field,"Field");
$this->lop = 'or';
$this->left = $field;
$this->lop = 'or';
return $this;
}
/**
* Prepares a logical AND query expression.
* Note: The common ClientDataQueryable.and() method cannot be used because and is a reserved word for PHP.
* @param string $field
* @return ClientDataQueryable
*/
public function also($field) {
Args::notNull($field,"Field");
$this->lop = 'and';
$this->left = $field;
return $this;
}
/**
* @param string $field
* @return ClientDataQueryable
*/
public function andAlso($field) {
if (is_null($field))
return $this;
$this->prepare();
$this->prepared_lop = 'and';
$this->left = $field;
return $this;
}
/**
* @param string $field
* @return ClientDataQueryable
*/
public function orElse($field) {
if (is_null($field))
return $this;
$this->prepare();
$this->prepared_lop = 'or';
$this->left = $field;
return $this;
}
/**
* @param string $field
* @return ClientDataQueryable
*/
public function where($field) {
Args::notNull($field,"Field");
//set in-process field
$this->left = $field;
return $this;
}
/**
* @param ...string $field
* @return ClientDataQueryable
* @throws Exception
*/
public function select($field) {
$arg_list = func_get_args();
if (count($arg_list)>0) {
$this->options->select = implode(',', $arg_list);
}
else {
throw new Exception('Invalid argument. Expected string.');
}
return $this;
}
/**
* @param ...string $field
* @return ClientDataQueryable
* @throws Exception
*/
public function groupBy($field) {
$arg_list = func_get_args();
if (count($arg_list)>0) {
$this->options->group = implode(',', $arg_list);
}
else {
throw new Exception('Invalid argument. Expected string.');
}
return $this;
}
/**
* @param ...string $field
* @return ClientDataQueryable
* @throws Exception
*/
public function expand($field) {
$arg_list = func_get_args();
if (count($arg_list)>0) {
$this->options->expand = implode(',', $arg_list);
}
else {
throw new Exception('Invalid argument. Expected string.');
}
return $this;
}