Skip to content

Commit 8e7c4bf

Browse files
committed
Merge branch 'daleattree-master'
2 parents 8be1697 + 8639427 commit 8e7c4bf

16 files changed

+583
-121
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,66 +58,66 @@ myFakeFunction((string)$path);
5858

5959
You can select which properties of the returned objects are included:
6060
```PHP
61-
$path->select(new ODataQuerySelect(array("FirstName", "LastName")));
61+
$path->setSelect(new ODataQuerySelect(array("FirstName", "LastName")));
6262
```
6363
See the Expand section below to learn how select can be applied to specific properties.
6464

6565
<h3>$search</h3>
6666

6767
You can search the properties of the object set using search:
6868
```PHP
69-
$path->search(new ODataQuerySearch('mountain bike'));
69+
$path->setSearch(new ODataQuerySearch('mountain bike'));
7070
```
7171
Search queries are also chainable:
7272
```PHP
73-
$search = $path->search();
73+
$search = $path->getSearch();
7474
// operations functions are both setters and getters. When setting, the funciton returns the $path object for chainability
7575
$search->_and('balloon');
76-
$path->search($search);
76+
$path->setSearch($search);
7777
```
7878
This will now search the set of Employees objects to be returned for '"mountain bike" AND balloon'. See the Expand section below to learn how the search function can be applied to specific properties.
7979

8080
<h3>$count</h3>
8181

8282
You can return the total record count of your query. The $count system query option ignores any $top, $skip, or $expand query options, and returns the total count of results across all pages including only those results matching any specified $filter and $search. Clients should be aware that the count returned inline may not exactly equal the actual number of items returned, due to latency between calculating the count and enumerating the last value or due to inexact calculations on the service.
8383
```PHP
84-
$path->count();
85-
$path->count(FALSE); // Disables $count
84+
$path->getCount();
85+
$path->setCount(FALSE); // Disables $count
8686
```
8787
<h3>$filter</h3>
8888

8989
The recordset queried can be filtered to return a more precise set of records. There are various filters available and most can be used in combination with another.
9090
```PHP
9191
$filter = new ODataGreaterThanEqualsFilter('YearsEmployed', 6); // YearsEmployed ge 6
92-
$path->filter($filter);
92+
$path->setFilter($filter);
9393
```
9494
Each filter has a set of extensible functions that allow the filter to be passed into another filter, returning the new filter.
9595
```PHP
9696
$add_filter = new ODataAddFilter('YearsEmployed', 5); // YearsEmployed add 5
9797
$filter = $add_filter->greaterThanEquals(6); // YearsEmployed add 5 ge 6
98-
$path->filter($filter);
98+
$path->setFilter($filter);
9999
```
100100
Filters can accept Filters as properties or values and a value can also be a property name
101101
```PHP
102102
$sub_filter = new ODataSubtractFilter('YearsEmployed', 'YearsSebatical'); // YearsEmployed sub YearsSebatical
103103
$sub_filter2 = new ODataAddFilter('Awards', 'Demotions'); // Awards sub Demotions
104104
$filter = $sub_filter->greaterThan($sub_filter2); // (YearsEmployed sub YearsSebatical) gt (Awards sub Demotions)
105-
$path->filter($filter);
105+
$path->setFilter($filter);
106106
```
107107
<h3>$pager</h3>
108108

109109
Records can be paged server-side by passing $top and $skip where $top is the limit of records returned and $skip is the start offset. The ODataQueryPager object takes the math out of the equation and lets you simply specify the limit and the page you want to return.
110110
```PHP
111111
$pager = new ODataQueryPager(20, 5); // $top=20&$skip=100
112-
$path->pager($pager);
112+
$path->setPager($pager);
113113
```
114114

115115
<h3>$orderby</h3>
116116

117117
Results can be sorted by a property name within the collection. Simply specify which property you would like to sort by in the orderBy() function.
118118

119119
```PHP
120-
$path->orderBy('LastName');
120+
$path->setOrderBy('LastName');
121121
```
122122

123123
<h3>$expand</h3>

Test/ODataQueryExpandCollectionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public function testExpandWithParameter() {
2121
$item1 = new \ODataQuery\Expand\ODataQueryExpand('TestValue');
2222
$item2 = new \ODataQuery\Expand\ODataQueryExpand('Property');
2323

24-
$item1->limits(4)
25-
->filter(new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator('SubValue', 6))
26-
->select(new \ODataQuery\Select\ODataQuerySelect(array('SubValue', 'OtherValue')))
27-
->search(new \ODataQuery\Search\ODataQuerySearch("mountain bike"));
24+
$item1->setLimits(4)
25+
->setFilter(new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator('SubValue', 6))
26+
->setSelect(new \ODataQuery\Select\ODataQuerySelect(array('SubValue', 'OtherValue')))
27+
->setSearch(new \ODataQuery\Search\ODataQuerySearch("mountain bike"));
2828

29-
$item2->expand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($item1)))
30-
->search(new \ODataQuery\Search\ODataQuerySearch("google"));
29+
$item2->setExpand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($item1)))
30+
->setSearch(new \ODataQuery\Search\ODataQuerySearch("google"));
3131

3232
$collection->add($item2);
3333
$this->assertEquals('Property($search=google&$expand=TestValue($select=SubValue,OtherValue&$filter=SubValue eq 6&$search="mountain bike"&$limits=4))', (string)$collection);

Test/ODataQueryPagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class ODataQueryPagerTest extends PHPUnit_Framework_TestCase {
1010
public function testPager() {
1111
$output = new \ODataQuery\Pager\ODataQueryPager();
1212
$this->assertEquals('$top=500&$skip=0', (string)$output);
13-
$output->limit(20);
14-
$output->page(6);
13+
$output->setLimit(20);
14+
$output->setPage(6);
1515
$this->assertEquals('$top=20&$skip=120', (string)$output);
1616
}
1717
}

Test/ODataQuerySearchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ODataQuerySearchTest extends PHPUnit_Framework_TestCase {
1010
public function testSearch() {
1111
$output = new \ODataQuery\Search\ODataQuerySearch('mountain');
1212
$this->assertEquals('mountain', (string)$output);
13-
$output->query('mountain bike');
13+
$output->setQuery('mountain bike');
1414
$this->assertEquals('"mountain bike"', (string)$output);
1515
}
1616

Test/ODataResourcePathTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ public function testPath() {
1414

1515
public function testSelect() {
1616
$output = new \ODataQuery\ODataResourcePath('api/Objects');
17-
$output->select(new \ODataQuery\Select\ODataQuerySelect(array("Prop1", "Prop2")));
17+
$output->setSelect(new \ODataQuery\Select\ODataQuerySelect(array("Prop1", "Prop2")));
1818
$this->assertEquals('api/Objects?$select=Prop1,Prop2', (string)$output);
1919
}
2020

2121
public function testSearch() {
2222
$output = new \ODataQuery\ODataResourcePath('api/Objects');
23-
$output->search(new \ODataQuery\Search\ODataQuerySearch("mountain bike"));
23+
$output->setSelect(new \ODataQuery\Search\ODataQuerySearch("mountain bike"));
2424
$this->assertEquals('api/Objects?$search="mountain bike"', (string)$output);
2525
}
2626

2727
public function testFilter() {
2828
$output = new \ODataQuery\ODataResourcePath('api/Objects');
29-
$output->filter(new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator("TestValue", 4));
29+
$output->setFilter(new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator("TestValue", 4));
3030
$this->assertEquals('api/Objects?$filter=TestValue eq 4', (string)$output);
3131
}
3232

3333
public function testPager() {
3434
$output = new \ODataQuery\ODataResourcePath('api/Objects');
35-
$output->pager(new \ODataQuery\Pager\ODataQueryPager(50, 4));
35+
$output->setPager(new \ODataQuery\Pager\ODataQueryPager(50, 4));
3636
$this->assertEquals('api/Objects?$top=50&$skip=200', (string)$output);
3737
}
3838

3939
public function testOrderBy() {
4040
$output = new \ODataQuery\ODataResourcePath('api/Objects');
41-
$output->orderBy('Property');
41+
$output->setOrderBy('Property');
4242
$this->assertEquals('api/Objects?$orderby=Property', (string)$output);
4343
}
4444

4545
public function testParameters() {
4646
$output = new \ODataQuery\ODataResourcePath('api/Objects');
4747
$params = new \ODataQuery\Parameter\ODataQueryParameterCollection();
4848
$params->prop = 'Property';
49-
$output->parameters($params);
49+
$output->setParameters($params);
5050
$this->assertEquals('api/Objects?@prop=Property', (string)$output);
5151
$params->test = 'TestProperty';
5252
$this->assertEquals('api/Objects?@prop=Property&@test=TestProperty', (string)$output);
@@ -57,12 +57,12 @@ public function testExpand() {
5757
$params->prop = 'Property';
5858
$output = new \ODataQuery\ODataResourcePath('api/Objects');
5959
$expand = new \ODataQuery\Expand\ODataQueryExpand('@prop');
60-
$expand->search(new \ODataQuery\Search\ODataQuerySearch("google"))
61-
->pager(new \ODataQuery\Pager\ODataQueryPager(20, 5));
60+
$expand->setSearch(new \ODataQuery\Search\ODataQuerySearch("google"))
61+
->setPager(new \ODataQuery\Pager\ODataQueryPager(20, 5));
6262
$expand2 = new \ODataQuery\Expand\ODataQueryExpand("SubProperty", new \ODataQuery\Filter\Operators\Logical\ODataLessThanOperator("SubSubProperty", 4));
63-
$expand->expand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($expand2)));
64-
$output->expand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($expand)));
65-
$output->parameters($params);
63+
$expand->setExpand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($expand2)));
64+
$output->setExpand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($expand)));
65+
$output->setParameters($params);
6666
$this->assertEquals('api/Objects?$expand=@prop($search=google&$expand=SubProperty($filter=SubSubProperty lt 4)&$top=20&$skip=100)&@prop=Property', (string)$output);
6767
}
6868

@@ -72,9 +72,9 @@ public function testExpand2() {
7272
$filter = new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator('FirstName', "'Bob'");
7373

7474
//$query = new \ODataQuery\ODataResource();
75-
$expand->filter($filter->_and(new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator('LastName',
75+
$expand->setFilter($filter->_and(new \ODataQuery\Filter\Operators\Logical\ODataEqualsOperator('LastName',
7676
"'Jones'")));
77-
$query->expand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($expand)));
77+
$query->setExpand(new \ODataQuery\Expand\ODataQueryExpandCollection(array($expand)));
7878
$this->assertEquals("api/Objects?\$expand=PrimaryContact(\$filter=(FirstName eq 'Bob') and (LastName eq 'Jones'))", (string)
7979
$query);
8080
}

composer.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
"minimum-stability": "dev",
55
"prefer-stable": true,
66
"license": "GPL-2.0",
7-
"version": "1.0.1",
8-
"time": "2014-12-29",
9-
"homepage": "http://curiosity26.github.io/ODataQuery-PHP/",
7+
"version": "1.0.2",
8+
"time": "2015-04-23",
109
"authors": [
1110
{
1211
"name": "Alex Boyce",
@@ -15,10 +14,6 @@
1514
"role": "Developer"
1615
}
1716
],
18-
"dist": {
19-
"url": "https://github.com/curiosity26/ODataQuery-PHP.git",
20-
"type": "git"
21-
},
2217
"support": {
2318
"issues": "https://github.com/curiosity26/ODataQuery-PHP/issues",
2419
"wiki": "https://github.com/curiosity26/ODataQuery-PHP/wiki",
@@ -32,4 +27,4 @@
3227
"require-dev": {
3328
"phpunit/phpunit": "4-stable"
3429
}
35-
}
30+
}

src/Expand/ODataExpandableInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111

1212
interface ODataExpandableInterface {
13-
public function property($property = NULL);
14-
public function limits($limits = NULL);
13+
public function setProperty($property = NULL);
14+
public function setLimits($limits = NULL);
15+
public function getProperty();
16+
public function getLimits();
1517
public function __toString();
1618
}

src/Expand/ODataQueryExpand.php

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,52 @@ class ODataQueryExpand extends ODataResource implements ODataExpandableInterface
2222
public function __construct($property = NULL, ODataQueryFilterInterface $filter = NULL,
2323
ODataQuerySelect $select = NULL, ODataResource $expand = NULL, ODataQueryPager $pager = NULL,
2424
ODataQuerySearch $search = NULL, $orderBy = NULL) {
25-
$this->property($property);
25+
$this->setProperty($property);
2626
parent::__construct($filter, $select, $expand, $pager, $search, $orderBy);
2727
}
2828

29+
/**
30+
* Use getter or setter
31+
* Retained for backward compatibility
32+
* @param null $property
33+
* @return $this
34+
* @deprecated
35+
*/
2936
public function property($property = NULL) {
3037
if (isset($property)) {
31-
$this->property = $property;
38+
$this->setProperty($property);
3239
return $this;
3340
}
34-
return $this->property;
41+
return $this->getProperty();
3542
}
3643

44+
/**
45+
* Use getter or setter
46+
* Retained for backward compatibility
47+
* @param null $limits
48+
* @return $this
49+
* @deprecated
50+
*/
3751
public function limits($limits = NULL) {
3852
if (isset($limits)) {
3953
if (is_int($limits)) {
40-
$this->limits = $limits;
54+
$this->setLimits($limits);
4155
return $this;
4256
}
4357
}
44-
return $this->limits;
58+
return $this->getLimits();
4559
}
4660

4761
public function build() {
4862
$build = parent::build();
4963
if ($this->count !== TRUE) {
50-
$build['$limits'] = $this->limits();
64+
$build['$limits'] = $this->getLimits();
5165
}
5266
return array_filter($build);
5367
}
5468

5569
public function __toString() {
56-
$output = (string)$this->property();
70+
$output = (string)$this->getProperty();
5771
$build = $this->build();
5872
$args = array();
5973
if (!empty($build)) {
@@ -69,4 +83,38 @@ public function __toString() {
6983

7084
return $output;
7185
}
86+
87+
/**
88+
* @return mixed
89+
*/
90+
public function getLimits()
91+
{
92+
return $this->limits;
93+
}
94+
95+
/**
96+
* @param mixed $limits
97+
*/
98+
public function setLimits($limits = NULL)
99+
{
100+
$this->limits = $limits;
101+
}
102+
103+
/**
104+
* @return mixed
105+
*/
106+
public function getProperty()
107+
{
108+
return $this->property;
109+
}
110+
111+
/**
112+
* @param mixed $property
113+
*/
114+
public function setProperty($property = NULL)
115+
{
116+
$this->property = $property;
117+
}
118+
119+
72120
}

src/Expand/ODataQueryExpandCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function __construct(array $collection = NULL) {
2626
}
2727

2828
public function add(ODataQueryExpand $item) {
29-
$name = (string)$item->property();
29+
$name = (string)$item->getProperty();
3030
$this->collection[$name] = $item;
3131
return $this;
3232
}
3333

3434
public function remove(ODataQueryExpand $item) {
35-
$name = (string)$item->property();
35+
$name = (string)$item->getProperty();
3636
unset($this->collection[$name]);
3737
return $this;
3838
}

0 commit comments

Comments
 (0)