@@ -71,21 +71,21 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | $isSingleResult = $request->isSingleResult(); |
| 73 | 73 | |
| 74 | - //$top, $skip, $order, $inlinecount & $count are only applicable if: |
|
| 75 | - //The query targets a resource collection |
|
| 74 | + //$top, $skip, $order, $inlinecount & $count are only applicable if: |
|
| 75 | + //The query targets a resource collection |
|
| 76 | 76 | $this->_setQueryApplicable = ($request->getTargetKind() == TargetKind::RESOURCE() && !$isSingleResult); |
| 77 | - //Or it's a $count resource (although $inlinecount isn't applicable in this case..but there's a check somewhere else for this |
|
| 78 | - $this->_setQueryApplicable |= $request->queryType == QueryType::COUNT(); |
|
| 77 | + //Or it's a $count resource (although $inlinecount isn't applicable in this case..but there's a check somewhere else for this |
|
| 78 | + $this->_setQueryApplicable |= $request->queryType == QueryType::COUNT(); |
|
| 79 | 79 | |
| 80 | - //Paging is allowed if |
|
| 81 | - //The request targets a resource collection |
|
| 82 | - //and the request isn't for a $count segment |
|
| 83 | - $this->_pagingApplicable = $this->request->getTargetKind() == TargetKind::RESOURCE() && !$isSingleResult && ($request->queryType != QueryType::COUNT()); |
|
| 80 | + //Paging is allowed if |
|
| 81 | + //The request targets a resource collection |
|
| 82 | + //and the request isn't for a $count segment |
|
| 83 | + $this->_pagingApplicable = $this->request->getTargetKind() == TargetKind::RESOURCE() && !$isSingleResult && ($request->queryType != QueryType::COUNT()); |
|
| 84 | 84 | |
| 85 | - $targetResourceType = $this->request->getTargetResourceType(); |
|
| 85 | + $targetResourceType = $this->request->getTargetResourceType(); |
|
| 86 | 86 | $targetResourceSetWrapper = $this->request->getTargetResourceSetWrapper(); |
| 87 | 87 | |
| 88 | - $this->_expandSelectApplicable = !is_null($targetResourceType) |
|
| 88 | + $this->_expandSelectApplicable = !is_null($targetResourceType) |
|
| 89 | 89 | && !is_null($targetResourceSetWrapper) |
| 90 | 90 | && $targetResourceType->getResourceTypeKind() == ResourceTypeKind::ENTITY |
| 91 | 91 | && !$this->request->isLinkUri(); |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | || $kind == TargetKind::COMPLEX_OBJECT() |
| 271 | 271 | || $this->request->queryType == QueryType::COUNT() ) |
| 272 | 272 | ) { |
| 273 | - throw ODataException::createBadRequestError( |
|
| 273 | + throw ODataException::createBadRequestError( |
|
| 274 | 274 | Messages::queryProcessorQueryFilterOptionNotApplicable() |
| 275 | 275 | ); |
| 276 | 276 | } |
@@ -296,27 +296,27 @@ discard block |
||
| 296 | 296 | { |
| 297 | 297 | $inlineCount = $this->service->getHost()->getQueryStringItem( ODataConstants::HTTPQUERY_STRING_INLINECOUNT ); |
| 298 | 298 | |
| 299 | - //If it's not specified, we're done |
|
| 300 | - if(is_null($inlineCount)) return; |
|
| 299 | + //If it's not specified, we're done |
|
| 300 | + if(is_null($inlineCount)) return; |
|
| 301 | 301 | |
| 302 | - //If the service doesn't allow count requests..then throw an exception |
|
| 302 | + //If the service doesn't allow count requests..then throw an exception |
|
| 303 | 303 | if (!$this->service->getConfiguration()->getAcceptCountRequests()) { |
| 304 | - throw ODataException::createBadRequestError( |
|
| 304 | + throw ODataException::createBadRequestError( |
|
| 305 | 305 | Messages::configurationCountNotAccepted() |
| 306 | 306 | ); |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $inlineCount = trim($inlineCount); |
| 310 | 310 | |
| 311 | - //if it's set to none, we don't do inline counts |
|
| 311 | + //if it's set to none, we don't do inline counts |
|
| 312 | 312 | if ($inlineCount === ODataConstants::URI_ROWCOUNT_OFFOPTION) { |
| 313 | 313 | return; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - //You can't specify $count & $inlinecount together |
|
| 317 | - //TODO: ensure there's a test for this case see #55 |
|
| 316 | + //You can't specify $count & $inlinecount together |
|
| 317 | + //TODO: ensure there's a test for this case see #55 |
|
| 318 | 318 | if ($this->request->queryType == QueryType::COUNT() ) { |
| 319 | - throw ODataException::createBadRequestError( |
|
| 319 | + throw ODataException::createBadRequestError( |
|
| 320 | 320 | Messages::queryProcessorInlineCountWithValueCount() |
| 321 | 321 | ); |
| 322 | 322 | } |
@@ -325,13 +325,13 @@ discard block |
||
| 325 | 325 | |
| 326 | 326 | |
| 327 | 327 | if ($inlineCount === ODataConstants::URI_ROWCOUNT_ALLOPTION) { |
| 328 | - $this->request->queryType = QueryType::ENTITIES_WITH_COUNT(); |
|
| 328 | + $this->request->queryType = QueryType::ENTITIES_WITH_COUNT(); |
|
| 329 | 329 | |
| 330 | 330 | $this->request->raiseMinVersionRequirement( 2, 0 ); |
| 331 | 331 | $this->request->raiseResponseVersion( 2, 0 ); |
| 332 | 332 | |
| 333 | 333 | } else { |
| 334 | - throw ODataException::createBadRequestError( |
|
| 334 | + throw ODataException::createBadRequestError( |
|
| 335 | 335 | Messages::queryProcessorInvalidInlineCountOptionError() |
| 336 | 336 | ); |
| 337 | 337 | } |
@@ -361,13 +361,13 @@ discard block |
||
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | if (!$this->_pagingApplicable) { |
| 364 | - throw ODataException::createBadRequestError( |
|
| 364 | + throw ODataException::createBadRequestError( |
|
| 365 | 365 | Messages::queryProcessorSkipTokenNotAllowed() |
| 366 | 366 | ); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | if (!$this->_isSSPagingRequired()) { |
| 370 | - throw ODataException::createBadRequestError( |
|
| 370 | + throw ODataException::createBadRequestError( |
|
| 371 | 371 | Messages::queryProcessorSkipTokenCannotBeAppliedForNonPagedResourceSet($this->request->getTargetResourceSetWrapper()) |
| 372 | 372 | ); |
| 373 | 373 | } |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | if (!is_null($select)) { |
| 414 | 414 | if (!$this->service->getConfiguration()->getAcceptProjectionRequests()) { |
| 415 | - throw ODataException::createBadRequestError( Messages::configurationProjectionsNotAccepted() ); |
|
| 415 | + throw ODataException::createBadRequestError( Messages::configurationProjectionsNotAccepted() ); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | $this->_checkExpandOrSelectApplicable( ODataConstants::HTTPQUERY_STRING_SELECT ); |
@@ -423,19 +423,19 @@ discard block |
||
| 423 | 423 | // 'RootProjectionNode' is required while generating next page Link |
| 424 | 424 | if ($this->_expandSelectApplicable || $this->request->isLinkUri() ) { |
| 425 | 425 | |
| 426 | - $rootProjectionNode = ExpandProjectionParser::parseExpandAndSelectClause( |
|
| 427 | - $this->request->getTargetResourceSetWrapper(), |
|
| 428 | - $this->request->getTargetResourceType(), |
|
| 429 | - $this->request->getInternalOrderByInfo(), |
|
| 430 | - $this->request->getSkipCount(), |
|
| 431 | - $this->request->getTopCount(), |
|
| 432 | - $expand, |
|
| 433 | - $select, |
|
| 434 | - $this->service->getProvidersWrapper() |
|
| 435 | - ); |
|
| 436 | - if ($rootProjectionNode->isSelectionSpecified()) { |
|
| 437 | - $this->request->raiseMinVersionRequirement(2, 0 ); |
|
| 438 | - } |
|
| 426 | + $rootProjectionNode = ExpandProjectionParser::parseExpandAndSelectClause( |
|
| 427 | + $this->request->getTargetResourceSetWrapper(), |
|
| 428 | + $this->request->getTargetResourceType(), |
|
| 429 | + $this->request->getInternalOrderByInfo(), |
|
| 430 | + $this->request->getSkipCount(), |
|
| 431 | + $this->request->getTopCount(), |
|
| 432 | + $expand, |
|
| 433 | + $select, |
|
| 434 | + $this->service->getProvidersWrapper() |
|
| 435 | + ); |
|
| 436 | + if ($rootProjectionNode->isSelectionSpecified()) { |
|
| 437 | + $this->request->raiseMinVersionRequirement(2, 0 ); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | if ($rootProjectionNode->hasPagedExpandedResult()) { |
| 441 | 441 | $this->request->raiseResponseVersion( 2, 0 ); |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | || !is_null($serviceHost->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_SKIPTOKEN)) |
| 534 | 534 | || !is_null($serviceHost->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_TOP)) |
| 535 | 535 | ) { |
| 536 | - throw ODataException::createBadRequestError( |
|
| 536 | + throw ODataException::createBadRequestError( |
|
| 537 | 537 | Messages::queryProcessorNoQueryOptionsApplicable() |
| 538 | 538 | ); |
| 539 | 539 | } |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | private function _checkSetQueryApplicable() |
| 552 | 552 | { |
| 553 | 553 | if (!$this->_setQueryApplicable) { |
| 554 | - throw ODataException::createBadRequestError( |
|
| 554 | + throw ODataException::createBadRequestError( |
|
| 555 | 555 | Messages::queryProcessorQuerySetOptionsNotApplicable() |
| 556 | 556 | ); |
| 557 | 557 | } |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | private function _checkExpandOrSelectApplicable($queryItem) |
| 573 | 573 | { |
| 574 | 574 | if (!$this->_expandSelectApplicable) { |
| 575 | - throw ODataException::createBadRequestError( |
|
| 575 | + throw ODataException::createBadRequestError( |
|
| 576 | 576 | Messages::queryProcessorSelectOrExpandOptionNotApplicable($queryItem) |
| 577 | 577 | ); |
| 578 | 578 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | $orderByPathSegments = $internalOrderByInfo->getOrderByPathSegments(); |
| 67 | 67 | $orderByPathCount = count($orderByPathSegments); |
| 68 | 68 | if ($count != ($orderByPathCount)) { |
| 69 | - throw ODataException::createBadRequestError( |
|
| 69 | + throw ODataException::createBadRequestError( |
|
| 70 | 70 | Messages::skipTokenParserSkipTokenNotMatchingOrdering( |
| 71 | 71 | $count, $skipToken, $orderByPathCount |
| 72 | 72 | ) |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | private $requiredMinRequestVersion; |
| 77 | 77 | |
| 78 | - /** @var Version */ |
|
| 79 | - private $maxServiceVersion; |
|
| 78 | + /** @var Version */ |
|
| 79 | + private $maxServiceVersion; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Collection of known data service versions. |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | private $_containerName; |
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * The count option specified in the request. |
|
| 119 | - * |
|
| 120 | - * @var QueryType |
|
| 121 | - */ |
|
| 122 | - public $queryType; |
|
| 117 | + /** |
|
| 118 | + * The count option specified in the request. |
|
| 119 | + * |
|
| 120 | + * @var QueryType |
|
| 121 | + */ |
|
| 122 | + public $queryType; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Number of segments. |
@@ -213,36 +213,36 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | |
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * @param SegmentDescriptor[] $segmentDescriptors Description of segments in the resource path. |
|
| 218 | - * @param Url $requestUri |
|
| 219 | - * @param Version $serviceMaxVersion |
|
| 220 | - * @param $requestVersion |
|
| 221 | - * @param $maxRequestVersion |
|
| 222 | - */ |
|
| 223 | - public function __construct($segmentDescriptors, Url $requestUri, Version $serviceMaxVersion, $requestVersion, $maxRequestVersion) |
|
| 216 | + /** |
|
| 217 | + * @param SegmentDescriptor[] $segmentDescriptors Description of segments in the resource path. |
|
| 218 | + * @param Url $requestUri |
|
| 219 | + * @param Version $serviceMaxVersion |
|
| 220 | + * @param $requestVersion |
|
| 221 | + * @param $maxRequestVersion |
|
| 222 | + */ |
|
| 223 | + public function __construct($segmentDescriptors, Url $requestUri, Version $serviceMaxVersion, $requestVersion, $maxRequestVersion) |
|
| 224 | 224 | { |
| 225 | 225 | $this->segments = $segmentDescriptors; |
| 226 | 226 | $this->_segmentCount = count($this->segments); |
| 227 | 227 | $this->requestUrl = $requestUri; |
| 228 | 228 | $this->lastSegment = $segmentDescriptors[$this->_segmentCount - 1]; |
| 229 | - $this->queryType = QueryType::ENTITIES(); |
|
| 229 | + $this->queryType = QueryType::ENTITIES(); |
|
| 230 | 230 | |
| 231 | 231 | //we use this for validation checks down in validateVersions...but maybe we should check that outside of this object... |
| 232 | 232 | $this->maxServiceVersion = $serviceMaxVersion; |
| 233 | 233 | |
| 234 | - //Per OData 1 & 2 spec we must return the smallest size |
|
| 235 | - //We start at 1.0 and move it up as features are requested |
|
| 234 | + //Per OData 1 & 2 spec we must return the smallest size |
|
| 235 | + //We start at 1.0 and move it up as features are requested |
|
| 236 | 236 | $this->requiredMinResponseVersion = clone Version::v1(); |
| 237 | 237 | $this->requiredMinRequestVersion = clone Version::v1(); |
| 238 | 238 | |
| 239 | 239 | |
| 240 | - //see http://www.odata.org/documentation/odata-v2-documentation/overview/#ProtocolVersioning |
|
| 241 | - //if requestVersion isn't there, use Service Max Version |
|
| 242 | - $this->requestVersion = is_null($requestVersion) ? $serviceMaxVersion : self::parseVersionHeader($requestVersion, ODataConstants::ODATAVERSIONHEADER); |
|
| 240 | + //see http://www.odata.org/documentation/odata-v2-documentation/overview/#ProtocolVersioning |
|
| 241 | + //if requestVersion isn't there, use Service Max Version |
|
| 242 | + $this->requestVersion = is_null($requestVersion) ? $serviceMaxVersion : self::parseVersionHeader($requestVersion, ODataConstants::ODATAVERSIONHEADER); |
|
| 243 | 243 | |
| 244 | - //if max version isn't there, use the request version |
|
| 245 | - $this->requestMaxVersion = is_null($maxRequestVersion) ? $this->requestVersion : self::parseVersionHeader($maxRequestVersion, ODataConstants::ODATAMAXVERSIONHEADER); |
|
| 244 | + //if max version isn't there, use the request version |
|
| 245 | + $this->requestMaxVersion = is_null($maxRequestVersion) ? $this->requestVersion : self::parseVersionHeader($maxRequestVersion, ODataConstants::ODATAMAXVERSIONHEADER); |
|
| 246 | 246 | |
| 247 | 247 | //if it's OData v3..things change a bit |
| 248 | 248 | if($this->maxServiceVersion == Version::v3()){ |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | public function raiseMinVersionRequirement($major, $minor) { |
| 285 | 285 | if($this->requiredMinRequestVersion->raiseVersion($major, $minor)) |
| 286 | 286 | { |
| 287 | - $this->validateVersions(); |
|
| 287 | + $this->validateVersions(); |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | public function raiseResponseVersion($major, $minor) { |
| 301 | 301 | if($this->requiredMinResponseVersion->raiseVersion($major, $minor)){ |
| 302 | - $this->validateVersions(); |
|
| 302 | + $this->validateVersions(); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | } |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | public function getResponseVersion() |
| 811 | 811 | { |
| 812 | 812 | |
| 813 | - return $this->requiredMinResponseVersion; |
|
| 813 | + return $this->requiredMinResponseVersion; |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | /** |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | { |
| 839 | 839 | if (is_null(self::$_knownDataServiceVersions)) { |
| 840 | 840 | self::$_knownDataServiceVersions = array( |
| 841 | - new Version(1, 0), |
|
| 841 | + new Version(1, 0), |
|
| 842 | 842 | new Version(2, 0), |
| 843 | 843 | new Version(3, 0) |
| 844 | 844 | ); |
@@ -867,32 +867,32 @@ discard block |
||
| 867 | 867 | */ |
| 868 | 868 | public function validateVersions() { |
| 869 | 869 | |
| 870 | - //If the request version is below the minimum version required by supplied request arguments..throw an exception |
|
| 870 | + //If the request version is below the minimum version required by supplied request arguments..throw an exception |
|
| 871 | 871 | if ($this->requestVersion->compare($this->requiredMinRequestVersion) < 0) { |
| 872 | - throw ODataException::createBadRequestError( |
|
| 872 | + throw ODataException::createBadRequestError( |
|
| 873 | 873 | Messages::requestVersionTooLow( |
| 874 | - $this->requestVersion->toString(), |
|
| 875 | - $this->requiredMinRequestVersion->toString() |
|
| 874 | + $this->requestVersion->toString(), |
|
| 875 | + $this->requiredMinRequestVersion->toString() |
|
| 876 | 876 | ) |
| 877 | 877 | ); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - //If the requested max version is below the version required to fulfill the response...throw an exception |
|
| 880 | + //If the requested max version is below the version required to fulfill the response...throw an exception |
|
| 881 | 881 | if ($this->requestMaxVersion->compare($this->requiredMinResponseVersion) < 0) { |
| 882 | - throw ODataException::createBadRequestError( |
|
| 882 | + throw ODataException::createBadRequestError( |
|
| 883 | 883 | Messages::requestVersionTooLow( |
| 884 | - $this->requestMaxVersion->toString(), |
|
| 885 | - $this->requiredMinResponseVersion->toString() |
|
| 884 | + $this->requestMaxVersion->toString(), |
|
| 885 | + $this->requiredMinResponseVersion->toString() |
|
| 886 | 886 | ) |
| 887 | 887 | ); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | //If the max version supported by the service is below the version required to fulfill the response..throw an exception |
| 891 | 891 | if ($this->maxServiceVersion->compare($this->requiredMinResponseVersion) < 0) { |
| 892 | - throw ODataException::createBadRequestError( |
|
| 892 | + throw ODataException::createBadRequestError( |
|
| 893 | 893 | Messages::requestVersionIsBiggerThanProtocolVersion( |
| 894 | - $this->requiredMinResponseVersion->toString(), |
|
| 895 | - $this->maxServiceVersion->toString() |
|
| 894 | + $this->requiredMinResponseVersion->toString(), |
|
| 895 | + $this->maxServiceVersion->toString() |
|
| 896 | 896 | ) |
| 897 | 897 | ); |
| 898 | 898 | } |
@@ -923,9 +923,9 @@ discard block |
||
| 923 | 923 | for ($i = 0; $i < $libNameIndex; $i++) { |
| 924 | 924 | if ($versionHeader[$i] == '.') { |
| 925 | 925 | |
| 926 | - //Throw an exception if we find more than 1 dot |
|
| 927 | - if ($dotIndex != -1) { |
|
| 928 | - throw ODataException::createBadRequestError( |
|
| 926 | + //Throw an exception if we find more than 1 dot |
|
| 927 | + if ($dotIndex != -1) { |
|
| 928 | + throw ODataException::createBadRequestError( |
|
| 929 | 929 | Messages::requestDescriptionInvalidVersionHeader( |
| 930 | 930 | $versionHeader, |
| 931 | 931 | $headerName |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | |
| 936 | 936 | $dotIndex = $i; |
| 937 | 937 | } else if ($versionHeader[$i] < '0' || $versionHeader[$i] > '9') { |
| 938 | - throw ODataException::createBadRequestError( |
|
| 938 | + throw ODataException::createBadRequestError( |
|
| 939 | 939 | Messages::requestDescriptionInvalidVersionHeader( |
| 940 | 940 | $versionHeader, |
| 941 | 941 | $headerName |
@@ -945,14 +945,14 @@ discard block |
||
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | |
| 948 | - $major = intval(substr($versionHeader, 0, $dotIndex)); |
|
| 949 | - $minor = 0; |
|
| 948 | + $major = intval(substr($versionHeader, 0, $dotIndex)); |
|
| 949 | + $minor = 0; |
|
| 950 | 950 | |
| 951 | - //Apparently the . is optional |
|
| 951 | + //Apparently the . is optional |
|
| 952 | 952 | if ($dotIndex != -1) { |
| 953 | 953 | if ($dotIndex == 0) { |
| 954 | - //If it starts with a ., throw an exception |
|
| 955 | - throw ODataException::createBadRequestError( |
|
| 954 | + //If it starts with a ., throw an exception |
|
| 955 | + throw ODataException::createBadRequestError( |
|
| 956 | 956 | Messages::requestDescriptionInvalidVersionHeader( |
| 957 | 957 | $versionHeader, |
| 958 | 958 | $headerName |
@@ -965,8 +965,8 @@ discard block |
||
| 965 | 965 | |
| 966 | 966 | $version = new Version($major, $minor); |
| 967 | 967 | |
| 968 | - //TODO: move this somewhere... |
|
| 969 | - /* |
|
| 968 | + //TODO: move this somewhere... |
|
| 969 | + /* |
|
| 970 | 970 | $isSupportedVersion = false; |
| 971 | 971 | foreach (self::getKnownDataServiceVersions() as $version1) { |
| 972 | 972 | if ($version->compare($version1) == 0) { |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * or in case of any version incompatibility. |
| 32 | 32 | */ |
| 33 | 33 | public static function process(IService $service) { |
| 34 | - $host = $service->getHost(); |
|
| 34 | + $host = $service->getHost(); |
|
| 35 | 35 | $absoluteRequestUri = $host->getAbsoluteRequestUri(); |
| 36 | 36 | $absoluteServiceUri = $host->getAbsoluteServiceUri(); |
| 37 | 37 | |
@@ -49,15 +49,15 @@ discard block |
||
| 49 | 49 | $request = new RequestDescription( |
| 50 | 50 | $segments, |
| 51 | 51 | $absoluteRequestUri, |
| 52 | - $service->getConfiguration()->getMaxDataServiceVersion(), |
|
| 53 | - $host->getRequestVersion(), |
|
| 54 | - $host->getRequestMaxVersion() |
|
| 52 | + $service->getConfiguration()->getMaxDataServiceVersion(), |
|
| 53 | + $host->getRequestVersion(), |
|
| 54 | + $host->getRequestMaxVersion() |
|
| 55 | 55 | ); |
| 56 | 56 | $kind = $request->getTargetKind(); |
| 57 | 57 | |
| 58 | - if ($kind == TargetKind::METADATA() || $kind == TargetKind::BATCH() || $kind == TargetKind::SERVICE_DIRECTORY()){ |
|
| 59 | - return $request; |
|
| 60 | - } |
|
| 58 | + if ($kind == TargetKind::METADATA() || $kind == TargetKind::BATCH() || $kind == TargetKind::SERVICE_DIRECTORY()){ |
|
| 59 | + return $request; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | // http://odata/NW.svc/Employees(1)/ThumbNail_48X48/$value |
| 69 | 69 | $request->setContainerName($segments[count($segments) - 2]->getIdentifier()); |
| 70 | 70 | } else { |
| 71 | - $request->setContainerName($request->getIdentifier()); |
|
| 71 | + $request->setContainerName($request->getIdentifier()); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | if ($request->getIdentifier() === ODataConstants::URI_COUNT_SEGMENT) { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | throw ODataException::createBadRequestError(Messages::configurationCountNotAccepted()); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $request->queryType = QueryType::COUNT(); |
|
| 79 | + $request->queryType = QueryType::COUNT(); |
|
| 80 | 80 | // use of $count requires request DataServiceVersion |
| 81 | 81 | // and MaxDataServiceVersion greater than or equal to 2.0 |
| 82 | 82 | |
@@ -175,7 +175,7 @@ |
||
| 175 | 175 | */ |
| 176 | 176 | public function isEmpty() |
| 177 | 177 | { |
| 178 | - return empty($this->_namedValues) |
|
| 178 | + return empty($this->_namedValues) |
|
| 179 | 179 | && empty($this->_positionalValues); |
| 180 | 180 | } |
| 181 | 181 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | $segmentLength = strlen($segment); |
| 94 | 94 | if (strrpos($segment, ')') !== $segmentLength - 1) { |
| 95 | - throw ODataException::createSyntaxError(Messages::syntaxError()); |
|
| 95 | + throw ODataException::createSyntaxError(Messages::syntaxError()); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $identifier = substr($segment, 0, $predicateStart); |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | if (empty($segments)) { |
| 114 | 114 | //If there's no segments, then it's the service root |
| 115 | - $descriptor = new SegmentDescriptor(); |
|
| 116 | - $descriptor->setTargetKind(TargetKind::SERVICE_DIRECTORY()); |
|
| 115 | + $descriptor = new SegmentDescriptor(); |
|
| 116 | + $descriptor->setTargetKind(TargetKind::SERVICE_DIRECTORY()); |
|
| 117 | 117 | $this->_segmentDescriptors[] = $descriptor; |
| 118 | 118 | return; |
| 119 | 119 | } |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | $segmentCount = count($segments); |
| 122 | 122 | $identifier = $keyPredicate = null; |
| 123 | 123 | $this->extractSegmentIdentifierAndKeyPredicate($segments[0], $identifier, $keyPredicate); |
| 124 | - $previous = $this->_createFirstSegmentDescriptor( |
|
| 124 | + $previous = $this->_createFirstSegmentDescriptor( |
|
| 125 | 125 | $identifier, $keyPredicate, $checkRights |
| 126 | 126 | ); |
| 127 | 127 | $this->_segmentDescriptors[0] = $previous; |
| 128 | 128 | |
| 129 | 129 | for ($i = 1; $i < $segmentCount; $i++) { |
| 130 | - $current = $this->createNextSegment($previous, $segments[$i], $checkRights); |
|
| 130 | + $current = $this->createNextSegment($previous, $segments[$i], $checkRights); |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | $current->setPrevious($previous); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | //At this point $previous is the final segment..which cannot be a $link |
| 140 | 140 | if ($previous->getTargetKind() == TargetKind::LINK()) { |
| 141 | - throw ODataException::createBadRequestError(Messages::segmentParserMissingSegmentAfterLink()); |
|
| 141 | + throw ODataException::createBadRequestError(Messages::segmentParserMissingSegmentAfterLink()); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | || $previousKind == TargetKind::MEDIA_RESOURCE() |
| 152 | 152 | ) { |
| 153 | 153 | //All these targets are terminal segments, there cannot be anything after them. |
| 154 | - throw ODataException::resourceNotFoundError( |
|
| 154 | + throw ODataException::resourceNotFoundError( |
|
| 155 | 155 | Messages::segmentParserMustBeLeafSegment($previous->getIdentifier()) |
| 156 | 156 | ); |
| 157 | 157 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $current = null; |
| 163 | 163 | if ($previousKind == TargetKind::PRIMITIVE()) { |
| 164 | 164 | if ($identifier !== ODataConstants::URI_VALUE_SEGMENT) { |
| 165 | - throw ODataException::resourceNotFoundError( |
|
| 165 | + throw ODataException::resourceNotFoundError( |
|
| 166 | 166 | Messages::segmentParserOnlyValueSegmentAllowedAfterPrimitivePropertySegment( |
| 167 | 167 | $identifier, $previous->getIdentifier() |
| 168 | 168 | ) |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $current->setTargetKind(TargetKind::PRIMITIVE_VALUE()); |
| 176 | 176 | $current->setSingleResult(true); |
| 177 | 177 | } else if (!is_null($previous->getPrevious()) && $previous->getPrevious()->getIdentifier() === ODataConstants::URI_LINK_SEGMENT && $identifier !== ODataConstants::URI_COUNT_SEGMENT) { |
| 178 | - throw ODataException::createBadRequestError( |
|
| 178 | + throw ODataException::createBadRequestError( |
|
| 179 | 179 | Messages::segmentParserNoSegmentAllowedAfterPostLinkSegment($identifier) |
| 180 | 180 | ); |
| 181 | 181 | } else if ($previousKind == TargetKind::RESOURCE() |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | if (!$previous->isSingleResult() && $identifier !== ODataConstants::URI_COUNT_SEGMENT) { |
| 201 | - throw ODataException::createBadRequestError( |
|
| 201 | + throw ODataException::createBadRequestError( |
|
| 202 | 202 | Messages::segmentParserCannotQueryCollection($previous->getIdentifier()) |
| 203 | 203 | ); |
| 204 | 204 | } |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | if ($identifier === ODataConstants::URI_COUNT_SEGMENT) { |
| 213 | 213 | if ($previousKind != TargetKind::RESOURCE()) { |
| 214 | - throw ODataException::createBadRequestError( |
|
| 214 | + throw ODataException::createBadRequestError( |
|
| 215 | 215 | Messages::segmentParserCountCannotBeApplied($previous->getIdentifier()) |
| 216 | 216 | ); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | if ($previous->isSingleResult()) { |
| 220 | - throw ODataException::createBadRequestError( |
|
| 220 | + throw ODataException::createBadRequestError( |
|
| 221 | 221 | Messages::segmentParserCountCannotFollowSingleton($previous->getIdentifier()) |
| 222 | 222 | ); |
| 223 | 223 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $previous->getTargetResourceType() |
| 249 | 249 | ); |
| 250 | 250 | } else { |
| 251 | - throw ODataException::createResourceNotFoundError($identifier); |
|
| 251 | + throw ODataException::createResourceNotFoundError($identifier); |
|
| 252 | 252 | } |
| 253 | 253 | } else { |
| 254 | 254 | $current->setTargetResourceType($projectedProperty->getResourceType()); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | if ($previousKind == TargetKind::LINK() |
| 257 | 257 | && $projectedProperty->getTypeKind() != ResourceTypeKind::ENTITY |
| 258 | 258 | ) { |
| 259 | - throw ODataException::createBadRequestError( |
|
| 259 | + throw ODataException::createBadRequestError( |
|
| 260 | 260 | Messages::segmentParserLinkSegmentMustBeFollowedByEntitySegment( |
| 261 | 261 | $identifier |
| 262 | 262 | ) |
@@ -276,14 +276,14 @@ discard block |
||
| 276 | 276 | $current->setTargetKind(TargetKind::RESOURCE()); |
| 277 | 277 | $resourceSetWrapper = $this->providerWrapper->getResourceSetWrapperForNavigationProperty($previous->getTargetResourceSetWrapper(), $previous->getTargetResourceType(), $projectedProperty); |
| 278 | 278 | if (is_null($resourceSetWrapper)) { |
| 279 | - throw ODataException::createResourceNotFoundError($projectedProperty->getName()); |
|
| 279 | + throw ODataException::createResourceNotFoundError($projectedProperty->getName()); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | $current->setTargetResourceSetWrapper($resourceSetWrapper); |
| 283 | 283 | break; |
| 284 | 284 | default: |
| 285 | 285 | if (!$projectedProperty->isKindOf(ResourcePropertyKind::PRIMITIVE)) { |
| 286 | - throw ODataException::createInternalServerError( |
|
| 286 | + throw ODataException::createInternalServerError( |
|
| 287 | 287 | Messages::segmentParserUnExpectedPropertyKind( |
| 288 | 288 | 'Primitive' |
| 289 | 289 | ) |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | if ($segmentIdentifier === ODataConstants::URI_COUNT_SEGMENT) { |
| 350 | - throw ODataException::createBadRequestError( |
|
| 350 | + throw ODataException::createBadRequestError( |
|
| 351 | 351 | Messages::segmentParserSegmentNotAllowedOnRoot( |
| 352 | 352 | ODataConstants::URI_COUNT_SEGMENT |
| 353 | 353 | ) |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | if ($segmentIdentifier === ODataConstants::URI_LINK_SEGMENT) { |
| 358 | - throw ODataException::createBadRequestError( |
|
| 358 | + throw ODataException::createBadRequestError( |
|
| 359 | 359 | Messages::segmentParserSegmentNotAllowedOnRoot( |
| 360 | 360 | ODataConstants::URI_LINK_SEGMENT |
| 361 | 361 | ) |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | |
| 365 | 365 | $resourceSetWrapper = $this->providerWrapper->resolveResourceSet($segmentIdentifier); |
| 366 | 366 | if ($resourceSetWrapper === null) { |
| 367 | - throw ODataException::createResourceNotFoundError($segmentIdentifier); |
|
| 367 | + throw ODataException::createResourceNotFoundError($segmentIdentifier); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | $descriptor->setTargetResourceSetWrapper($resourceSetWrapper); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $absoluteServiceUri = $service->getHost()->getAbsoluteServiceUri(); |
| 99 | 99 | |
| 100 | 100 | if (!$absoluteServiceUri->isBaseOf($absoluteRequestUri)) { |
| 101 | - throw ODataException::createInternalServerError( |
|
| 101 | + throw ODataException::createInternalServerError( |
|
| 102 | 102 | Messages::uriProcessorRequestUriDoesNotHaveTheRightBaseUri( |
| 103 | 103 | $absoluteRequestUri->getUrlAsString(), |
| 104 | 104 | $absoluteServiceUri->getUrlAsString() |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | $uriProcessor = new UriProcessor($service); |
| 110 | 110 | //Parse the resource path part of the request Uri. |
| 111 | - $uriProcessor->request = ResourcePathProcessor::process($service); |
|
| 111 | + $uriProcessor->request = ResourcePathProcessor::process($service); |
|
| 112 | 112 | |
| 113 | - $uriProcessor->request->setUriProcessor($uriProcessor); |
|
| 113 | + $uriProcessor->request->setUriProcessor($uriProcessor); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | //Parse the query string options of the request Uri. |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $requestTargetKind = $segment->getTargetKind(); |
| 142 | 142 | |
| 143 | - if ($segment->getTargetSource() == TargetSource::ENTITY_SET) { |
|
| 143 | + if ($segment->getTargetSource() == TargetSource::ENTITY_SET) { |
|
| 144 | 144 | $this->handleSegmentTargetsToResourceSet($segment); |
| 145 | 145 | } else if ($requestTargetKind == TargetKind::RESOURCE()) { |
| 146 | 146 | if (is_null($segment->getPrevious()->getResult())) { |
| 147 | - throw ODataException::createResourceNotFoundError( |
|
| 147 | + throw ODataException::createResourceNotFoundError( |
|
| 148 | 148 | $segment->getPrevious()->getIdentifier() |
| 149 | 149 | ); |
| 150 | 150 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } else { |
| 160 | 160 | if ($requestTargetKind == TargetKind::MEDIA_RESOURCE()) { |
| 161 | 161 | if (is_null($segment->getPrevious()->getResult())) { |
| 162 | - throw ODataException::createResourceNotFoundError( |
|
| 162 | + throw ODataException::createResourceNotFoundError( |
|
| 163 | 163 | $segment->getPrevious()->getIdentifier() |
| 164 | 164 | ); |
| 165 | 165 | } |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | break; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $value = $segment->getPrevious()->getResult(); |
|
| 175 | + $value = $segment->getPrevious()->getResult(); |
|
| 176 | 176 | while (!is_null($segment)) { |
| 177 | - //TODO: what exactly is this doing here? Once a null's found it seems everything will be null |
|
| 177 | + //TODO: what exactly is this doing here? Once a null's found it seems everything will be null |
|
| 178 | 178 | if (!is_null($value)) { |
| 179 | 179 | $value = null; |
| 180 | 180 | } else { |
| 181 | 181 | try { |
| 182 | - //see #88 |
|
| 182 | + //see #88 |
|
| 183 | 183 | $property = new \ReflectionProperty($value, $segment->getIdentifier()); |
| 184 | 184 | $value = $property->getValue($value); |
| 185 | 185 | } catch (\ReflectionException $reflectionException) { |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - // Apply $select and $expand options to result set, this function will be always applied |
|
| 208 | - // irrespective of return value of IDSQP2::canApplyQueryOptions which means library will |
|
| 209 | - // not delegate $expand/$select operation to IDSQP2 implementation |
|
| 207 | + // Apply $select and $expand options to result set, this function will be always applied |
|
| 208 | + // irrespective of return value of IDSQP2::canApplyQueryOptions which means library will |
|
| 209 | + // not delegate $expand/$select operation to IDSQP2 implementation |
|
| 210 | 210 | $this->handleExpansion(); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | } else { |
| 230 | 230 | |
| 231 | 231 | $queryResult = $this->providers->getResourceSet( |
| 232 | - $this->request->queryType, |
|
| 232 | + $this->request->queryType, |
|
| 233 | 233 | $segment->getTargetResourceSetWrapper(), |
| 234 | 234 | $this->request->getFilterInfo(), |
| 235 | 235 | $this->request->getInternalOrderByInfo(), |
@@ -266,13 +266,13 @@ discard block |
||
| 266 | 266 | $segment->setResult($entityInstance); |
| 267 | 267 | } else { |
| 268 | 268 | $queryResult = $this->providers->getRelatedResourceSet( |
| 269 | - $this->request->queryType, |
|
| 269 | + $this->request->queryType, |
|
| 270 | 270 | $segment->getPrevious()->getTargetResourceSetWrapper(), |
| 271 | 271 | $segment->getPrevious()->getResult(), |
| 272 | 272 | $segment->getTargetResourceSetWrapper(), |
| 273 | 273 | $segment->getProjectedProperty(), |
| 274 | 274 | $this->request->getFilterInfo(), |
| 275 | - //TODO: why are these null? see #98 |
|
| 275 | + //TODO: why are these null? see #98 |
|
| 276 | 276 | null, // $orderby |
| 277 | 277 | null, // $top |
| 278 | 278 | null // $skip |
@@ -302,19 +302,19 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | private function applyQueryOptions(SegmentDescriptor $segment) |
| 304 | 304 | { |
| 305 | - //TODO: I'm not really happy with this..i think i'd rather keep the result the QueryResult |
|
| 306 | - //not even bother with the setCountValue stuff (shouldn't counts be on segments?) |
|
| 307 | - //and just work with the QueryResult in the object model serializer |
|
| 308 | - $result = $segment->getResult(); |
|
| 309 | - |
|
| 310 | - if(!$result instanceof QueryResult){ |
|
| 311 | - //If the segment isn't a query result, then there's no paging or counting to be done |
|
| 312 | - return; |
|
| 305 | + //TODO: I'm not really happy with this..i think i'd rather keep the result the QueryResult |
|
| 306 | + //not even bother with the setCountValue stuff (shouldn't counts be on segments?) |
|
| 307 | + //and just work with the QueryResult in the object model serializer |
|
| 308 | + $result = $segment->getResult(); |
|
| 309 | + |
|
| 310 | + if(!$result instanceof QueryResult){ |
|
| 311 | + //If the segment isn't a query result, then there's no paging or counting to be done |
|
| 312 | + return; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
| 316 | 316 | // Note $inlinecount=allpages means include the total count regardless of paging..so we set the counts first |
| 317 | - // regardless if POData does the paging or not. |
|
| 317 | + // regardless if POData does the paging or not. |
|
| 318 | 318 | if ($this->request->queryType == QueryType::ENTITIES_WITH_COUNT()) { |
| 319 | 319 | if ($this->providers->handlesOrderedPaging()) { |
| 320 | 320 | $this->request->setCountValue($result->count); |
@@ -323,57 +323,57 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - //Have POData perform paging if necessary |
|
| 327 | - if(!$this->providers->handlesOrderedPaging() && !empty($result->results)){ |
|
| 328 | - $result->results = $this->performPaging($result->results); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - //a bit surprising, but $skip and $top affects $count so update it here, not above |
|
| 332 | - //IE data.svc/Collection/$count?$top=10 returns 10 even if Collection has 11+ entries |
|
| 333 | - if ($this->request->queryType == QueryType::COUNT()) { |
|
| 334 | - if ($this->providers->handlesOrderedPaging()) { |
|
| 335 | - $this->request->setCountValue($result->count); |
|
| 336 | - } else { |
|
| 337 | - $this->request->setCountValue(count($result->results)); |
|
| 338 | - } |
|
| 339 | - } |
|
| 326 | + //Have POData perform paging if necessary |
|
| 327 | + if(!$this->providers->handlesOrderedPaging() && !empty($result->results)){ |
|
| 328 | + $result->results = $this->performPaging($result->results); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + //a bit surprising, but $skip and $top affects $count so update it here, not above |
|
| 332 | + //IE data.svc/Collection/$count?$top=10 returns 10 even if Collection has 11+ entries |
|
| 333 | + if ($this->request->queryType == QueryType::COUNT()) { |
|
| 334 | + if ($this->providers->handlesOrderedPaging()) { |
|
| 335 | + $this->request->setCountValue($result->count); |
|
| 336 | + } else { |
|
| 337 | + $this->request->setCountValue(count($result->results)); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | 341 | $segment->setResult($result->results); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * If the provider does not perform the paging (ordering, top, skip) then this method does it |
|
| 346 | - * |
|
| 347 | - * @param array $result |
|
| 348 | - * @return array |
|
| 349 | - */ |
|
| 350 | - private function performPaging(array $result) |
|
| 351 | - { |
|
| 352 | - //Apply (implicit and explicit) $orderby option |
|
| 353 | - $internalOrderByInfo = $this->request->getInternalOrderByInfo(); |
|
| 354 | - if (!is_null($internalOrderByInfo)) { |
|
| 355 | - $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference(); |
|
| 356 | - usort($result, $orderByFunction); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - //Apply $skiptoken option |
|
| 360 | - $internalSkipTokenInfo = $this->request->getInternalSkipTokenInfo(); |
|
| 361 | - if (!is_null($internalSkipTokenInfo)) { |
|
| 362 | - $matchingIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($result); |
|
| 363 | - $result = array_slice($result, $matchingIndex); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - //Apply $top and $skip option |
|
| 367 | - if (!empty($result)) { |
|
| 368 | - $top = $this->request->getTopCount(); |
|
| 369 | - $skip = $this->request->getSkipCount(); |
|
| 370 | - if(is_null($skip)) $skip = 0; |
|
| 371 | - |
|
| 372 | - $result = array_slice($result, $skip, $top); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return $result; |
|
| 376 | - } |
|
| 344 | + /** |
|
| 345 | + * If the provider does not perform the paging (ordering, top, skip) then this method does it |
|
| 346 | + * |
|
| 347 | + * @param array $result |
|
| 348 | + * @return array |
|
| 349 | + */ |
|
| 350 | + private function performPaging(array $result) |
|
| 351 | + { |
|
| 352 | + //Apply (implicit and explicit) $orderby option |
|
| 353 | + $internalOrderByInfo = $this->request->getInternalOrderByInfo(); |
|
| 354 | + if (!is_null($internalOrderByInfo)) { |
|
| 355 | + $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference(); |
|
| 356 | + usort($result, $orderByFunction); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + //Apply $skiptoken option |
|
| 360 | + $internalSkipTokenInfo = $this->request->getInternalSkipTokenInfo(); |
|
| 361 | + if (!is_null($internalSkipTokenInfo)) { |
|
| 362 | + $matchingIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($result); |
|
| 363 | + $result = array_slice($result, $matchingIndex); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + //Apply $top and $skip option |
|
| 367 | + if (!empty($result)) { |
|
| 368 | + $top = $this->request->getTopCount(); |
|
| 369 | + $skip = $this->request->getSkipCount(); |
|
| 370 | + if(is_null($skip)) $skip = 0; |
|
| 371 | + |
|
| 372 | + $result = array_slice($result, $skip, $top); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return $result; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | $resourceSetOfProjectedProperty = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet(); |
| 417 | 417 | $projectedProperty1 = $expandedProjectionNode->getResourceProperty(); |
| 418 | 418 | $result1 = $this->providers->getRelatedResourceSet( |
| 419 | - QueryType::ENTITIES(), //it's always entities for an expansion |
|
| 419 | + QueryType::ENTITIES(), //it's always entities for an expansion |
|
| 420 | 420 | $currentResourceSet, |
| 421 | 421 | $entry, |
| 422 | 422 | $resourceSetOfProjectedProperty, |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | $resourceSetOfProjectedProperty2 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet(); |
| 476 | 476 | $projectedProperty4 = $expandedProjectionNode->getResourceProperty(); |
| 477 | 477 | $result1 = $this->providers->getRelatedResourceSet( |
| 478 | - QueryType::ENTITIES(), //it's always entities for an expansion |
|
| 478 | + QueryType::ENTITIES(), //it's always entities for an expansion |
|
| 479 | 479 | $currentResourceSet2, |
| 480 | 480 | $result, |
| 481 | 481 | $resourceSetOfProjectedProperty2, |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public $xmlWriter; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * The service base uri |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $baseUri; |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * The service base uri |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $baseUri; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Construct a new instance of AtomODataWriter. |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function __construct($absoluteServiceUri) |
| 47 | 47 | { |
| 48 | - $this->baseUri = $absoluteServiceUri; |
|
| 48 | + $this->baseUri = $absoluteServiceUri; |
|
| 49 | 49 | |
| 50 | 50 | $this->xmlWriter = new \XMLWriter(); |
| 51 | 51 | $this->xmlWriter->openMemory(); |
@@ -53,67 +53,67 @@ discard block |
||
| 53 | 53 | $this->xmlWriter->setIndent(4); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Determines if the given writer is capable of writing the response or not |
|
| 58 | - * @param Version $responseVersion the OData version of the response |
|
| 59 | - * @param string $contentType the Content Type of the response |
|
| 60 | - * @return boolean true if the writer can handle the response, false otherwise |
|
| 61 | - */ |
|
| 62 | - public function canHandle(Version $responseVersion, $contentType) |
|
| 63 | - { |
|
| 64 | - |
|
| 65 | - $parts = explode(";", $contentType); |
|
| 66 | - |
|
| 67 | - //first 2 parts are for service documents, second part is for Resources |
|
| 68 | - //TODO: i'm not sold about this first part not being constrained to v1 (or maybe v2)..but it's how WS DS works. See #94 |
|
| 69 | - return in_array(MimeTypes::MIME_APPLICATION_XML, $parts) || in_array(MimeTypes::MIME_APPLICATION_ATOMSERVICE, $parts) || in_array(MimeTypes::MIME_APPLICATION_ATOM, $parts); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Write the given OData model in a specific response format |
|
| 74 | - * |
|
| 75 | - * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 76 | - * |
|
| 77 | - * @return AtomODataWriter |
|
| 78 | - */ |
|
| 79 | - public function write($model) |
|
| 80 | - { |
|
| 81 | - if ($model instanceof ODataURL) { |
|
| 82 | - return $this->writeURL($model); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ($model instanceof ODataURLCollection) { |
|
| 86 | - return $this->writeURLCollection($model); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if ($model instanceof ODataPropertyContent) { |
|
| 90 | - return $this->writeProperties($model, true); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if ($model instanceof ODataFeed) { |
|
| 94 | - return $this->writeFeed($model, true); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if ($model instanceof ODataEntry) { |
|
| 98 | - return $this->writeEntry($model, true); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $this; |
|
| 102 | - } |
|
| 56 | + /** |
|
| 57 | + * Determines if the given writer is capable of writing the response or not |
|
| 58 | + * @param Version $responseVersion the OData version of the response |
|
| 59 | + * @param string $contentType the Content Type of the response |
|
| 60 | + * @return boolean true if the writer can handle the response, false otherwise |
|
| 61 | + */ |
|
| 62 | + public function canHandle(Version $responseVersion, $contentType) |
|
| 63 | + { |
|
| 64 | + |
|
| 65 | + $parts = explode(";", $contentType); |
|
| 66 | + |
|
| 67 | + //first 2 parts are for service documents, second part is for Resources |
|
| 68 | + //TODO: i'm not sold about this first part not being constrained to v1 (or maybe v2)..but it's how WS DS works. See #94 |
|
| 69 | + return in_array(MimeTypes::MIME_APPLICATION_XML, $parts) || in_array(MimeTypes::MIME_APPLICATION_ATOMSERVICE, $parts) || in_array(MimeTypes::MIME_APPLICATION_ATOM, $parts); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Write the given OData model in a specific response format |
|
| 74 | + * |
|
| 75 | + * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 76 | + * |
|
| 77 | + * @return AtomODataWriter |
|
| 78 | + */ |
|
| 79 | + public function write($model) |
|
| 80 | + { |
|
| 81 | + if ($model instanceof ODataURL) { |
|
| 82 | + return $this->writeURL($model); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if ($model instanceof ODataURLCollection) { |
|
| 86 | + return $this->writeURLCollection($model); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if ($model instanceof ODataPropertyContent) { |
|
| 90 | + return $this->writeProperties($model, true); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if ($model instanceof ODataFeed) { |
|
| 94 | + return $this->writeFeed($model, true); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if ($model instanceof ODataEntry) { |
|
| 98 | + return $this->writeEntry($model, true); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $this; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * @param ODataUrl $url the url to write. |
| 106 | 106 | * |
| 107 | 107 | * @return AtomODataWriter |
| 108 | 108 | */ |
| 109 | - protected function writeURL(ODataURL $url) |
|
| 109 | + protected function writeURL(ODataURL $url) |
|
| 110 | 110 | { |
| 111 | 111 | $this->xmlWriter->startElement(ODataConstants::ATOM_URI_ELEMENT_NAME); |
| 112 | 112 | $this->xmlWriter->writeAttribute(ODataConstants::XMLNS_NAMESPACE_PREFIX, ODataConstants::ODATA_NAMESPACE); |
| 113 | 113 | $this->xmlWriter->text($url->url); |
| 114 | 114 | $this->xmlWriter->endElement(); |
| 115 | 115 | |
| 116 | - return $this; |
|
| 116 | + return $this; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
| 155 | - if ($urls->nextPageLink!=null) { |
|
| 156 | - $this->writeLinkNode($urls->nextPageLink, false); |
|
| 157 | - } |
|
| 158 | - $this->xmlWriter->endElement(); |
|
| 155 | + if ($urls->nextPageLink!=null) { |
|
| 156 | + $this->writeLinkNode($urls->nextPageLink, false); |
|
| 157 | + } |
|
| 158 | + $this->xmlWriter->endElement(); |
|
| 159 | 159 | |
| 160 | - return $this; |
|
| 160 | + return $this; |
|
| 161 | 161 | |
| 162 | 162 | } |
| 163 | 163 | |
@@ -176,65 +176,65 @@ discard block |
||
| 176 | 176 | $this->writeBaseUriAndDefaultNamespaces(); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $this |
|
| 180 | - ->writeNodeAttributeValue( |
|
| 181 | - ODataConstants::ATOM_TITLE_ELELMET_NAME, |
|
| 182 | - ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, |
|
| 183 | - MimeTypes::MIME_TEXTTYPE, |
|
| 184 | - $feed->title |
|
| 185 | - ) |
|
| 186 | - ->writeNodeValue(ODataConstants::ATOM_ID_ELEMENT_NAME, $feed->id) |
|
| 187 | - ->writeNodeValue(ODataConstants::ATOM_UPDATED_ELEMENT_NAME, date(DATE_ATOM) ) |
|
| 188 | - ->writeLinkNode($feed->selfLink, false); |
|
| 189 | - |
|
| 190 | - if ($feed->rowCount != null) { |
|
| 191 | - $this->xmlWriter->startElementNs( |
|
| 192 | - ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 193 | - ODataConstants::ROWCOUNT_ELEMENT, null |
|
| 194 | - ); |
|
| 195 | - $this->xmlWriter->text($feed->rowCount); |
|
| 196 | - $this->xmlWriter->endElement(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - foreach ($feed->entries as $entry) { |
|
| 200 | - $this->writeEntry($entry); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - if ($feed->nextPageLink != null) { |
|
| 204 | - $this->writeLinkNode($feed->nextPageLink, false); |
|
| 205 | - } |
|
| 206 | - $this->xmlWriter->endElement(); |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - return $this; |
|
| 179 | + $this |
|
| 180 | + ->writeNodeAttributeValue( |
|
| 181 | + ODataConstants::ATOM_TITLE_ELELMET_NAME, |
|
| 182 | + ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, |
|
| 183 | + MimeTypes::MIME_TEXTTYPE, |
|
| 184 | + $feed->title |
|
| 185 | + ) |
|
| 186 | + ->writeNodeValue(ODataConstants::ATOM_ID_ELEMENT_NAME, $feed->id) |
|
| 187 | + ->writeNodeValue(ODataConstants::ATOM_UPDATED_ELEMENT_NAME, date(DATE_ATOM) ) |
|
| 188 | + ->writeLinkNode($feed->selfLink, false); |
|
| 189 | + |
|
| 190 | + if ($feed->rowCount != null) { |
|
| 191 | + $this->xmlWriter->startElementNs( |
|
| 192 | + ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 193 | + ODataConstants::ROWCOUNT_ELEMENT, null |
|
| 194 | + ); |
|
| 195 | + $this->xmlWriter->text($feed->rowCount); |
|
| 196 | + $this->xmlWriter->endElement(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + foreach ($feed->entries as $entry) { |
|
| 200 | + $this->writeEntry($entry); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if ($feed->nextPageLink != null) { |
|
| 204 | + $this->writeLinkNode($feed->nextPageLink, false); |
|
| 205 | + } |
|
| 206 | + $this->xmlWriter->endElement(); |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + return $this; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Write top level entry |
|
| 215 | - * |
|
| 216 | - * @param ODataEntry $entry Object of ODataEntry |
|
| 217 | - * @param boolean $isTopLevel |
|
| 218 | - * |
|
| 219 | - * @return AtomODataWriter |
|
| 220 | - */ |
|
| 221 | - protected function writeEntry(ODataEntry $entry, $isTopLevel = false) |
|
| 222 | - { |
|
| 223 | - $this->writeBeginEntry($entry, $isTopLevel); |
|
| 224 | - foreach ($entry->links as $link) { |
|
| 225 | - $this->writeLink($link); |
|
| 226 | - } |
|
| 213 | + /** |
|
| 214 | + * Write top level entry |
|
| 215 | + * |
|
| 216 | + * @param ODataEntry $entry Object of ODataEntry |
|
| 217 | + * @param boolean $isTopLevel |
|
| 218 | + * |
|
| 219 | + * @return AtomODataWriter |
|
| 220 | + */ |
|
| 221 | + protected function writeEntry(ODataEntry $entry, $isTopLevel = false) |
|
| 222 | + { |
|
| 223 | + $this->writeBeginEntry($entry, $isTopLevel); |
|
| 224 | + foreach ($entry->links as $link) { |
|
| 225 | + $this->writeLink($link); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - $this |
|
| 229 | - ->preWriteProperties($entry) |
|
| 230 | - ->writeProperties($entry->propertyContent) |
|
| 231 | - ->postWriteProperties($entry); |
|
| 228 | + $this |
|
| 229 | + ->preWriteProperties($entry) |
|
| 230 | + ->writeProperties($entry->propertyContent) |
|
| 231 | + ->postWriteProperties($entry); |
|
| 232 | 232 | |
| 233 | - $this->xmlWriter->endElement(); |
|
| 233 | + $this->xmlWriter->endElement(); |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - return $this; |
|
| 237 | - } |
|
| 236 | + return $this; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -262,155 +262,155 @@ discard block |
||
| 262 | 262 | $this->xmlWriter->endAttribute(); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - $this |
|
| 266 | - ->writeNodeValue(ODataConstants::ATOM_ID_ELEMENT_NAME, $entry->id) |
|
| 267 | - ->writeNodeAttributeValue( |
|
| 268 | - ODataConstants::ATOM_TITLE_ELELMET_NAME, |
|
| 269 | - ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, |
|
| 270 | - MimeTypes::MIME_TEXTTYPE, |
|
| 271 | - $entry->title |
|
| 272 | - ) |
|
| 273 | - ->writeNodeValue(ODataConstants::ATOM_UPDATED_ELEMENT_NAME, date(DATE_ATOM)); |
|
| 274 | - |
|
| 275 | - $this->xmlWriter->startElement(ODataConstants::ATOM_AUTHOR_ELEMENT_NAME); |
|
| 276 | - $this->xmlWriter->startElement(ODataConstants::ATOM_NAME_ELEMENT_NAME); |
|
| 277 | - $this->xmlWriter->endElement(); |
|
| 278 | - $this->xmlWriter->endElement(); |
|
| 279 | - if ($entry->isMediaLinkEntry) { |
|
| 280 | - $this->xmlWriter->startElement(ODataConstants::ATOM_LINK_ELEMENT_NAME); |
|
| 281 | - if ($entry->mediaLink->eTag != null) { |
|
| 282 | - $this->xmlWriter->startAttributeNs( |
|
| 283 | - ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 284 | - ODataConstants::ATOM_ETAG_ATTRIBUTE_NAME, |
|
| 285 | - null |
|
| 286 | - ); |
|
| 287 | - $this->xmlWriter->text($entry->mediaLink->eTag); |
|
| 288 | - $this->xmlWriter->endAttribute(); |
|
| 289 | - } |
|
| 290 | - $this->xmlWriter->startAttribute( |
|
| 291 | - ODataConstants::ATOM_LINK_RELATION_ATTRIBUTE_NAME |
|
| 292 | - ); |
|
| 293 | - $this->xmlWriter->text(ODataConstants::ATOM_EDIT_MEDIA_RELATION_ATTRIBUTE_VALUE); |
|
| 294 | - $this->xmlWriter->endAttribute(); |
|
| 295 | - |
|
| 296 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME); |
|
| 297 | - $this->xmlWriter->text($entry->mediaLink->contentType); |
|
| 298 | - $this->xmlWriter->endAttribute(); |
|
| 299 | - |
|
| 300 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_TITLE_ELELMET_NAME); |
|
| 301 | - $this->xmlWriter->text($entry->mediaLink->name); |
|
| 302 | - $this->xmlWriter->endAttribute(); |
|
| 303 | - |
|
| 304 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_HREF_ATTRIBUTE_NAME); |
|
| 305 | - $this->xmlWriter->text($entry->mediaLink->editLink); |
|
| 306 | - $this->xmlWriter->endAttribute(); |
|
| 307 | - $this->xmlWriter->endElement(); |
|
| 308 | - |
|
| 309 | - foreach ($entry->mediaLinks as $mediaLink) { |
|
| 310 | - $this->xmlWriter->startElement(ODataConstants::ATOM_LINK_ELEMENT_NAME); |
|
| 311 | - if ($mediaLink->eTag != null) { |
|
| 312 | - $this->xmlWriter->startAttributeNs( |
|
| 313 | - ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 314 | - ODataConstants::ATOM_ETAG_ATTRIBUTE_NAME, |
|
| 315 | - null |
|
| 316 | - ); |
|
| 317 | - $this->xmlWriter->text($mediaLink->eTag); |
|
| 318 | - $this->xmlWriter->endAttribute(); |
|
| 319 | - } |
|
| 320 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_LINK_RELATION_ATTRIBUTE_NAME); |
|
| 321 | - $this->xmlWriter->text( |
|
| 322 | - "http://schemas.microsoft.com/ado/2007/08/dataservices/mediaresource/" |
|
| 323 | - .$mediaLink->name |
|
| 324 | - ); |
|
| 325 | - $this->xmlWriter->endAttribute(); |
|
| 326 | - |
|
| 327 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME); |
|
| 328 | - $this->xmlWriter->text($mediaLink->contentType); |
|
| 329 | - $this->xmlWriter->endAttribute(); |
|
| 330 | - |
|
| 331 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_TITLE_ELELMET_NAME); |
|
| 332 | - $this->xmlWriter->text($mediaLink->name); |
|
| 333 | - $this->xmlWriter->endAttribute(); |
|
| 334 | - |
|
| 335 | - $this->xmlWriter->startAttribute(ODataConstants::ATOM_HREF_ATTRIBUTE_NAME); |
|
| 336 | - $this->xmlWriter->text($mediaLink->editLink); |
|
| 337 | - $this->xmlWriter->endAttribute(); |
|
| 338 | - $this->xmlWriter->endElement(); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - return $this; |
|
| 265 | + $this |
|
| 266 | + ->writeNodeValue(ODataConstants::ATOM_ID_ELEMENT_NAME, $entry->id) |
|
| 267 | + ->writeNodeAttributeValue( |
|
| 268 | + ODataConstants::ATOM_TITLE_ELELMET_NAME, |
|
| 269 | + ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, |
|
| 270 | + MimeTypes::MIME_TEXTTYPE, |
|
| 271 | + $entry->title |
|
| 272 | + ) |
|
| 273 | + ->writeNodeValue(ODataConstants::ATOM_UPDATED_ELEMENT_NAME, date(DATE_ATOM)); |
|
| 274 | + |
|
| 275 | + $this->xmlWriter->startElement(ODataConstants::ATOM_AUTHOR_ELEMENT_NAME); |
|
| 276 | + $this->xmlWriter->startElement(ODataConstants::ATOM_NAME_ELEMENT_NAME); |
|
| 277 | + $this->xmlWriter->endElement(); |
|
| 278 | + $this->xmlWriter->endElement(); |
|
| 279 | + if ($entry->isMediaLinkEntry) { |
|
| 280 | + $this->xmlWriter->startElement(ODataConstants::ATOM_LINK_ELEMENT_NAME); |
|
| 281 | + if ($entry->mediaLink->eTag != null) { |
|
| 282 | + $this->xmlWriter->startAttributeNs( |
|
| 283 | + ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 284 | + ODataConstants::ATOM_ETAG_ATTRIBUTE_NAME, |
|
| 285 | + null |
|
| 286 | + ); |
|
| 287 | + $this->xmlWriter->text($entry->mediaLink->eTag); |
|
| 288 | + $this->xmlWriter->endAttribute(); |
|
| 289 | + } |
|
| 290 | + $this->xmlWriter->startAttribute( |
|
| 291 | + ODataConstants::ATOM_LINK_RELATION_ATTRIBUTE_NAME |
|
| 292 | + ); |
|
| 293 | + $this->xmlWriter->text(ODataConstants::ATOM_EDIT_MEDIA_RELATION_ATTRIBUTE_VALUE); |
|
| 294 | + $this->xmlWriter->endAttribute(); |
|
| 295 | + |
|
| 296 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME); |
|
| 297 | + $this->xmlWriter->text($entry->mediaLink->contentType); |
|
| 298 | + $this->xmlWriter->endAttribute(); |
|
| 299 | + |
|
| 300 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_TITLE_ELELMET_NAME); |
|
| 301 | + $this->xmlWriter->text($entry->mediaLink->name); |
|
| 302 | + $this->xmlWriter->endAttribute(); |
|
| 303 | + |
|
| 304 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_HREF_ATTRIBUTE_NAME); |
|
| 305 | + $this->xmlWriter->text($entry->mediaLink->editLink); |
|
| 306 | + $this->xmlWriter->endAttribute(); |
|
| 307 | + $this->xmlWriter->endElement(); |
|
| 308 | + |
|
| 309 | + foreach ($entry->mediaLinks as $mediaLink) { |
|
| 310 | + $this->xmlWriter->startElement(ODataConstants::ATOM_LINK_ELEMENT_NAME); |
|
| 311 | + if ($mediaLink->eTag != null) { |
|
| 312 | + $this->xmlWriter->startAttributeNs( |
|
| 313 | + ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 314 | + ODataConstants::ATOM_ETAG_ATTRIBUTE_NAME, |
|
| 315 | + null |
|
| 316 | + ); |
|
| 317 | + $this->xmlWriter->text($mediaLink->eTag); |
|
| 318 | + $this->xmlWriter->endAttribute(); |
|
| 319 | + } |
|
| 320 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_LINK_RELATION_ATTRIBUTE_NAME); |
|
| 321 | + $this->xmlWriter->text( |
|
| 322 | + "http://schemas.microsoft.com/ado/2007/08/dataservices/mediaresource/" |
|
| 323 | + .$mediaLink->name |
|
| 324 | + ); |
|
| 325 | + $this->xmlWriter->endAttribute(); |
|
| 326 | + |
|
| 327 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME); |
|
| 328 | + $this->xmlWriter->text($mediaLink->contentType); |
|
| 329 | + $this->xmlWriter->endAttribute(); |
|
| 330 | + |
|
| 331 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_TITLE_ELELMET_NAME); |
|
| 332 | + $this->xmlWriter->text($mediaLink->name); |
|
| 333 | + $this->xmlWriter->endAttribute(); |
|
| 334 | + |
|
| 335 | + $this->xmlWriter->startAttribute(ODataConstants::ATOM_HREF_ATTRIBUTE_NAME); |
|
| 336 | + $this->xmlWriter->text($mediaLink->editLink); |
|
| 337 | + $this->xmlWriter->endAttribute(); |
|
| 338 | + $this->xmlWriter->endElement(); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + return $this; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
| 346 | 346 | |
| 347 | 347 | |
| 348 | - /** |
|
| 349 | - * |
|
| 350 | - * @param ODataLink $link Link to write. |
|
| 351 | - * |
|
| 352 | - * @return AtomODataWriter |
|
| 353 | - */ |
|
| 354 | - protected function writeLink(ODataLink $link) |
|
| 348 | + /** |
|
| 349 | + * |
|
| 350 | + * @param ODataLink $link Link to write. |
|
| 351 | + * |
|
| 352 | + * @return AtomODataWriter |
|
| 353 | + */ |
|
| 354 | + protected function writeLink(ODataLink $link) |
|
| 355 | 355 | { |
| 356 | 356 | $this->writeLinkNode($link, $link->isExpanded); |
| 357 | 357 | |
| 358 | - if ($link->isExpanded) { |
|
| 359 | - $this->xmlWriter->startElementNS( |
|
| 360 | - ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 361 | - ODataConstants::ATOM_INLINE_ELEMENT_NAME, |
|
| 362 | - null |
|
| 363 | - ); |
|
| 358 | + if ($link->isExpanded) { |
|
| 359 | + $this->xmlWriter->startElementNS( |
|
| 360 | + ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
|
| 361 | + ODataConstants::ATOM_INLINE_ELEMENT_NAME, |
|
| 362 | + null |
|
| 363 | + ); |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | - if (!is_null($link->expandedResult)) { |
|
| 367 | - if ($link->isCollection) { |
|
| 368 | - $this->writeFeed($link->expandedResult); |
|
| 369 | - } else { |
|
| 370 | - $this->writeEntry($link->expandedResult); |
|
| 371 | - } |
|
| 372 | - } |
|
| 366 | + if (!is_null($link->expandedResult)) { |
|
| 367 | + if ($link->isCollection) { |
|
| 368 | + $this->writeFeed($link->expandedResult); |
|
| 369 | + } else { |
|
| 370 | + $this->writeEntry($link->expandedResult); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | 374 | |
| 375 | - $this->xmlWriter->endElement(); |
|
| 376 | - $this->xmlWriter->endElement(); |
|
| 377 | - } |
|
| 375 | + $this->xmlWriter->endElement(); |
|
| 376 | + $this->xmlWriter->endElement(); |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - return $this; |
|
| 379 | + return $this; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | |
| 383 | 383 | |
| 384 | 384 | |
| 385 | - /** |
|
| 386 | - * Write the given collection of properties. |
|
| 387 | - * (properties of an entity or complex type) |
|
| 388 | - * |
|
| 389 | - * @param ODataPropertyContent $properties Collection of properties. |
|
| 390 | - * @param bool $topLevel indicates if this property content is the top level response to be written |
|
| 391 | - * @return AtomODataWriter |
|
| 392 | - */ |
|
| 393 | - protected function writeProperties(ODataPropertyContent $properties, $topLevel = false) |
|
| 394 | - { |
|
| 395 | - foreach ($properties->properties as $property) { |
|
| 396 | - $this->beginWriteProperty($property, $topLevel); |
|
| 397 | - |
|
| 398 | - if ($property->value == null) { |
|
| 399 | - $this->writeNullValue($property); |
|
| 400 | - } elseif ($property->value instanceof ODataPropertyContent) { |
|
| 401 | - $this->writeProperties($property->value, false); |
|
| 402 | - } elseif ($property->value instanceof ODataBagContent) { |
|
| 403 | - $this->writeBagContent($property->value); |
|
| 404 | - } else { |
|
| 405 | - $value = $this->beforeWriteValue($property->value, $property->typeName); |
|
| 406 | - $this->xmlWriter->text($value); |
|
| 407 | - } |
|
| 385 | + /** |
|
| 386 | + * Write the given collection of properties. |
|
| 387 | + * (properties of an entity or complex type) |
|
| 388 | + * |
|
| 389 | + * @param ODataPropertyContent $properties Collection of properties. |
|
| 390 | + * @param bool $topLevel indicates if this property content is the top level response to be written |
|
| 391 | + * @return AtomODataWriter |
|
| 392 | + */ |
|
| 393 | + protected function writeProperties(ODataPropertyContent $properties, $topLevel = false) |
|
| 394 | + { |
|
| 395 | + foreach ($properties->properties as $property) { |
|
| 396 | + $this->beginWriteProperty($property, $topLevel); |
|
| 397 | + |
|
| 398 | + if ($property->value == null) { |
|
| 399 | + $this->writeNullValue($property); |
|
| 400 | + } elseif ($property->value instanceof ODataPropertyContent) { |
|
| 401 | + $this->writeProperties($property->value, false); |
|
| 402 | + } elseif ($property->value instanceof ODataBagContent) { |
|
| 403 | + $this->writeBagContent($property->value); |
|
| 404 | + } else { |
|
| 405 | + $value = $this->beforeWriteValue($property->value, $property->typeName); |
|
| 406 | + $this->xmlWriter->text($value); |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - $this->xmlWriter->endElement(); |
|
| 410 | - } |
|
| 409 | + $this->xmlWriter->endElement(); |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - return $this; |
|
| 413 | - } |
|
| 412 | + return $this; |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | 415 | /** |
| 416 | 416 | * XML write a basic data type (string, number, boolean, null) |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | } else { |
| 473 | 473 | $this->xmlWriter->writeAttribute( |
| 474 | 474 | ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, |
| 475 | - MimeTypes::MIME_APPLICATION_XML |
|
| 475 | + MimeTypes::MIME_APPLICATION_XML |
|
| 476 | 476 | ); |
| 477 | 477 | $this->xmlWriter->startElementNS( |
| 478 | 478 | ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | ); |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - return $this; |
|
| 484 | + return $this; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | $this->xmlWriter->endAttribute(); |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - return $this; |
|
| 522 | + return $this; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | } |
| 539 | 539 | $this->xmlWriter->endElement(); |
| 540 | 540 | |
| 541 | - return $this; |
|
| 541 | + return $this; |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - return $this; |
|
| 574 | + return $this; |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | ODataConstants::XML_TRUE_LITERAL |
| 595 | 595 | ); |
| 596 | 596 | } |
| 597 | - return $this; |
|
| 597 | + return $this; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | $this->xmlWriter->text($value); |
| 666 | 666 | $this->xmlWriter->endElement(); |
| 667 | 667 | |
| 668 | - return $this; |
|
| 668 | + return $this; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | $this->xmlWriter->text($nodeValue); |
| 690 | 690 | $this->xmlWriter->endElement(); |
| 691 | 691 | |
| 692 | - return $this; |
|
| 692 | + return $this; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | $this->xmlWriter->endElement(); |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - return $this; |
|
| 730 | + return $this; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | ODataConstants::ATOM_NAMESPACE |
| 759 | 759 | ); |
| 760 | 760 | |
| 761 | - return $this; |
|
| 761 | + return $this; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -20,23 +20,23 @@ |
||
| 20 | 20 | interface IODataWriter |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Determines if the given writer is capable of writing the response or not |
|
| 25 | - * @param Version $responseVersion the OData version of the response |
|
| 26 | - * @param string $contentType the Content Type of the response |
|
| 27 | - * @return boolean true if the writer can handle the response, false otherwise |
|
| 28 | - */ |
|
| 29 | - public function canHandle(Version $responseVersion, $contentType); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Create OData object model from the request description and transform it to required content type form |
|
| 33 | - * |
|
| 34 | - * |
|
| 35 | - * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 36 | - * |
|
| 37 | - * @return IODataWriter |
|
| 38 | - */ |
|
| 39 | - public function write($model); |
|
| 23 | + /** |
|
| 24 | + * Determines if the given writer is capable of writing the response or not |
|
| 25 | + * @param Version $responseVersion the OData version of the response |
|
| 26 | + * @param string $contentType the Content Type of the response |
|
| 27 | + * @return boolean true if the writer can handle the response, false otherwise |
|
| 28 | + */ |
|
| 29 | + public function canHandle(Version $responseVersion, $contentType); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Create OData object model from the request description and transform it to required content type form |
|
| 33 | + * |
|
| 34 | + * |
|
| 35 | + * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 36 | + * |
|
| 37 | + * @return IODataWriter |
|
| 38 | + */ |
|
| 39 | + public function write($model); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | /** |