@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | * @param SegmentDescriptor[] $segmentDescriptors Description of segments in the resource path. |
| 218 | 218 | * @param Url $requestUri |
| 219 | 219 | * @param Version $serviceMaxVersion |
| 220 | - * @param $requestVersion |
|
| 221 | - * @param $maxRequestVersion |
|
| 220 | + * @param string|null $requestVersion |
|
| 221 | + * @param string|null $maxRequestVersion |
|
| 222 | 222 | */ |
| 223 | 223 | public function __construct($segmentDescriptors, Url $requestUri, Version $serviceMaxVersion, $requestVersion, $maxRequestVersion) |
| 224 | 224 | { |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * (i) $bath |
| 383 | 383 | * http://server/NW.svc/$batch |
| 384 | 384 | * |
| 385 | - * @return ResourceSetWrapper|null |
|
| 385 | + * @return ResourceSetWrapper |
|
| 386 | 386 | */ |
| 387 | 387 | public function getTargetResourceSetWrapper() |
| 388 | 388 | { |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * (c) $bath |
| 427 | 427 | * http://server/NW.svc/$batch |
| 428 | 428 | * |
| 429 | - * @return ResourceType|null |
|
| 429 | + * @return ResourceType |
|
| 430 | 430 | */ |
| 431 | 431 | public function getTargetResourceType() |
| 432 | 432 | { |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | * (e) $bath |
| 474 | 474 | * http://server/NW.svc/$batch |
| 475 | 475 | * |
| 476 | - * @return ResourceProperty|null |
|
| 476 | + * @return ResourceProperty |
|
| 477 | 477 | */ |
| 478 | 478 | public function getProjectedProperty() |
| 479 | 479 | { |
@@ -7,11 +7,9 @@ |
||
| 7 | 7 | use POData\Common\Messages; |
| 8 | 8 | use POData\Common\Version; |
| 9 | 9 | use POData\Common\ODataException; |
| 10 | -use POData\IService; |
|
| 11 | 10 | use POData\Providers\Metadata\ResourceProperty; |
| 12 | 11 | use POData\Providers\Metadata\ResourceSetWrapper; |
| 13 | 12 | use POData\Providers\Metadata\ResourceStreamInfo; |
| 14 | -use POData\UriProcessor\QueryProcessor\QueryProcessor; |
|
| 15 | 13 | use POData\UriProcessor\UriProcessor; |
| 16 | 14 | use POData\UriProcessor\ResourcePathProcessor\SegmentParser\TargetSource; |
| 17 | 15 | use POData\UriProcessor\ResourcePathProcessor\SegmentParser\TargetKind; |
@@ -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) { |
@@ -245,8 +245,8 @@ discard block |
||
| 245 | 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 | - if($this->maxServiceVersion == Version::v3()){ |
|
| 249 | - if(is_null($maxRequestVersion)) |
|
| 248 | + if ($this->maxServiceVersion == Version::v3()) { |
|
| 249 | + if (is_null($maxRequestVersion)) |
|
| 250 | 250 | { |
| 251 | 251 | //if max request version isn't specified we use the service max version instead of the request version |
| 252 | 252 | //thus we favour newer versions |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @throws ODataException If capability negotiation fails. |
| 283 | 283 | */ |
| 284 | 284 | public function raiseMinVersionRequirement($major, $minor) { |
| 285 | - if($this->requiredMinRequestVersion->raiseVersion($major, $minor)) |
|
| 285 | + if ($this->requiredMinRequestVersion->raiseVersion($major, $minor)) |
|
| 286 | 286 | { |
| 287 | 287 | $this->validateVersions(); |
| 288 | 288 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @throws ODataException If capability negotiation fails. |
| 299 | 299 | */ |
| 300 | 300 | public function raiseResponseVersion($major, $minor) { |
| 301 | - if($this->requiredMinResponseVersion->raiseVersion($major, $minor)){ |
|
| 301 | + if ($this->requiredMinResponseVersion->raiseVersion($major, $minor)) { |
|
| 302 | 302 | $this->validateVersions(); |
| 303 | 303 | } |
| 304 | 304 | |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | * |
| 624 | 624 | * @return void |
| 625 | 625 | */ |
| 626 | - public function setInternalOrderByInfo(InternalOrderByInfo &$internalOrderByInfo) |
|
| 626 | + public function setInternalOrderByInfo(InternalOrderByInfo & $internalOrderByInfo) |
|
| 627 | 627 | { |
| 628 | 628 | $this->internalOrderByInfo = $internalOrderByInfo; |
| 629 | 629 | } |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | * @return void |
| 648 | 648 | */ |
| 649 | 649 | public function setInternalSkipTokenInfo( |
| 650 | - InternalSkipTokenInfo &$internalSkipTokenInfo |
|
| 650 | + InternalSkipTokenInfo & $internalSkipTokenInfo |
|
| 651 | 651 | ) { |
| 652 | 652 | $this->_internalSkipTokenInfo = $internalSkipTokenInfo; |
| 653 | 653 | } |
@@ -679,9 +679,9 @@ discard block |
||
| 679 | 679 | * |
| 680 | 680 | * @return void |
| 681 | 681 | */ |
| 682 | - public function setRootProjectionNode(RootProjectionNode &$rootProjectionNode) |
|
| 682 | + public function setRootProjectionNode(RootProjectionNode & $rootProjectionNode) |
|
| 683 | 683 | { |
| 684 | - $this->_rootProjectionNode = $rootProjectionNode; |
|
| 684 | + $this->_rootProjectionNode = $rootProjectionNode; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * KeyDescription. |
| 203 | 203 | * |
| 204 | 204 | * @param string $keyPredicate The predicate to parse |
| 205 | - * @param KeyDescriptor &$keyDescriptor On return, Description of key after |
|
| 205 | + * @param KeyDescriptor KeyDescriptor On return, Description of key after |
|
| 206 | 206 | * parsing |
| 207 | 207 | * |
| 208 | 208 | * @return boolean True if the given values were parsed; false if there was |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | * the type if valid this function provide the PHP value equivalent to |
| 455 | 455 | * the astoira URI key value |
| 456 | 456 | * |
| 457 | - * @param unknown $value The Astoria URI key value |
|
| 457 | + * @param string $value The Astoria URI key value |
|
| 458 | 458 | * @param ExpressionTokenId $tokenId The tokenId for $value literal |
| 459 | 459 | * @param unknown &$outValue After the invocation, this parameter |
| 460 | 460 | * holds the PHP value equivalent to $value, |
@@ -16,7 +16,6 @@ |
||
| 16 | 16 | use POData\Providers\Metadata\Type\Int32; |
| 17 | 17 | use POData\Providers\Metadata\Type\Null1; |
| 18 | 18 | use POData\UriProcessor\QueryProcessor\ExpressionParser\ExpressionTokenId; |
| 19 | -use POData\UriProcessor\QueryProcessor\ExpressionParser\ExpressionToken; |
|
| 20 | 19 | use POData\UriProcessor\QueryProcessor\ExpressionParser\ExpressionLexer; |
| 21 | 20 | use POData\Common\Messages; |
| 22 | 21 | |
@@ -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 | |
@@ -470,39 +470,39 @@ |
||
| 470 | 470 | private static function _getTypeAndValidateKeyValue($value, $tokenId, &$outValue, &$outType) |
| 471 | 471 | { |
| 472 | 472 | switch ($tokenId) { |
| 473 | - case ExpressionTokenId::BOOLEAN_LITERAL: |
|
| 474 | - $outType = new Boolean(); |
|
| 475 | - break; |
|
| 476 | - case ExpressionTokenId::DATETIME_LITERAL: |
|
| 477 | - $outType = new DateTime(); |
|
| 478 | - break; |
|
| 479 | - case ExpressionTokenId::GUID_LITERAL: |
|
| 480 | - $outType = new Guid(); |
|
| 481 | - break; |
|
| 482 | - case ExpressionTokenId::STRING_LITERAL: |
|
| 483 | - $outType = new String(); |
|
| 484 | - break; |
|
| 485 | - case ExpressionTokenId::INTEGER_LITERAL: |
|
| 486 | - $outType = new Int32(); |
|
| 487 | - break; |
|
| 488 | - case ExpressionTokenId::DECIMAL_LITERAL: |
|
| 489 | - $outType = new Decimal(); |
|
| 490 | - break; |
|
| 491 | - case ExpressionTokenId::DOUBLE_LITERAL: |
|
| 492 | - $outType = new Double(); |
|
| 493 | - break; |
|
| 494 | - case ExpressionTokenId::INT64_LITERAL: |
|
| 495 | - $outType = new Int64(); |
|
| 496 | - break; |
|
| 497 | - case ExpressionTokenId::SINGLE_LITERAL: |
|
| 498 | - $outType = new Single(); |
|
| 499 | - break; |
|
| 500 | - case ExpressionTokenId::NULL_LITERAL: |
|
| 501 | - $outType = new Null1(); |
|
| 502 | - break; |
|
| 503 | - default: |
|
| 504 | - $outType = null; |
|
| 505 | - return false; |
|
| 473 | + case ExpressionTokenId::BOOLEAN_LITERAL: |
|
| 474 | + $outType = new Boolean(); |
|
| 475 | + break; |
|
| 476 | + case ExpressionTokenId::DATETIME_LITERAL: |
|
| 477 | + $outType = new DateTime(); |
|
| 478 | + break; |
|
| 479 | + case ExpressionTokenId::GUID_LITERAL: |
|
| 480 | + $outType = new Guid(); |
|
| 481 | + break; |
|
| 482 | + case ExpressionTokenId::STRING_LITERAL: |
|
| 483 | + $outType = new String(); |
|
| 484 | + break; |
|
| 485 | + case ExpressionTokenId::INTEGER_LITERAL: |
|
| 486 | + $outType = new Int32(); |
|
| 487 | + break; |
|
| 488 | + case ExpressionTokenId::DECIMAL_LITERAL: |
|
| 489 | + $outType = new Decimal(); |
|
| 490 | + break; |
|
| 491 | + case ExpressionTokenId::DOUBLE_LITERAL: |
|
| 492 | + $outType = new Double(); |
|
| 493 | + break; |
|
| 494 | + case ExpressionTokenId::INT64_LITERAL: |
|
| 495 | + $outType = new Int64(); |
|
| 496 | + break; |
|
| 497 | + case ExpressionTokenId::SINGLE_LITERAL: |
|
| 498 | + $outType = new Single(); |
|
| 499 | + break; |
|
| 500 | + case ExpressionTokenId::NULL_LITERAL: |
|
| 501 | + $outType = new Null1(); |
|
| 502 | + break; |
|
| 503 | + default: |
|
| 504 | + $outType = null; |
|
| 505 | + return false; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | if (!$outType->validate($value, $outValue)) { |
@@ -271,7 +271,7 @@ |
||
| 271 | 271 | if (!array_key_exists($keyName, $this->_namedValues)) { |
| 272 | 272 | $keysAsString = null; |
| 273 | 273 | foreach (array_keys($keyProperties) as $key) { |
| 274 | - $keysAsString .= $key . ', '; |
|
| 274 | + $keysAsString .= $key.', '; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | $keysAsString = rtrim($keysAsString, ' ,'); |
@@ -142,6 +142,10 @@ |
||
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | + /** |
|
| 146 | + * @param string $segment |
|
| 147 | + * @param boolean $checkRights |
|
| 148 | + */ |
|
| 145 | 149 | private function createNextSegment(SegmentDescriptor $previous, $segment, $checkRights){ |
| 146 | 150 | $previousKind = $previous->getTargetKind(); |
| 147 | 151 | if ($previousKind == TargetKind::METADATA() |
@@ -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); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param ProvidersWrapper $providerWrapper Reference to metadata and query provider wrapper |
| 52 | 52 | * |
| 53 | 53 | */ |
| 54 | - private function __construct(ProvidersWrapper $providerWrapper ) { |
|
| 54 | + private function __construct(ProvidersWrapper $providerWrapper) { |
|
| 55 | 55 | $this->providerWrapper = $providerWrapper; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - private function createNextSegment(SegmentDescriptor $previous, $segment, $checkRights){ |
|
| 145 | + private function createNextSegment(SegmentDescriptor $previous, $segment, $checkRights) { |
|
| 146 | 146 | $previousKind = $previous->getTargetKind(); |
| 147 | 147 | if ($previousKind == TargetKind::METADATA() |
| 148 | 148 | || $previousKind == TargetKind::BATCH() |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | ); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - switch($projectedProperty->getKind()) { |
|
| 266 | + switch ($projectedProperty->getKind()) { |
|
| 267 | 267 | case ResourcePropertyKind::COMPLEX_TYPE: |
| 268 | 268 | $current->setTargetKind(TargetKind::COMPLEX_OBJECT()); |
| 269 | 269 | break; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | if ($hasPredicate) { |
| 298 | 298 | $this->_assertion(!$current->isSingleResult()); |
| 299 | 299 | $keyDescriptor = $this->_createKeyDescriptor( |
| 300 | - $identifier . '(' . $keyPredicate . ')', |
|
| 300 | + $identifier.'('.$keyPredicate.')', |
|
| 301 | 301 | $projectedProperty->getResourceType(), |
| 302 | 302 | $keyPredicate |
| 303 | 303 | ); |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ($checkRights&& !is_null($current->getTargetResourceSetWrapper())) { |
|
| 310 | + if ($checkRights && !is_null($current->getTargetResourceSetWrapper())) { |
|
| 311 | 311 | $current->getTargetResourceSetWrapper() |
| 312 | 312 | ->checkResourceSetRightsForRead( |
| 313 | 313 | $current->isSingleResult() |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | $descriptor->setTargetKind(TargetKind::RESOURCE()); |
| 374 | 374 | if ($keyPredicate !== null) { |
| 375 | 375 | $keyDescriptor = $this->_createKeyDescriptor( |
| 376 | - $segmentIdentifier . '(' . $keyPredicate . ')', |
|
| 376 | + $segmentIdentifier.'('.$keyPredicate.')', |
|
| 377 | 377 | $resourceSetWrapper->getResourceType(), |
| 378 | 378 | $keyPredicate |
| 379 | 379 | ); |
@@ -15,7 +15,6 @@ |
||
| 15 | 15 | use POData\UriProcessor\ResourcePathProcessor\SegmentParser\TargetKind; |
| 16 | 16 | use POData\UriProcessor\ResourcePathProcessor\SegmentParser\TargetSource; |
| 17 | 17 | use POData\IService; |
| 18 | -use POData\Common\Url; |
|
| 19 | 18 | use POData\Common\Messages; |
| 20 | 19 | use POData\Common\ODataException; |
| 21 | 20 | use POData\Common\InvalidOperationException; |
@@ -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, |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | //Parse the query string options of the request Uri. |
| 117 | - QueryProcessor::process( $uriProcessor->request, $service ); |
|
| 117 | + QueryProcessor::process($uriProcessor->request, $service); |
|
| 118 | 118 | |
| 119 | 119 | return $uriProcessor; |
| 120 | 120 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return void |
| 218 | 218 | * |
| 219 | 219 | */ |
| 220 | - private function handleSegmentTargetsToResourceSet( SegmentDescriptor $segment ) { |
|
| 220 | + private function handleSegmentTargetsToResourceSet(SegmentDescriptor $segment) { |
|
| 221 | 221 | if ($segment->isSingleResult()) { |
| 222 | 222 | $entityInstance = $this->providers->getResourceFromResourceSet( |
| 223 | 223 | $segment->getTargetResourceSetWrapper(), |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | //and just work with the QueryResult in the object model serializer |
| 308 | 308 | $result = $segment->getResult(); |
| 309 | 309 | |
| 310 | - if(!$result instanceof QueryResult){ |
|
| 310 | + if (!$result instanceof QueryResult) { |
|
| 311 | 311 | //If the segment isn't a query result, then there's no paging or counting to be done |
| 312 | 312 | return; |
| 313 | 313 | } |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | //Have POData perform paging if necessary |
| 327 | - if(!$this->providers->handlesOrderedPaging() && !empty($result->results)){ |
|
| 327 | + if (!$this->providers->handlesOrderedPaging() && !empty($result->results)) { |
|
| 328 | 328 | $result->results = $this->performPaging($result->results); |
| 329 | 329 | } |
| 330 | 330 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | if (!empty($result)) { |
| 368 | 368 | $top = $this->request->getTopCount(); |
| 369 | 369 | $skip = $this->request->getSkipCount(); |
| 370 | - if(is_null($skip)) $skip = 0; |
|
| 370 | + if (is_null($skip)) $skip = 0; |
|
| 371 | 371 | |
| 372 | 372 | $result = array_slice($result, $skip, $top); |
| 373 | 373 | } |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @throws InvalidOperationException If this function invoked with non-navigation |
| 575 | 575 | * property instance. |
| 576 | 576 | */ |
| 577 | - private function _pushSegmentForNavigationProperty(ResourceProperty &$resourceProperty) |
|
| 577 | + private function _pushSegmentForNavigationProperty(ResourceProperty & $resourceProperty) |
|
| 578 | 578 | { |
| 579 | 579 | if ($resourceProperty->getTypeKind() == ResourceTypeKind::ENTITY) { |
| 580 | 580 | $this->assert( |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | * |
| 670 | 670 | * @return bool true if the segment was push, false otherwise |
| 671 | 671 | */ |
| 672 | - private function _pushSegment($segmentName, ResourceSetWrapper &$resourceSetWrapper) |
|
| 672 | + private function _pushSegment($segmentName, ResourceSetWrapper & $resourceSetWrapper) |
|
| 673 | 673 | { |
| 674 | 674 | $rootProjectionNode = $this->request->getRootProjectionNode(); |
| 675 | 675 | if (!is_null($rootProjectionNode) |
@@ -367,7 +367,9 @@ |
||
| 367 | 367 | if (!empty($result)) { |
| 368 | 368 | $top = $this->request->getTopCount(); |
| 369 | 369 | $skip = $this->request->getSkipCount(); |
| 370 | - if(is_null($skip)) $skip = 0; |
|
| 370 | + if(is_null($skip)) { |
|
| 371 | + $skip = 0; |
|
| 372 | + } |
|
| 371 | 373 | |
| 372 | 374 | $result = array_slice($result, $skip, $top); |
| 373 | 375 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | - * @param ODataUrl $url the url to write. |
|
| 105 | + * @param ODataURL $url the url to write. |
|
| 106 | 106 | * |
| 107 | 107 | * @return AtomODataWriter |
| 108 | 108 | */ |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | /** |
| 120 | 120 | * Begin write odata links |
| 121 | 121 | * |
| 122 | - * @param ODataUrlCollection $urls Object of ODataUrlCollection to start writing collection of url. |
|
| 122 | + * @param ODataURLCollection $urls Object of ODataUrlCollection to start writing collection of url. |
|
| 123 | 123 | * |
| 124 | 124 | * |
| 125 | 125 | * @return AtomODataWriter |
@@ -415,10 +415,10 @@ discard block |
||
| 415 | 415 | /** |
| 416 | 416 | * XML write a basic data type (string, number, boolean, null) |
| 417 | 417 | * |
| 418 | - * @param mixed $value value to be written |
|
| 418 | + * @param string $value value to be written |
|
| 419 | 419 | * @param string $type data type of the value |
| 420 | 420 | * |
| 421 | - * @return mixed |
|
| 421 | + * @return string |
|
| 422 | 422 | */ |
| 423 | 423 | protected function beforeWriteValue($value, $type = null) |
| 424 | 424 | { |
@@ -11,7 +11,6 @@ |
||
| 11 | 11 | use POData\ObjectModel\ODataPropertyContent; |
| 12 | 12 | use POData\ObjectModel\ODataBagContent; |
| 13 | 13 | use POData\ObjectModel\ODataProperty; |
| 14 | -use POData\ObjectModel\ODataMediaLink; |
|
| 15 | 14 | use POData\Writers\IODataWriter; |
| 16 | 15 | use POData\Common\ODataConstants; |
| 17 | 16 | use POData\Common\MimeTypes; |
@@ -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 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
| 155 | - if ($urls->nextPageLink!=null) { |
|
| 155 | + if ($urls->nextPageLink != null) { |
|
| 156 | 156 | $this->writeLinkNode($urls->nextPageLink, false); |
| 157 | 157 | } |
| 158 | 158 | $this->xmlWriter->endElement(); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $feed->title |
| 185 | 185 | ) |
| 186 | 186 | ->writeNodeValue(ODataConstants::ATOM_ID_ELEMENT_NAME, $feed->id) |
| 187 | - ->writeNodeValue(ODataConstants::ATOM_UPDATED_ELEMENT_NAME, date(DATE_ATOM) ) |
|
| 187 | + ->writeNodeValue(ODataConstants::ATOM_UPDATED_ELEMENT_NAME, date(DATE_ATOM)) |
|
| 188 | 188 | ->writeLinkNode($feed->selfLink, false); |
| 189 | 189 | |
| 190 | 190 | if ($feed->rowCount != null) { |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | $property->name, |
| 500 | 500 | null |
| 501 | 501 | ); |
| 502 | - if ($property->typeName!=null) { |
|
| 502 | + if ($property->typeName != null) { |
|
| 503 | 503 | $this->xmlWriter->startAttributeNs( |
| 504 | 504 | ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, |
| 505 | 505 | ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | $this->xmlWriter->startAttributeNs(ODataConstants::XMLNS_NAMESPACE_PREFIX, ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, null); |
| 516 | 516 | $this->xmlWriter->text(ODataConstants::ODATA_METADATA_NAMESPACE); |
| 517 | 517 | } |
| 518 | - if ($property->typeName!=null || $isTopLevel) { |
|
| 518 | + if ($property->typeName != null || $isTopLevel) { |
|
| 519 | 519 | $this->xmlWriter->endAttribute(); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @param ProvidersWrapper $providers |
| 781 | 781 | * @return IODataWriter |
| 782 | 782 | */ |
| 783 | - public function writeServiceDocument(ProvidersWrapper $providers){ |
|
| 783 | + public function writeServiceDocument(ProvidersWrapper $providers) { |
|
| 784 | 784 | $writer = $this->xmlWriter; |
| 785 | 785 | $writer->startElementNs(null, ODataConstants::ATOM_PUBLISHING_SERVICE_ELEMENT_NAME, ODataConstants::APP_NAMESPACE); |
| 786 | 786 | $writer->writeAttributeNs(ODataConstants::XML_NAMESPACE_PREFIX, ODataConstants::XML_BASE_ATTRIBUTE_NAME, null, $this->baseUri); |
@@ -43,6 +43,9 @@ discard block |
||
| 43 | 43 | protected $baseUri; |
| 44 | 44 | |
| 45 | 45 | |
| 46 | + /** |
|
| 47 | + * @param string $absoluteServiceUri |
|
| 48 | + */ |
|
| 46 | 49 | public function __construct(JsonLightMetadataLevel $metadataLevel, $absoluteServiceUri) |
| 47 | 50 | { |
| 48 | 51 | if(strlen($absoluteServiceUri) == 0) |
@@ -148,6 +151,9 @@ discard block |
||
| 148 | 151 | |
| 149 | 152 | |
| 150 | 153 | |
| 154 | + /** |
|
| 155 | + * @param string $fragment |
|
| 156 | + */ |
|
| 151 | 157 | protected function writeTopLevelMeta($fragment) |
| 152 | 158 | { |
| 153 | 159 | if($this->metadataLevel == JsonLightMetadataLevel::NONE()) |
@@ -10,15 +10,10 @@ |
||
| 10 | 10 | use POData\ObjectModel\ODataPropertyContent; |
| 11 | 11 | use POData\ObjectModel\ODataBagContent; |
| 12 | 12 | use POData\ObjectModel\ODataProperty; |
| 13 | -use POData\ObjectModel\ODataMediaLink; |
|
| 14 | 13 | use POData\Writers\Json\JsonWriter; |
| 15 | 14 | use POData\Common\Version; |
| 16 | 15 | use POData\Common\ODataConstants; |
| 17 | 16 | use POData\Common\MimeTypes; |
| 18 | -use POData\Common\Messages; |
|
| 19 | -use POData\Common\ODataException; |
|
| 20 | -use POData\Common\InvalidOperationException; |
|
| 21 | - |
|
| 22 | 17 | use POData\Writers\Json\JsonLightMetadataLevel; |
| 23 | 18 | |
| 24 | 19 | |
@@ -29,255 +29,255 @@ discard block |
||
| 29 | 29 | class JsonLightODataWriter extends JsonODataV2Writer |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var JsonLightMetadataLevel |
|
| 34 | - */ |
|
| 35 | - protected $metadataLevel; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * |
|
| 40 | - * The service base uri |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - protected $baseUri; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - public function __construct(JsonLightMetadataLevel $metadataLevel, $absoluteServiceUri) |
|
| 47 | - { |
|
| 48 | - if(strlen($absoluteServiceUri) == 0) |
|
| 49 | - { |
|
| 50 | - throw new \Exception("absoluteServiceUri must not be empty or null"); |
|
| 51 | - } |
|
| 52 | - $this->baseUri = $absoluteServiceUri; |
|
| 53 | - |
|
| 54 | - $this->_writer = new JsonWriter(''); |
|
| 55 | - $this->urlKey = ODataConstants::JSON_URL_STRING; |
|
| 56 | - $this->dataArrayName = ODataConstants::JSON_LIGHT_VALUE_NAME; |
|
| 57 | - $this->rowCountName = ODataConstants::JSON_LIGHT_ROWCOUNT_STRING; |
|
| 58 | - $this->metadataLevel = $metadataLevel; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Determines if the given writer is capable of writing the response or not |
|
| 64 | - * @param Version $responseVersion the OData version of the response |
|
| 65 | - * @param string $contentType the Content Type of the response |
|
| 66 | - * @return boolean true if the writer can handle the response, false otherwise |
|
| 67 | - */ |
|
| 68 | - public function canHandle(Version $responseVersion, $contentType) |
|
| 69 | - { |
|
| 70 | - if($responseVersion != Version::v3()){ |
|
| 71 | - return false; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $parts = explode(";", $contentType); |
|
| 75 | - |
|
| 76 | - //It must be app/json and have the right odata= piece |
|
| 77 | - return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts) && in_array($this->metadataLevel->getValue(), $parts); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Write the given OData model in a specific response format |
|
| 84 | - * |
|
| 85 | - * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 86 | - * |
|
| 87 | - * @return JsonLightODataWriter |
|
| 88 | - */ |
|
| 89 | - public function write($model){ |
|
| 90 | - $this->_writer->startObjectScope(); |
|
| 91 | - |
|
| 92 | - if ($model instanceof ODataURL) { |
|
| 93 | - $this->writeTopLevelMeta("url"); |
|
| 94 | - $this->writeURL($model); |
|
| 95 | - } elseif ($model instanceof ODataURLCollection) { |
|
| 96 | - $this->writeTopLevelMeta("urlCollection"); |
|
| 97 | - $this->writeURLCollection($model); |
|
| 98 | - } elseif ($model instanceof ODataPropertyContent) { |
|
| 99 | - $this->writeTopLevelMeta( $model->properties[0]->typeName ); |
|
| 100 | - $this->writeTopLevelProperty($model->properties[0]); |
|
| 101 | - } elseif ($model instanceof ODataFeed) { |
|
| 102 | - $this->writeTopLevelMeta($model->title); |
|
| 103 | - $this->writeRowCount($model->rowCount); |
|
| 104 | - $this->writeNextPageLink($model->nextPageLink); |
|
| 105 | - $this->_writer |
|
| 106 | - ->writeName($this->dataArrayName) |
|
| 107 | - ->startArrayScope(); |
|
| 108 | - $this->writeFeed($model); |
|
| 109 | - $this->_writer->endScope(); |
|
| 110 | - }elseif ($model instanceof ODataEntry) { |
|
| 111 | - $this->writeTopLevelMeta($model->resourceSetName . "/@Element"); |
|
| 112 | - $this->writeEntry($model); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->_writer->endScope(); |
|
| 116 | - |
|
| 117 | - return $this; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * |
|
| 123 | - * @param ODataProperty $property |
|
| 124 | - * |
|
| 125 | - * @return JsonLightODataWriter |
|
| 126 | - */ |
|
| 127 | - protected function writeTopLevelProperty(ODataProperty $property) |
|
| 128 | - { |
|
| 129 | - $this->writePropertyMeta($property); |
|
| 130 | - if ($property->value == null) { |
|
| 131 | - $this->_writer->writeName(ODataConstants::JSON_LIGHT_VALUE_NAME); |
|
| 132 | - $this->_writer->writeValue("null"); |
|
| 133 | - } elseif ($property->value instanceof ODataPropertyContent) { |
|
| 134 | - //In the case of complex properties at the top level we don't write the name of the property, |
|
| 135 | - //just the sub properties. |
|
| 136 | - $this->writeComplexPropertyMeta($property) |
|
| 137 | - ->writeProperties($property->value); |
|
| 138 | - } elseif ($property->value instanceof ODataBagContent) { |
|
| 139 | - $this->_writer->writeName(ODataConstants::JSON_LIGHT_VALUE_NAME); |
|
| 140 | - $this->writeBagContent($property->value); |
|
| 141 | - } else { |
|
| 142 | - $this->_writer->writeName(ODataConstants::JSON_LIGHT_VALUE_NAME); |
|
| 143 | - $this->_writer->writeValue($property->value, $property->typeName); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - protected function writeTopLevelMeta($fragment) |
|
| 152 | - { |
|
| 153 | - if($this->metadataLevel == JsonLightMetadataLevel::NONE()) |
|
| 154 | - { |
|
| 155 | - return; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $this->_writer |
|
| 159 | - ->writeName(ODataConstants::JSON_LIGHT_METADATA_STRING) |
|
| 160 | - ->writeValue($this->baseUri . '/' . ODataConstants::URI_METADATA_SEGMENT . '#' . $fragment); |
|
| 161 | - |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - protected function writePropertyMeta(ODataProperty $property) |
|
| 166 | - { |
|
| 167 | - if($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 168 | - { |
|
| 169 | - //Only full meta level outputs this info |
|
| 170 | - return $this; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if(is_null($property->value)) |
|
| 174 | - { |
|
| 175 | - //it appears full metadata doesn't output types for nulls... |
|
| 176 | - return $this; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - switch($property->typeName) |
|
| 181 | - { |
|
| 182 | - //The type metadata is only included on certain types of properties |
|
| 183 | - //Note this also excludes Complex types |
|
| 184 | - |
|
| 185 | - case "Edm.Decimal": |
|
| 186 | - case "Edm.DateTime": |
|
| 187 | - $this->_writer |
|
| 188 | - ->writeName($property->name . ODataConstants::JSON_LIGHT_METADATA_PROPERTY_TYPE_SUFFIX_STRING) |
|
| 189 | - ->writeValue($property->typeName); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - return $this; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * |
|
| 198 | - * @param ODataEntry $entry Entry to write metadata for. |
|
| 199 | - * |
|
| 200 | - * @return JsonLightODataWriter |
|
| 201 | - */ |
|
| 202 | - protected function writeEntryMetadata(ODataEntry $entry){ |
|
| 203 | - |
|
| 204 | - if($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 205 | - { |
|
| 206 | - //Only full meta level outputs this info |
|
| 207 | - return $this; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $this->_writer |
|
| 211 | - ->writeName(ODataConstants::JSON_LIGHT_METADATA_TYPE_STRING) |
|
| 212 | - ->writeValue($entry->type) |
|
| 213 | - ->writeName(ODataConstants::JSON_LIGHT_METADATA_ID_STRING) |
|
| 214 | - ->writeValue($entry->id) |
|
| 215 | - ->writeName(ODataConstants::JSON_LIGHT_METADATA_ETAG_STRING) |
|
| 216 | - ->writeValue($entry->eTag) |
|
| 217 | - ->writeName(ODataConstants::JSON_LIGHT_METADATA_EDIT_LINK_STRING) |
|
| 218 | - ->writeValue($entry->editLink) |
|
| 219 | - ; |
|
| 220 | - |
|
| 221 | - return $this; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param ODataLink $link Link to write. |
|
| 227 | - * |
|
| 228 | - * @return JsonLightODataWriter |
|
| 229 | - */ |
|
| 230 | - protected function writeLink(ODataLink $link){ |
|
| 231 | - |
|
| 232 | - if($this->metadataLevel == JsonLightMetadataLevel::FULL()) |
|
| 233 | - { |
|
| 234 | - //Interestingly the fullmetadata outputs this metadata..even if the thing is expanded |
|
| 235 | - $this->_writer |
|
| 236 | - ->writeName($link->title . ODataConstants::JSON_LIGHT_METADATA_LINK_NAVIGATION_SUFFIX_STRING) |
|
| 237 | - ->writeValue($link->url);; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - if($link->isExpanded) |
|
| 242 | - { |
|
| 243 | - $this->_writer->writeName($link->title); |
|
| 244 | - |
|
| 245 | - if(is_null($link->expandedResult)) { |
|
| 246 | - $this->_writer->writeValue("null"); |
|
| 247 | - } else { |
|
| 248 | - $this->writeExpandedLink($link); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $this; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - protected function writeExpandedLink(ODataLink $link) |
|
| 256 | - { |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - if ($link->isCollection) { |
|
| 260 | - $this->_writer->startArrayScope(); |
|
| 261 | - $this->writeFeed($link->expandedResult); |
|
| 262 | - } else { |
|
| 263 | - $this->_writer->startObjectScope(); |
|
| 264 | - $this->writeEntry($link->expandedResult); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - $this->_writer->endScope(); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Writes the next page link. |
|
| 273 | - * |
|
| 274 | - * @param ODataLink $nextPageLinkUri Uri for next page link. |
|
| 275 | - * |
|
| 276 | - * @return JsonLightODataWriter |
|
| 277 | - */ |
|
| 278 | - protected function writeNextPageLink(ODataLink $nextPageLinkUri = null) |
|
| 279 | - { |
|
| 280 | - /* |
|
| 32 | + /** |
|
| 33 | + * @var JsonLightMetadataLevel |
|
| 34 | + */ |
|
| 35 | + protected $metadataLevel; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * |
|
| 40 | + * The service base uri |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + protected $baseUri; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + public function __construct(JsonLightMetadataLevel $metadataLevel, $absoluteServiceUri) |
|
| 47 | + { |
|
| 48 | + if(strlen($absoluteServiceUri) == 0) |
|
| 49 | + { |
|
| 50 | + throw new \Exception("absoluteServiceUri must not be empty or null"); |
|
| 51 | + } |
|
| 52 | + $this->baseUri = $absoluteServiceUri; |
|
| 53 | + |
|
| 54 | + $this->_writer = new JsonWriter(''); |
|
| 55 | + $this->urlKey = ODataConstants::JSON_URL_STRING; |
|
| 56 | + $this->dataArrayName = ODataConstants::JSON_LIGHT_VALUE_NAME; |
|
| 57 | + $this->rowCountName = ODataConstants::JSON_LIGHT_ROWCOUNT_STRING; |
|
| 58 | + $this->metadataLevel = $metadataLevel; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Determines if the given writer is capable of writing the response or not |
|
| 64 | + * @param Version $responseVersion the OData version of the response |
|
| 65 | + * @param string $contentType the Content Type of the response |
|
| 66 | + * @return boolean true if the writer can handle the response, false otherwise |
|
| 67 | + */ |
|
| 68 | + public function canHandle(Version $responseVersion, $contentType) |
|
| 69 | + { |
|
| 70 | + if($responseVersion != Version::v3()){ |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $parts = explode(";", $contentType); |
|
| 75 | + |
|
| 76 | + //It must be app/json and have the right odata= piece |
|
| 77 | + return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts) && in_array($this->metadataLevel->getValue(), $parts); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Write the given OData model in a specific response format |
|
| 84 | + * |
|
| 85 | + * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 86 | + * |
|
| 87 | + * @return JsonLightODataWriter |
|
| 88 | + */ |
|
| 89 | + public function write($model){ |
|
| 90 | + $this->_writer->startObjectScope(); |
|
| 91 | + |
|
| 92 | + if ($model instanceof ODataURL) { |
|
| 93 | + $this->writeTopLevelMeta("url"); |
|
| 94 | + $this->writeURL($model); |
|
| 95 | + } elseif ($model instanceof ODataURLCollection) { |
|
| 96 | + $this->writeTopLevelMeta("urlCollection"); |
|
| 97 | + $this->writeURLCollection($model); |
|
| 98 | + } elseif ($model instanceof ODataPropertyContent) { |
|
| 99 | + $this->writeTopLevelMeta( $model->properties[0]->typeName ); |
|
| 100 | + $this->writeTopLevelProperty($model->properties[0]); |
|
| 101 | + } elseif ($model instanceof ODataFeed) { |
|
| 102 | + $this->writeTopLevelMeta($model->title); |
|
| 103 | + $this->writeRowCount($model->rowCount); |
|
| 104 | + $this->writeNextPageLink($model->nextPageLink); |
|
| 105 | + $this->_writer |
|
| 106 | + ->writeName($this->dataArrayName) |
|
| 107 | + ->startArrayScope(); |
|
| 108 | + $this->writeFeed($model); |
|
| 109 | + $this->_writer->endScope(); |
|
| 110 | + }elseif ($model instanceof ODataEntry) { |
|
| 111 | + $this->writeTopLevelMeta($model->resourceSetName . "/@Element"); |
|
| 112 | + $this->writeEntry($model); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->_writer->endScope(); |
|
| 116 | + |
|
| 117 | + return $this; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * |
|
| 123 | + * @param ODataProperty $property |
|
| 124 | + * |
|
| 125 | + * @return JsonLightODataWriter |
|
| 126 | + */ |
|
| 127 | + protected function writeTopLevelProperty(ODataProperty $property) |
|
| 128 | + { |
|
| 129 | + $this->writePropertyMeta($property); |
|
| 130 | + if ($property->value == null) { |
|
| 131 | + $this->_writer->writeName(ODataConstants::JSON_LIGHT_VALUE_NAME); |
|
| 132 | + $this->_writer->writeValue("null"); |
|
| 133 | + } elseif ($property->value instanceof ODataPropertyContent) { |
|
| 134 | + //In the case of complex properties at the top level we don't write the name of the property, |
|
| 135 | + //just the sub properties. |
|
| 136 | + $this->writeComplexPropertyMeta($property) |
|
| 137 | + ->writeProperties($property->value); |
|
| 138 | + } elseif ($property->value instanceof ODataBagContent) { |
|
| 139 | + $this->_writer->writeName(ODataConstants::JSON_LIGHT_VALUE_NAME); |
|
| 140 | + $this->writeBagContent($property->value); |
|
| 141 | + } else { |
|
| 142 | + $this->_writer->writeName(ODataConstants::JSON_LIGHT_VALUE_NAME); |
|
| 143 | + $this->_writer->writeValue($property->value, $property->typeName); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + protected function writeTopLevelMeta($fragment) |
|
| 152 | + { |
|
| 153 | + if($this->metadataLevel == JsonLightMetadataLevel::NONE()) |
|
| 154 | + { |
|
| 155 | + return; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $this->_writer |
|
| 159 | + ->writeName(ODataConstants::JSON_LIGHT_METADATA_STRING) |
|
| 160 | + ->writeValue($this->baseUri . '/' . ODataConstants::URI_METADATA_SEGMENT . '#' . $fragment); |
|
| 161 | + |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + protected function writePropertyMeta(ODataProperty $property) |
|
| 166 | + { |
|
| 167 | + if($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 168 | + { |
|
| 169 | + //Only full meta level outputs this info |
|
| 170 | + return $this; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if(is_null($property->value)) |
|
| 174 | + { |
|
| 175 | + //it appears full metadata doesn't output types for nulls... |
|
| 176 | + return $this; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + switch($property->typeName) |
|
| 181 | + { |
|
| 182 | + //The type metadata is only included on certain types of properties |
|
| 183 | + //Note this also excludes Complex types |
|
| 184 | + |
|
| 185 | + case "Edm.Decimal": |
|
| 186 | + case "Edm.DateTime": |
|
| 187 | + $this->_writer |
|
| 188 | + ->writeName($property->name . ODataConstants::JSON_LIGHT_METADATA_PROPERTY_TYPE_SUFFIX_STRING) |
|
| 189 | + ->writeValue($property->typeName); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + return $this; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * |
|
| 198 | + * @param ODataEntry $entry Entry to write metadata for. |
|
| 199 | + * |
|
| 200 | + * @return JsonLightODataWriter |
|
| 201 | + */ |
|
| 202 | + protected function writeEntryMetadata(ODataEntry $entry){ |
|
| 203 | + |
|
| 204 | + if($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 205 | + { |
|
| 206 | + //Only full meta level outputs this info |
|
| 207 | + return $this; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $this->_writer |
|
| 211 | + ->writeName(ODataConstants::JSON_LIGHT_METADATA_TYPE_STRING) |
|
| 212 | + ->writeValue($entry->type) |
|
| 213 | + ->writeName(ODataConstants::JSON_LIGHT_METADATA_ID_STRING) |
|
| 214 | + ->writeValue($entry->id) |
|
| 215 | + ->writeName(ODataConstants::JSON_LIGHT_METADATA_ETAG_STRING) |
|
| 216 | + ->writeValue($entry->eTag) |
|
| 217 | + ->writeName(ODataConstants::JSON_LIGHT_METADATA_EDIT_LINK_STRING) |
|
| 218 | + ->writeValue($entry->editLink) |
|
| 219 | + ; |
|
| 220 | + |
|
| 221 | + return $this; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param ODataLink $link Link to write. |
|
| 227 | + * |
|
| 228 | + * @return JsonLightODataWriter |
|
| 229 | + */ |
|
| 230 | + protected function writeLink(ODataLink $link){ |
|
| 231 | + |
|
| 232 | + if($this->metadataLevel == JsonLightMetadataLevel::FULL()) |
|
| 233 | + { |
|
| 234 | + //Interestingly the fullmetadata outputs this metadata..even if the thing is expanded |
|
| 235 | + $this->_writer |
|
| 236 | + ->writeName($link->title . ODataConstants::JSON_LIGHT_METADATA_LINK_NAVIGATION_SUFFIX_STRING) |
|
| 237 | + ->writeValue($link->url);; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + if($link->isExpanded) |
|
| 242 | + { |
|
| 243 | + $this->_writer->writeName($link->title); |
|
| 244 | + |
|
| 245 | + if(is_null($link->expandedResult)) { |
|
| 246 | + $this->_writer->writeValue("null"); |
|
| 247 | + } else { |
|
| 248 | + $this->writeExpandedLink($link); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $this; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + protected function writeExpandedLink(ODataLink $link) |
|
| 256 | + { |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + if ($link->isCollection) { |
|
| 260 | + $this->_writer->startArrayScope(); |
|
| 261 | + $this->writeFeed($link->expandedResult); |
|
| 262 | + } else { |
|
| 263 | + $this->_writer->startObjectScope(); |
|
| 264 | + $this->writeEntry($link->expandedResult); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + $this->_writer->endScope(); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Writes the next page link. |
|
| 273 | + * |
|
| 274 | + * @param ODataLink $nextPageLinkUri Uri for next page link. |
|
| 275 | + * |
|
| 276 | + * @return JsonLightODataWriter |
|
| 277 | + */ |
|
| 278 | + protected function writeNextPageLink(ODataLink $nextPageLinkUri = null) |
|
| 279 | + { |
|
| 280 | + /* |
|
| 281 | 281 | // "__next" : uri |
| 282 | 282 | if ($nextPageLinkUri != null) { |
| 283 | 283 | $this->_writer |
@@ -287,48 +287,48 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | return $this; |
| 289 | 289 | */ |
| 290 | - } |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Begin write complex property. |
|
| 295 | - * |
|
| 296 | - * @param ODataProperty $property property to write. |
|
| 297 | - * |
|
| 298 | - * @return JsonLightODataWriter |
|
| 299 | - */ |
|
| 300 | - protected function writeComplexProperty(ODataProperty $property) |
|
| 301 | - { |
|
| 293 | + /** |
|
| 294 | + * Begin write complex property. |
|
| 295 | + * |
|
| 296 | + * @param ODataProperty $property property to write. |
|
| 297 | + * |
|
| 298 | + * @return JsonLightODataWriter |
|
| 299 | + */ |
|
| 300 | + protected function writeComplexProperty(ODataProperty $property) |
|
| 301 | + { |
|
| 302 | 302 | |
| 303 | - // { |
|
| 304 | - $this->_writer->startObjectScope(); |
|
| 303 | + // { |
|
| 304 | + $this->_writer->startObjectScope(); |
|
| 305 | 305 | |
| 306 | - $this->writeComplexPropertyMeta($property) |
|
| 307 | - ->writeProperties($property->value); |
|
| 306 | + $this->writeComplexPropertyMeta($property) |
|
| 307 | + ->writeProperties($property->value); |
|
| 308 | 308 | |
| 309 | - $this->_writer->endScope(); |
|
| 309 | + $this->_writer->endScope(); |
|
| 310 | 310 | |
| 311 | - return $this; |
|
| 312 | - } |
|
| 311 | + return $this; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - protected function writeComplexPropertyMeta(ODataProperty $property) |
|
| 315 | - { |
|
| 316 | - if($this->metadataLevel == JsonLightMetadataLevel::FULL()){ |
|
| 317 | - $this->_writer |
|
| 318 | - ->writeName(ODataConstants::JSON_LIGHT_METADATA_TYPE_STRING) |
|
| 319 | - ->writeValue($property->typeName); |
|
| 320 | - } |
|
| 314 | + protected function writeComplexPropertyMeta(ODataProperty $property) |
|
| 315 | + { |
|
| 316 | + if($this->metadataLevel == JsonLightMetadataLevel::FULL()){ |
|
| 317 | + $this->_writer |
|
| 318 | + ->writeName(ODataConstants::JSON_LIGHT_METADATA_TYPE_STRING) |
|
| 319 | + ->writeValue($property->typeName); |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - return $this; |
|
| 323 | - } |
|
| 322 | + return $this; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - protected function writeBagContent(ODataBagContent $bag) |
|
| 326 | - { |
|
| 325 | + protected function writeBagContent(ODataBagContent $bag) |
|
| 326 | + { |
|
| 327 | 327 | |
| 328 | - $this->_writer |
|
| 328 | + $this->_writer |
|
| 329 | 329 | |
| 330 | 330 | |
| 331 | - /* |
|
| 331 | + /* |
|
| 332 | 332 | ->writeName(ODataConstants::JSON_METADATA_STRING) //__metadata : { Type : "typename" } |
| 333 | 333 | ->startObjectScope() |
| 334 | 334 | |
@@ -338,24 +338,24 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | |
| 340 | 340 | |
| 341 | - ->startArrayScope(); // [ |
|
| 341 | + ->startArrayScope(); // [ |
|
| 342 | 342 | |
| 343 | - foreach ($bag->propertyContents as $content) { |
|
| 344 | - if ($content instanceof ODataPropertyContent) { |
|
| 345 | - $this->_writer->startObjectScope(); |
|
| 346 | - $this->writeProperties($content); |
|
| 347 | - $this->_writer->endScope(); |
|
| 348 | - } else { |
|
| 349 | - // retrieving the collection datatype in order |
|
| 350 | - //to write in json specific format, with in chords or not |
|
| 351 | - preg_match('#\((.*?)\)#', $bag->type, $type); |
|
| 352 | - $this->_writer->writeValue($content, $type[1]); |
|
| 353 | - } |
|
| 354 | - } |
|
| 343 | + foreach ($bag->propertyContents as $content) { |
|
| 344 | + if ($content instanceof ODataPropertyContent) { |
|
| 345 | + $this->_writer->startObjectScope(); |
|
| 346 | + $this->writeProperties($content); |
|
| 347 | + $this->_writer->endScope(); |
|
| 348 | + } else { |
|
| 349 | + // retrieving the collection datatype in order |
|
| 350 | + //to write in json specific format, with in chords or not |
|
| 351 | + preg_match('#\((.*?)\)#', $bag->type, $type); |
|
| 352 | + $this->_writer->writeValue($content, $type[1]); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | |
| 357 | - $this->_writer->endScope(); // ] |
|
| 358 | - return $this; |
|
| 359 | - } |
|
| 357 | + $this->_writer->endScope(); // ] |
|
| 358 | + return $this; |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | 361 | } |
| 362 | 362 | \ No newline at end of file |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public function __construct(JsonLightMetadataLevel $metadataLevel, $absoluteServiceUri) |
| 47 | 47 | { |
| 48 | - if(strlen($absoluteServiceUri) == 0) |
|
| 48 | + if (strlen($absoluteServiceUri) == 0) |
|
| 49 | 49 | { |
| 50 | 50 | throw new \Exception("absoluteServiceUri must not be empty or null"); |
| 51 | 51 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function canHandle(Version $responseVersion, $contentType) |
| 69 | 69 | { |
| 70 | - if($responseVersion != Version::v3()){ |
|
| 70 | + if ($responseVersion != Version::v3()) { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return JsonLightODataWriter |
| 88 | 88 | */ |
| 89 | - public function write($model){ |
|
| 89 | + public function write($model) { |
|
| 90 | 90 | $this->_writer->startObjectScope(); |
| 91 | 91 | |
| 92 | 92 | if ($model instanceof ODataURL) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $this->writeTopLevelMeta("urlCollection"); |
| 97 | 97 | $this->writeURLCollection($model); |
| 98 | 98 | } elseif ($model instanceof ODataPropertyContent) { |
| 99 | - $this->writeTopLevelMeta( $model->properties[0]->typeName ); |
|
| 99 | + $this->writeTopLevelMeta($model->properties[0]->typeName); |
|
| 100 | 100 | $this->writeTopLevelProperty($model->properties[0]); |
| 101 | 101 | } elseif ($model instanceof ODataFeed) { |
| 102 | 102 | $this->writeTopLevelMeta($model->title); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $this->writeFeed($model); |
| 109 | 109 | $this->_writer->endScope(); |
| 110 | 110 | }elseif ($model instanceof ODataEntry) { |
| 111 | - $this->writeTopLevelMeta($model->resourceSetName . "/@Element"); |
|
| 111 | + $this->writeTopLevelMeta($model->resourceSetName."/@Element"); |
|
| 112 | 112 | $this->writeEntry($model); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -150,34 +150,34 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | protected function writeTopLevelMeta($fragment) |
| 152 | 152 | { |
| 153 | - if($this->metadataLevel == JsonLightMetadataLevel::NONE()) |
|
| 153 | + if ($this->metadataLevel == JsonLightMetadataLevel::NONE()) |
|
| 154 | 154 | { |
| 155 | 155 | return; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $this->_writer |
| 159 | 159 | ->writeName(ODataConstants::JSON_LIGHT_METADATA_STRING) |
| 160 | - ->writeValue($this->baseUri . '/' . ODataConstants::URI_METADATA_SEGMENT . '#' . $fragment); |
|
| 160 | + ->writeValue($this->baseUri.'/'.ODataConstants::URI_METADATA_SEGMENT.'#'.$fragment); |
|
| 161 | 161 | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
| 165 | 165 | protected function writePropertyMeta(ODataProperty $property) |
| 166 | 166 | { |
| 167 | - if($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 167 | + if ($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 168 | 168 | { |
| 169 | 169 | //Only full meta level outputs this info |
| 170 | 170 | return $this; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if(is_null($property->value)) |
|
| 173 | + if (is_null($property->value)) |
|
| 174 | 174 | { |
| 175 | 175 | //it appears full metadata doesn't output types for nulls... |
| 176 | 176 | return $this; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
| 180 | - switch($property->typeName) |
|
| 180 | + switch ($property->typeName) |
|
| 181 | 181 | { |
| 182 | 182 | //The type metadata is only included on certain types of properties |
| 183 | 183 | //Note this also excludes Complex types |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | case "Edm.Decimal": |
| 186 | 186 | case "Edm.DateTime": |
| 187 | 187 | $this->_writer |
| 188 | - ->writeName($property->name . ODataConstants::JSON_LIGHT_METADATA_PROPERTY_TYPE_SUFFIX_STRING) |
|
| 188 | + ->writeName($property->name.ODataConstants::JSON_LIGHT_METADATA_PROPERTY_TYPE_SUFFIX_STRING) |
|
| 189 | 189 | ->writeValue($property->typeName); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return JsonLightODataWriter |
| 201 | 201 | */ |
| 202 | - protected function writeEntryMetadata(ODataEntry $entry){ |
|
| 202 | + protected function writeEntryMetadata(ODataEntry $entry) { |
|
| 203 | 203 | |
| 204 | - if($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 204 | + if ($this->metadataLevel != JsonLightMetadataLevel::FULL()) |
|
| 205 | 205 | { |
| 206 | 206 | //Only full meta level outputs this info |
| 207 | 207 | return $this; |
@@ -227,22 +227,22 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @return JsonLightODataWriter |
| 229 | 229 | */ |
| 230 | - protected function writeLink(ODataLink $link){ |
|
| 230 | + protected function writeLink(ODataLink $link) { |
|
| 231 | 231 | |
| 232 | - if($this->metadataLevel == JsonLightMetadataLevel::FULL()) |
|
| 232 | + if ($this->metadataLevel == JsonLightMetadataLevel::FULL()) |
|
| 233 | 233 | { |
| 234 | 234 | //Interestingly the fullmetadata outputs this metadata..even if the thing is expanded |
| 235 | 235 | $this->_writer |
| 236 | - ->writeName($link->title . ODataConstants::JSON_LIGHT_METADATA_LINK_NAVIGATION_SUFFIX_STRING) |
|
| 237 | - ->writeValue($link->url);; |
|
| 236 | + ->writeName($link->title.ODataConstants::JSON_LIGHT_METADATA_LINK_NAVIGATION_SUFFIX_STRING) |
|
| 237 | + ->writeValue($link->url); ; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
| 241 | - if($link->isExpanded) |
|
| 241 | + if ($link->isExpanded) |
|
| 242 | 242 | { |
| 243 | 243 | $this->_writer->writeName($link->title); |
| 244 | 244 | |
| 245 | - if(is_null($link->expandedResult)) { |
|
| 245 | + if (is_null($link->expandedResult)) { |
|
| 246 | 246 | $this->_writer->writeValue("null"); |
| 247 | 247 | } else { |
| 248 | 248 | $this->writeExpandedLink($link); |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | protected function writeComplexPropertyMeta(ODataProperty $property) |
| 315 | 315 | { |
| 316 | - if($this->metadataLevel == JsonLightMetadataLevel::FULL()){ |
|
| 316 | + if ($this->metadataLevel == JsonLightMetadataLevel::FULL()) { |
|
| 317 | 317 | $this->_writer |
| 318 | 318 | ->writeName(ODataConstants::JSON_LIGHT_METADATA_TYPE_STRING) |
| 319 | 319 | ->writeValue($property->typeName); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
| 357 | - $this->_writer->endScope(); // ] |
|
| 357 | + $this->_writer->endScope(); // ] |
|
| 358 | 358 | return $this; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | ->startArrayScope(); |
| 108 | 108 | $this->writeFeed($model); |
| 109 | 109 | $this->_writer->endScope(); |
| 110 | - }elseif ($model instanceof ODataEntry) { |
|
| 110 | + } elseif ($model instanceof ODataEntry) { |
|
| 111 | 111 | $this->writeTopLevelMeta($model->resourceSetName . "/@Element"); |
| 112 | 112 | $this->writeEntry($model); |
| 113 | 113 | } |
@@ -10,15 +10,12 @@ |
||
| 10 | 10 | use POData\ObjectModel\ODataPropertyContent; |
| 11 | 11 | use POData\ObjectModel\ODataBagContent; |
| 12 | 12 | use POData\ObjectModel\ODataProperty; |
| 13 | -use POData\ObjectModel\ODataMediaLink; |
|
| 14 | 13 | use POData\Writers\Json\JsonWriter; |
| 15 | 14 | use POData\Writers\IODataWriter; |
| 16 | 15 | use POData\Common\Version; |
| 17 | 16 | use POData\Common\ODataConstants; |
| 18 | 17 | use POData\Common\MimeTypes; |
| 19 | -use POData\Common\Messages; |
|
| 20 | 18 | use POData\Common\ODataException; |
| 21 | -use POData\Common\InvalidOperationException; |
|
| 22 | 19 | use POData\Providers\ProvidersWrapper; |
| 23 | 20 | |
| 24 | 21 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | protected $_writer; |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - protected $urlKey = ODataConstants::JSON_URI_STRING; |
|
| 37 | + protected $urlKey = ODataConstants::JSON_URI_STRING; |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Constructs and initializes the Json output writer. |
@@ -45,60 +45,60 @@ discard block |
||
| 45 | 45 | $this->_writer = new JsonWriter(''); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Determines if the given writer is capable of writing the response or not |
|
| 50 | - * @param Version $responseVersion the OData version of the response |
|
| 51 | - * @param string $contentType the Content Type of the response |
|
| 52 | - * @return boolean true if the writer can handle the response, false otherwise |
|
| 53 | - */ |
|
| 54 | - public function canHandle(Version $responseVersion, $contentType) |
|
| 55 | - { |
|
| 56 | - if($responseVersion != Version::v1()){ |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $parts = explode(";", $contentType); |
|
| 61 | - |
|
| 62 | - return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Write the given OData model in a specific response format |
|
| 67 | - * |
|
| 68 | - * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 69 | - * |
|
| 70 | - * @return JsonODataV1Writer |
|
| 71 | - */ |
|
| 72 | - public function write($model){ |
|
| 73 | - // { "d" : |
|
| 74 | - $this->_writer |
|
| 75 | - ->startObjectScope() |
|
| 76 | - ->writeName("d"); |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - if ($model instanceof ODataURL) { |
|
| 80 | - $this->_writer->startObjectScope(); |
|
| 81 | - $this->writeURL($model); |
|
| 82 | - } elseif ($model instanceof ODataURLCollection) { |
|
| 83 | - $this->_writer->startArrayScope(); |
|
| 84 | - $this->writeURLCollection($model); |
|
| 85 | - } elseif ($model instanceof ODataPropertyContent) { |
|
| 86 | - $this->_writer->startObjectScope(); |
|
| 87 | - $this->writeProperties($model); |
|
| 88 | - } elseif ($model instanceof ODataFeed) { |
|
| 89 | - $this->_writer->startArrayScope(); |
|
| 90 | - $this->writeFeed($model); |
|
| 91 | - }elseif ($model instanceof ODataEntry) { |
|
| 92 | - $this->_writer->startObjectScope(); |
|
| 93 | - $this->writeEntry($model); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - $this->_writer->endScope(); |
|
| 98 | - $this->_writer->endScope(); |
|
| 99 | - |
|
| 100 | - return $this; |
|
| 101 | - } |
|
| 48 | + /** |
|
| 49 | + * Determines if the given writer is capable of writing the response or not |
|
| 50 | + * @param Version $responseVersion the OData version of the response |
|
| 51 | + * @param string $contentType the Content Type of the response |
|
| 52 | + * @return boolean true if the writer can handle the response, false otherwise |
|
| 53 | + */ |
|
| 54 | + public function canHandle(Version $responseVersion, $contentType) |
|
| 55 | + { |
|
| 56 | + if($responseVersion != Version::v1()){ |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $parts = explode(";", $contentType); |
|
| 61 | + |
|
| 62 | + return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Write the given OData model in a specific response format |
|
| 67 | + * |
|
| 68 | + * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 69 | + * |
|
| 70 | + * @return JsonODataV1Writer |
|
| 71 | + */ |
|
| 72 | + public function write($model){ |
|
| 73 | + // { "d" : |
|
| 74 | + $this->_writer |
|
| 75 | + ->startObjectScope() |
|
| 76 | + ->writeName("d"); |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + if ($model instanceof ODataURL) { |
|
| 80 | + $this->_writer->startObjectScope(); |
|
| 81 | + $this->writeURL($model); |
|
| 82 | + } elseif ($model instanceof ODataURLCollection) { |
|
| 83 | + $this->_writer->startArrayScope(); |
|
| 84 | + $this->writeURLCollection($model); |
|
| 85 | + } elseif ($model instanceof ODataPropertyContent) { |
|
| 86 | + $this->_writer->startObjectScope(); |
|
| 87 | + $this->writeProperties($model); |
|
| 88 | + } elseif ($model instanceof ODataFeed) { |
|
| 89 | + $this->_writer->startArrayScope(); |
|
| 90 | + $this->writeFeed($model); |
|
| 91 | + }elseif ($model instanceof ODataEntry) { |
|
| 92 | + $this->_writer->startObjectScope(); |
|
| 93 | + $this->writeEntry($model); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + $this->_writer->endScope(); |
|
| 98 | + $this->_writer->endScope(); |
|
| 99 | + |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -110,9 +110,9 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $this->_writer |
| 112 | 112 | ->writeName($this->urlKey) |
| 113 | - ->writeValue($url->url); |
|
| 113 | + ->writeValue($url->url); |
|
| 114 | 114 | |
| 115 | - return $this; |
|
| 115 | + return $this; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -125,11 +125,11 @@ discard block |
||
| 125 | 125 | public function writeUrlCollection(ODataURLCollection $urls) |
| 126 | 126 | { |
| 127 | 127 | foreach ($urls->urls as $url) { |
| 128 | - $this->_writer->startObjectScope(); |
|
| 128 | + $this->_writer->startObjectScope(); |
|
| 129 | 129 | $this->writeUrl($url); |
| 130 | - $this->_writer->endScope(); |
|
| 130 | + $this->_writer->endScope(); |
|
| 131 | 131 | } |
| 132 | - return $this; |
|
| 132 | + return $this; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | protected function writeFeed(ODataFeed $feed) |
| 143 | 143 | { |
| 144 | 144 | |
| 145 | - foreach ($feed->entries as $entry) { |
|
| 146 | - $this->_writer->startObjectScope(); |
|
| 147 | - $this->writeEntry($entry); |
|
| 148 | - $this->_writer->endScope(); |
|
| 149 | - } |
|
| 145 | + foreach ($feed->entries as $entry) { |
|
| 146 | + $this->_writer->startObjectScope(); |
|
| 147 | + $this->writeEntry($entry); |
|
| 148 | + $this->_writer->endScope(); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | - return $this; |
|
| 152 | + return $this; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -163,15 +163,15 @@ discard block |
||
| 163 | 163 | protected function writeEntry(ODataEntry $entry) |
| 164 | 164 | { |
| 165 | 165 | |
| 166 | - $this->writeEntryMetadata($entry); |
|
| 167 | - foreach ($entry->links as $link) { |
|
| 168 | - $this->writeLink($link); |
|
| 169 | - } |
|
| 166 | + $this->writeEntryMetadata($entry); |
|
| 167 | + foreach ($entry->links as $link) { |
|
| 168 | + $this->writeLink($link); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - $this->writeProperties($entry->propertyContent); |
|
| 171 | + $this->writeProperties($entry->propertyContent); |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - return $this; |
|
| 174 | + return $this; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -187,28 +187,28 @@ discard block |
||
| 187 | 187 | if ($entry->id != null || $entry->type != null || $entry->eTag != null) { |
| 188 | 188 | // "__metadata" |
| 189 | 189 | $this->_writer |
| 190 | - ->writeName(ODataConstants::JSON_METADATA_STRING) |
|
| 190 | + ->writeName(ODataConstants::JSON_METADATA_STRING) |
|
| 191 | 191 | ->startObjectScope(); |
| 192 | 192 | |
| 193 | 193 | // Write uri value only for entity types |
| 194 | 194 | if ($entry->id != null) { |
| 195 | 195 | $this->_writer |
| 196 | - ->writeName($this->urlKey) |
|
| 196 | + ->writeName($this->urlKey) |
|
| 197 | 197 | ->writeValue($entry->id); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Write the etag property, if the entry has etag properties. |
| 201 | 201 | if ($entry->eTag != null) { |
| 202 | 202 | $this->_writer |
| 203 | - ->writeName(ODataConstants::JSON_ETAG_STRING) |
|
| 203 | + ->writeName(ODataConstants::JSON_ETAG_STRING) |
|
| 204 | 204 | ->writeValue($entry->eTag); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | // Write the type property, if the entry has type properties. |
| 208 | 208 | if ($entry->type != null) { |
| 209 | 209 | $this->_writer |
| 210 | - ->writeName(ODataConstants::JSON_TYPE_STRING) |
|
| 211 | - ->writeValue($entry->type); |
|
| 210 | + ->writeName(ODataConstants::JSON_TYPE_STRING) |
|
| 211 | + ->writeValue($entry->type); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
@@ -216,19 +216,19 @@ discard block |
||
| 216 | 216 | if ($entry->isMediaLinkEntry) { |
| 217 | 217 | if ($entry->mediaLink != null) { |
| 218 | 218 | $this->_writer |
| 219 | - ->writeName(ODataConstants::JSON_EDITMEDIA_STRING) |
|
| 220 | - ->writeValue($entry->mediaLink->editLink) |
|
| 219 | + ->writeName(ODataConstants::JSON_EDITMEDIA_STRING) |
|
| 220 | + ->writeValue($entry->mediaLink->editLink) |
|
| 221 | 221 | |
| 222 | - ->writeName(ODataConstants::JSON_MEDIASRC_STRING) |
|
| 223 | - ->writeValue($entry->mediaLink->srcLink) |
|
| 222 | + ->writeName(ODataConstants::JSON_MEDIASRC_STRING) |
|
| 223 | + ->writeValue($entry->mediaLink->srcLink) |
|
| 224 | 224 | |
| 225 | - ->writeName(ODataConstants::JSON_CONTENTTYPE_STRING) |
|
| 226 | - ->writeValue($entry->mediaLink->contentType); |
|
| 225 | + ->writeName(ODataConstants::JSON_CONTENTTYPE_STRING) |
|
| 226 | + ->writeValue($entry->mediaLink->contentType); |
|
| 227 | 227 | |
| 228 | 228 | if ($entry->mediaLink->eTag != null) { |
| 229 | 229 | $this->_writer |
| 230 | - ->writeName(ODataConstants::JSON_MEDIAETAG_STRING) |
|
| 231 | - ->writeValue($entry->mediaLink->eTag); |
|
| 230 | + ->writeName(ODataConstants::JSON_MEDIAETAG_STRING) |
|
| 231 | + ->writeValue($entry->mediaLink->eTag); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | $this->_writer->endScope(); |
@@ -237,19 +237,19 @@ discard block |
||
| 237 | 237 | // writing named resource streams |
| 238 | 238 | foreach ($entry->mediaLinks as $mediaLink) { |
| 239 | 239 | $this->_writer |
| 240 | - ->writeName($mediaLink->name) |
|
| 241 | - ->startObjectScope() |
|
| 240 | + ->writeName($mediaLink->name) |
|
| 241 | + ->startObjectScope() |
|
| 242 | 242 | |
| 243 | - ->writeName(ODataConstants::JSON_MEDIASRC_STRING) |
|
| 244 | - ->writeValue($mediaLink->srcLink) |
|
| 243 | + ->writeName(ODataConstants::JSON_MEDIASRC_STRING) |
|
| 244 | + ->writeValue($mediaLink->srcLink) |
|
| 245 | 245 | |
| 246 | - ->writeName(ODataConstants::JSON_CONTENTTYPE_STRING) |
|
| 247 | - ->writeValue($mediaLink->contentType); |
|
| 246 | + ->writeName(ODataConstants::JSON_CONTENTTYPE_STRING) |
|
| 247 | + ->writeValue($mediaLink->contentType); |
|
| 248 | 248 | |
| 249 | 249 | if ($mediaLink->eTag != null) { |
| 250 | 250 | $this->_writer |
| 251 | - ->writeName(ODataConstants::JSON_MEDIAETAG_STRING) |
|
| 252 | - ->writeValue($mediaLink->eTag); |
|
| 251 | + ->writeName(ODataConstants::JSON_MEDIAETAG_STRING) |
|
| 252 | + ->writeValue($mediaLink->eTag); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $this->_writer->endScope(); |
@@ -258,92 +258,92 @@ discard block |
||
| 258 | 258 | $this->_writer->endScope(); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - return $this; |
|
| 261 | + return $this; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * @param ODataLink $link Link to write. |
|
| 267 | - * |
|
| 268 | - * @return JsonODataV1Writer |
|
| 269 | - */ |
|
| 270 | - protected function writeLink(ODataLink $link) |
|
| 265 | + /** |
|
| 266 | + * @param ODataLink $link Link to write. |
|
| 267 | + * |
|
| 268 | + * @return JsonODataV1Writer |
|
| 269 | + */ |
|
| 270 | + protected function writeLink(ODataLink $link) |
|
| 271 | 271 | { |
| 272 | 272 | |
| 273 | 273 | // "<linkname>" : |
| 274 | 274 | $this->_writer->writeName($link->title); |
| 275 | 275 | |
| 276 | - if ($link->isExpanded) { |
|
| 277 | - if(is_null($link->expandedResult)){ |
|
| 278 | - $this->_writer->writeValue("null"); |
|
| 279 | - } |
|
| 280 | - else{ |
|
| 281 | - $this->writeExpandedLink($link); |
|
| 282 | - } |
|
| 283 | - } else { |
|
| 284 | - $this->_writer |
|
| 285 | - ->startObjectScope() |
|
| 286 | - ->writeName(ODataConstants::JSON_DEFERRED_STRING) |
|
| 287 | - ->startObjectScope() |
|
| 288 | - ->writeName($this->urlKey) |
|
| 289 | - ->writeValue($link->url) |
|
| 290 | - ->endScope() |
|
| 291 | - ->endScope() |
|
| 292 | - ; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - return $this; |
|
| 276 | + if ($link->isExpanded) { |
|
| 277 | + if(is_null($link->expandedResult)){ |
|
| 278 | + $this->_writer->writeValue("null"); |
|
| 279 | + } |
|
| 280 | + else{ |
|
| 281 | + $this->writeExpandedLink($link); |
|
| 282 | + } |
|
| 283 | + } else { |
|
| 284 | + $this->_writer |
|
| 285 | + ->startObjectScope() |
|
| 286 | + ->writeName(ODataConstants::JSON_DEFERRED_STRING) |
|
| 287 | + ->startObjectScope() |
|
| 288 | + ->writeName($this->urlKey) |
|
| 289 | + ->writeValue($link->url) |
|
| 290 | + ->endScope() |
|
| 291 | + ->endScope() |
|
| 292 | + ; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + return $this; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + protected function writeExpandedLink(ODataLink $link) |
|
| 299 | + { |
|
| 300 | + if ($link->isCollection) { |
|
| 301 | + $this->_writer->startArrayScope(); |
|
| 302 | + $this->writeFeed($link->expandedResult); |
|
| 303 | + } else { |
|
| 304 | + $this->_writer->startObjectScope(); |
|
| 305 | + $this->writeEntry($link->expandedResult); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + $this->_writer->endScope(); |
|
| 296 | 309 | } |
| 297 | 310 | |
| 298 | - protected function writeExpandedLink(ODataLink $link) |
|
| 299 | - { |
|
| 300 | - if ($link->isCollection) { |
|
| 301 | - $this->_writer->startArrayScope(); |
|
| 302 | - $this->writeFeed($link->expandedResult); |
|
| 303 | - } else { |
|
| 304 | - $this->_writer->startObjectScope(); |
|
| 305 | - $this->writeEntry($link->expandedResult); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - $this->_writer->endScope(); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Write the given collection of properties. |
|
| 314 | - * (properties of an entity or complex type) |
|
| 315 | - * |
|
| 316 | - * @param ODataPropertyContent $properties Collection of properties. |
|
| 317 | - * |
|
| 318 | - * @return JsonODataV1Writer |
|
| 319 | - */ |
|
| 320 | - protected function writeProperties(ODataPropertyContent $properties) |
|
| 321 | - { |
|
| 322 | - foreach ($properties->properties as $property) { |
|
| 323 | - |
|
| 324 | - $this->writePropertyMeta($property); |
|
| 325 | - $this->_writer->writeName($property->name); |
|
| 326 | - |
|
| 327 | - if ($property->value == null) { |
|
| 328 | - $this->_writer->writeValue("null"); |
|
| 329 | - } elseif ($property->value instanceof ODataPropertyContent) { |
|
| 330 | - $this->writeComplexProperty($property); |
|
| 331 | - } elseif ($property->value instanceof ODataBagContent) { |
|
| 332 | - $this->writeBagContent($property->value); |
|
| 333 | - } else { |
|
| 334 | - $this->_writer->writeValue($property->value, $property->typeName); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return $this; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - protected function writePropertyMeta(ODataProperty $property) |
|
| 344 | - { |
|
| 345 | - return $this; //does nothing in v1 or v2, json light outputs stuff |
|
| 346 | - } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Write the given collection of properties. |
|
| 314 | + * (properties of an entity or complex type) |
|
| 315 | + * |
|
| 316 | + * @param ODataPropertyContent $properties Collection of properties. |
|
| 317 | + * |
|
| 318 | + * @return JsonODataV1Writer |
|
| 319 | + */ |
|
| 320 | + protected function writeProperties(ODataPropertyContent $properties) |
|
| 321 | + { |
|
| 322 | + foreach ($properties->properties as $property) { |
|
| 323 | + |
|
| 324 | + $this->writePropertyMeta($property); |
|
| 325 | + $this->_writer->writeName($property->name); |
|
| 326 | + |
|
| 327 | + if ($property->value == null) { |
|
| 328 | + $this->_writer->writeValue("null"); |
|
| 329 | + } elseif ($property->value instanceof ODataPropertyContent) { |
|
| 330 | + $this->writeComplexProperty($property); |
|
| 331 | + } elseif ($property->value instanceof ODataBagContent) { |
|
| 332 | + $this->writeBagContent($property->value); |
|
| 333 | + } else { |
|
| 334 | + $this->_writer->writeValue($property->value, $property->typeName); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return $this; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + protected function writePropertyMeta(ODataProperty $property) |
|
| 344 | + { |
|
| 345 | + return $this; //does nothing in v1 or v2, json light outputs stuff |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | 348 | /** |
| 349 | 349 | * Begin write complex property. |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | { |
| 357 | 357 | |
| 358 | 358 | $this->_writer |
| 359 | - // { |
|
| 360 | - ->startObjectScope() |
|
| 359 | + // { |
|
| 360 | + ->startObjectScope() |
|
| 361 | 361 | |
| 362 | - // __metadata : { Type : "typename" } |
|
| 363 | - ->writeName(ODataConstants::JSON_METADATA_STRING) |
|
| 364 | - ->startObjectScope() |
|
| 365 | - ->writeName(ODataConstants::JSON_TYPE_STRING) |
|
| 366 | - ->writeValue($property->typeName) |
|
| 367 | - ->endScope(); |
|
| 362 | + // __metadata : { Type : "typename" } |
|
| 363 | + ->writeName(ODataConstants::JSON_METADATA_STRING) |
|
| 364 | + ->startObjectScope() |
|
| 365 | + ->writeName(ODataConstants::JSON_TYPE_STRING) |
|
| 366 | + ->writeValue($property->typeName) |
|
| 367 | + ->endScope(); |
|
| 368 | 368 | |
| 369 | - $this->writeProperties($property->value); |
|
| 369 | + $this->writeProperties($property->value); |
|
| 370 | 370 | |
| 371 | - $this->_writer->endScope(); |
|
| 371 | + $this->_writer->endScope(); |
|
| 372 | 372 | |
| 373 | - return $this; |
|
| 373 | + return $this; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | |
@@ -385,15 +385,15 @@ discard block |
||
| 385 | 385 | { |
| 386 | 386 | |
| 387 | 387 | $this->_writer |
| 388 | - ->startObjectScope() // { |
|
| 389 | - ->writeName(ODataConstants::JSON_METADATA_STRING) //__metadata : { Type : "typename" } |
|
| 388 | + ->startObjectScope() // { |
|
| 389 | + ->writeName(ODataConstants::JSON_METADATA_STRING) //__metadata : { Type : "typename" } |
|
| 390 | 390 | ->startObjectScope() |
| 391 | 391 | |
| 392 | 392 | ->writeName(ODataConstants::JSON_TYPE_STRING) |
| 393 | 393 | ->writeValue($bag->type) |
| 394 | 394 | ->endScope() // } |
| 395 | - ->writeName(ODataConstants::JSON_RESULT_NAME) // "__results": |
|
| 396 | - ->startArrayScope(); // [ |
|
| 395 | + ->writeName(ODataConstants::JSON_RESULT_NAME) // "__results": |
|
| 396 | + ->startArrayScope(); // [ |
|
| 397 | 397 | |
| 398 | 398 | foreach ($bag->propertyContents as $content) { |
| 399 | 399 | if ($content instanceof ODataPropertyContent) { |
@@ -410,9 +410,9 @@ discard block |
||
| 410 | 410 | |
| 411 | 411 | |
| 412 | 412 | $this->_writer |
| 413 | - ->endScope() // ] |
|
| 414 | - ->endScope(); // } |
|
| 415 | - return $this; |
|
| 413 | + ->endScope() // ] |
|
| 414 | + ->endScope(); // } |
|
| 415 | + return $this; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -433,29 +433,29 @@ discard block |
||
| 433 | 433 | $writer = new JsonWriter(''); |
| 434 | 434 | // Wrapper for error. |
| 435 | 435 | $writer |
| 436 | - ->startObjectScope() |
|
| 436 | + ->startObjectScope() |
|
| 437 | 437 | ->writeName(ODataConstants::JSON_ERROR) // "error" |
| 438 | 438 | ->startObjectScope(); |
| 439 | 439 | |
| 440 | 440 | // "code" |
| 441 | 441 | if ($exception->getCode() != null) { |
| 442 | 442 | $writer |
| 443 | - ->writeName(ODataConstants::JSON_ERROR_CODE) |
|
| 444 | - ->writeValue($exception->getCode()); |
|
| 443 | + ->writeName(ODataConstants::JSON_ERROR_CODE) |
|
| 444 | + ->writeValue($exception->getCode()); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // "message" |
| 448 | 448 | $writer |
| 449 | - ->writeName(ODataConstants::JSON_ERROR_MESSAGE) |
|
| 450 | - ->startObjectScope() |
|
| 451 | - ->writeName(ODataConstants::XML_LANG_ATTRIBUTE_NAME) // "lang" |
|
| 452 | - ->writeValue('en-US') |
|
| 449 | + ->writeName(ODataConstants::JSON_ERROR_MESSAGE) |
|
| 450 | + ->startObjectScope() |
|
| 451 | + ->writeName(ODataConstants::XML_LANG_ATTRIBUTE_NAME) // "lang" |
|
| 452 | + ->writeValue('en-US') |
|
| 453 | 453 | ->writeName(ODataConstants::JSON_ERROR_VALUE) |
| 454 | - ->writeValue($exception->getMessage()) |
|
| 454 | + ->writeValue($exception->getMessage()) |
|
| 455 | 455 | |
| 456 | - ->endScope() |
|
| 457 | - ->endScope() |
|
| 458 | - ->endScope(); |
|
| 456 | + ->endScope() |
|
| 457 | + ->endScope() |
|
| 458 | + ->endScope(); |
|
| 459 | 459 | |
| 460 | 460 | return $writer->getJsonOutput(); |
| 461 | 461 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function canHandle(Version $responseVersion, $contentType) |
| 55 | 55 | { |
| 56 | - if($responseVersion != Version::v1()){ |
|
| 56 | + if ($responseVersion != Version::v1()) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return JsonODataV1Writer |
| 71 | 71 | */ |
| 72 | - public function write($model){ |
|
| 72 | + public function write($model) { |
|
| 73 | 73 | // { "d" : |
| 74 | 74 | $this->_writer |
| 75 | 75 | ->startObjectScope() |
@@ -274,10 +274,10 @@ discard block |
||
| 274 | 274 | $this->_writer->writeName($link->title); |
| 275 | 275 | |
| 276 | 276 | if ($link->isExpanded) { |
| 277 | - if(is_null($link->expandedResult)){ |
|
| 277 | + if (is_null($link->expandedResult)) { |
|
| 278 | 278 | $this->_writer->writeValue("null"); |
| 279 | 279 | } |
| 280 | - else{ |
|
| 280 | + else { |
|
| 281 | 281 | $this->writeExpandedLink($link); |
| 282 | 282 | } |
| 283 | 283 | } else { |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * @param ProvidersWrapper $providers |
| 478 | 478 | * @return IODataWriter |
| 479 | 479 | */ |
| 480 | - public function writeServiceDocument(ProvidersWrapper $providers){ |
|
| 480 | + public function writeServiceDocument(ProvidersWrapper $providers) { |
|
| 481 | 481 | $writer = $this->_writer; |
| 482 | 482 | $writer |
| 483 | 483 | ->startObjectScope() // { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | } elseif ($model instanceof ODataFeed) { |
| 89 | 89 | $this->_writer->startArrayScope(); |
| 90 | 90 | $this->writeFeed($model); |
| 91 | - }elseif ($model instanceof ODataEntry) { |
|
| 91 | + } elseif ($model instanceof ODataEntry) { |
|
| 92 | 92 | $this->_writer->startObjectScope(); |
| 93 | 93 | $this->writeEntry($model); |
| 94 | 94 | } |
@@ -276,8 +276,7 @@ discard block |
||
| 276 | 276 | if ($link->isExpanded) { |
| 277 | 277 | if(is_null($link->expandedResult)){ |
| 278 | 278 | $this->_writer->writeValue("null"); |
| 279 | - } |
|
| 280 | - else{ |
|
| 279 | + } else{ |
|
| 281 | 280 | $this->writeExpandedLink($link); |
| 282 | 281 | } |
| 283 | 282 | } else { |
@@ -8,16 +8,9 @@ |
||
| 8 | 8 | use POData\ObjectModel\ODataURL; |
| 9 | 9 | use POData\ObjectModel\ODataLink; |
| 10 | 10 | use POData\ObjectModel\ODataPropertyContent; |
| 11 | -use POData\ObjectModel\ODataBagContent; |
|
| 12 | -use POData\ObjectModel\ODataProperty; |
|
| 13 | -use POData\ObjectModel\ODataMediaLink; |
|
| 14 | - |
|
| 15 | 11 | use POData\Common\MimeTypes; |
| 16 | 12 | use POData\Common\Version; |
| 17 | 13 | use POData\Common\ODataConstants; |
| 18 | -use POData\Common\Messages; |
|
| 19 | -use POData\Common\ODataException; |
|
| 20 | -use POData\Common\InvalidOperationException; |
|
| 21 | 14 | |
| 22 | 15 | /** |
| 23 | 16 | * Class JsonODataV2Writer is a writer for the json format in OData V2 AKA JSON Verbose |
@@ -25,87 +25,87 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | class JsonODataV2Writer extends JsonODataV1Writer |
| 27 | 27 | { |
| 28 | - //The key difference between 1 and 2 is that in 2 collection results |
|
| 29 | - //are wrapped in a "result" array. this is to allow a place for collection metadata to be placed |
|
| 30 | - // |
|
| 31 | - //IE {d : [ item1, item2, item3] } |
|
| 32 | - //is now { d : { results :[item1, item2, item3], meta1 : x, meta2 : y } |
|
| 33 | - //So we override the collection methods to shove this stuff in there |
|
| 28 | + //The key difference between 1 and 2 is that in 2 collection results |
|
| 29 | + //are wrapped in a "result" array. this is to allow a place for collection metadata to be placed |
|
| 30 | + // |
|
| 31 | + //IE {d : [ item1, item2, item3] } |
|
| 32 | + //is now { d : { results :[item1, item2, item3], meta1 : x, meta2 : y } |
|
| 33 | + //So we override the collection methods to shove this stuff in there |
|
| 34 | 34 | |
| 35 | - protected $dataArrayName = ODataConstants::JSON_RESULT_NAME; |
|
| 35 | + protected $dataArrayName = ODataConstants::JSON_RESULT_NAME; |
|
| 36 | 36 | |
| 37 | - protected $rowCountName = ODataConstants::JSON_ROWCOUNT_STRING; |
|
| 37 | + protected $rowCountName = ODataConstants::JSON_ROWCOUNT_STRING; |
|
| 38 | 38 | |
| 39 | - protected $nextLinkName = ODataConstants::JSON_NEXT_STRING; |
|
| 39 | + protected $nextLinkName = ODataConstants::JSON_NEXT_STRING; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Determines if the given writer is capable of writing the response or not |
|
| 44 | - * @param Version $responseVersion the OData version of the response |
|
| 45 | - * @param string $contentType the Content Type of the response |
|
| 46 | - * @return boolean true if the writer can handle the response, false otherwise |
|
| 47 | - */ |
|
| 48 | - public function canHandle(Version $responseVersion, $contentType) |
|
| 49 | - { |
|
| 50 | - $parts = explode(";", $contentType); |
|
| 51 | - |
|
| 52 | - //special case, in v3 verbose is the v2 writer |
|
| 53 | - if($responseVersion == Version::v3()){ |
|
| 54 | - return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts) && in_array('odata=verbose', $parts); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if($responseVersion != Version::v2()){ |
|
| 58 | - return false; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts); |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Write the given OData model in a specific response format |
|
| 68 | - * |
|
| 69 | - * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 70 | - * |
|
| 71 | - * @return JsonODataV1Writer |
|
| 72 | - */ |
|
| 73 | - public function write($model){ |
|
| 74 | - // { "d" : |
|
| 75 | - $this->_writer |
|
| 76 | - ->startObjectScope() |
|
| 77 | - ->writeName("d") |
|
| 78 | - ->startObjectScope(); |
|
| 79 | - |
|
| 42 | + /** |
|
| 43 | + * Determines if the given writer is capable of writing the response or not |
|
| 44 | + * @param Version $responseVersion the OData version of the response |
|
| 45 | + * @param string $contentType the Content Type of the response |
|
| 46 | + * @return boolean true if the writer can handle the response, false otherwise |
|
| 47 | + */ |
|
| 48 | + public function canHandle(Version $responseVersion, $contentType) |
|
| 49 | + { |
|
| 50 | + $parts = explode(";", $contentType); |
|
| 80 | 51 | |
| 81 | - if ($model instanceof ODataURL) { |
|
| 52 | + //special case, in v3 verbose is the v2 writer |
|
| 53 | + if($responseVersion == Version::v3()){ |
|
| 54 | + return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts) && in_array('odata=verbose', $parts); |
|
| 55 | + } |
|
| 82 | 56 | |
| 83 | - $this->writeURL($model); |
|
| 84 | - } elseif ($model instanceof ODataURLCollection) { |
|
| 85 | - $this->writeURLCollection($model); |
|
| 86 | - } elseif ($model instanceof ODataPropertyContent) { |
|
| 87 | - $this->writeProperties($model); |
|
| 88 | - } elseif ($model instanceof ODataFeed) { |
|
| 89 | - // Json Format V2: |
|
| 90 | - // "results": |
|
| 91 | - $this->writeRowCount($model->rowCount); |
|
| 92 | - $this->writeNextPageLink($model->nextPageLink); |
|
| 93 | - $this->_writer |
|
| 94 | - ->writeName($this->dataArrayName) |
|
| 95 | - ->startArrayScope(); |
|
| 96 | - $this->writeFeed($model); |
|
| 97 | - $this->_writer->endScope(); |
|
| 57 | + if($responseVersion != Version::v2()){ |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 98 | 60 | |
| 99 | - }elseif ($model instanceof ODataEntry) { |
|
| 100 | - $this->writeEntry($model); |
|
| 101 | - } |
|
| 61 | + return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts); |
|
| 102 | 62 | |
| 63 | + } |
|
| 103 | 64 | |
| 104 | - $this->_writer->endScope(); |
|
| 105 | - $this->_writer->endScope(); |
|
| 106 | 65 | |
| 107 | - return $this; |
|
| 108 | - } |
|
| 66 | + /** |
|
| 67 | + * Write the given OData model in a specific response format |
|
| 68 | + * |
|
| 69 | + * @param ODataURL|ODataURLCollection|ODataPropertyContent|ODataFeed|ODataEntry $model Object of requested content. |
|
| 70 | + * |
|
| 71 | + * @return JsonODataV1Writer |
|
| 72 | + */ |
|
| 73 | + public function write($model){ |
|
| 74 | + // { "d" : |
|
| 75 | + $this->_writer |
|
| 76 | + ->startObjectScope() |
|
| 77 | + ->writeName("d") |
|
| 78 | + ->startObjectScope(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + if ($model instanceof ODataURL) { |
|
| 82 | + |
|
| 83 | + $this->writeURL($model); |
|
| 84 | + } elseif ($model instanceof ODataURLCollection) { |
|
| 85 | + $this->writeURLCollection($model); |
|
| 86 | + } elseif ($model instanceof ODataPropertyContent) { |
|
| 87 | + $this->writeProperties($model); |
|
| 88 | + } elseif ($model instanceof ODataFeed) { |
|
| 89 | + // Json Format V2: |
|
| 90 | + // "results": |
|
| 91 | + $this->writeRowCount($model->rowCount); |
|
| 92 | + $this->writeNextPageLink($model->nextPageLink); |
|
| 93 | + $this->_writer |
|
| 94 | + ->writeName($this->dataArrayName) |
|
| 95 | + ->startArrayScope(); |
|
| 96 | + $this->writeFeed($model); |
|
| 97 | + $this->_writer->endScope(); |
|
| 98 | + |
|
| 99 | + }elseif ($model instanceof ODataEntry) { |
|
| 100 | + $this->writeEntry($model); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + $this->_writer->endScope(); |
|
| 105 | + $this->_writer->endScope(); |
|
| 106 | + |
|
| 107 | + return $this; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -119,76 +119,76 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | |
| 121 | 121 | $this->writeRowCount($urls->count); |
| 122 | - $this->writeNextPageLink($urls->nextPageLink); |
|
| 122 | + $this->writeNextPageLink($urls->nextPageLink); |
|
| 123 | 123 | |
| 124 | 124 | // Json Format V2: |
| 125 | 125 | // "results": |
| 126 | - $this->_writer |
|
| 127 | - ->writeName($this->dataArrayName) |
|
| 128 | - ->startArrayScope(); |
|
| 126 | + $this->_writer |
|
| 127 | + ->writeName($this->dataArrayName) |
|
| 128 | + ->startArrayScope(); |
|
| 129 | 129 | |
| 130 | - parent::writeUrlCollection($urls); |
|
| 130 | + parent::writeUrlCollection($urls); |
|
| 131 | 131 | |
| 132 | - $this->_writer->endScope(); |
|
| 132 | + $this->_writer->endScope(); |
|
| 133 | 133 | |
| 134 | - return $this; |
|
| 134 | + return $this; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Writes the row count. |
|
| 140 | - * |
|
| 141 | - * @param int $count Row count value. |
|
| 142 | - * |
|
| 143 | - * @return JsonODataV2Writer |
|
| 144 | - */ |
|
| 145 | - protected function writeRowCount($count) |
|
| 146 | - { |
|
| 147 | - if ($count != null) { |
|
| 148 | - $this->_writer->writeName($this->rowCountName); |
|
| 149 | - $this->_writer->writeValue($count); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $this; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Writes the next page link. |
|
| 158 | - * |
|
| 159 | - * @param ODataLink $nextPageLinkUri Uri for next page link. |
|
| 160 | - * |
|
| 161 | - * @return JsonODataV2Writer |
|
| 162 | - */ |
|
| 163 | - protected function writeNextPageLink(ODataLink $nextPageLinkUri = null) |
|
| 164 | - { |
|
| 165 | - // "__next" : uri |
|
| 166 | - if ($nextPageLinkUri != null) { |
|
| 167 | - $this->_writer |
|
| 168 | - ->writeName($this->nextLinkName) |
|
| 169 | - ->writeValue($nextPageLinkUri->url); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $this; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - protected function writeExpandedLink(ODataLink $link) |
|
| 176 | - { |
|
| 177 | - //Difference from v1 is that expanded collection have a result: wrapper to allow for metadata to exist |
|
| 178 | - $this->_writer->startObjectScope(); |
|
| 179 | - |
|
| 180 | - if ($link->isCollection) { |
|
| 181 | - $this->_writer |
|
| 182 | - ->writeName($this->dataArrayName) |
|
| 183 | - ->startArrayScope(); |
|
| 184 | - $this->writeFeed($link->expandedResult); |
|
| 185 | - $this->_writer->endScope(); |
|
| 186 | - } else { |
|
| 187 | - $this->writeEntry($link->expandedResult); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - $this->_writer->endScope(); |
|
| 192 | - } |
|
| 138 | + /** |
|
| 139 | + * Writes the row count. |
|
| 140 | + * |
|
| 141 | + * @param int $count Row count value. |
|
| 142 | + * |
|
| 143 | + * @return JsonODataV2Writer |
|
| 144 | + */ |
|
| 145 | + protected function writeRowCount($count) |
|
| 146 | + { |
|
| 147 | + if ($count != null) { |
|
| 148 | + $this->_writer->writeName($this->rowCountName); |
|
| 149 | + $this->_writer->writeValue($count); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $this; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Writes the next page link. |
|
| 158 | + * |
|
| 159 | + * @param ODataLink $nextPageLinkUri Uri for next page link. |
|
| 160 | + * |
|
| 161 | + * @return JsonODataV2Writer |
|
| 162 | + */ |
|
| 163 | + protected function writeNextPageLink(ODataLink $nextPageLinkUri = null) |
|
| 164 | + { |
|
| 165 | + // "__next" : uri |
|
| 166 | + if ($nextPageLinkUri != null) { |
|
| 167 | + $this->_writer |
|
| 168 | + ->writeName($this->nextLinkName) |
|
| 169 | + ->writeValue($nextPageLinkUri->url); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $this; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + protected function writeExpandedLink(ODataLink $link) |
|
| 176 | + { |
|
| 177 | + //Difference from v1 is that expanded collection have a result: wrapper to allow for metadata to exist |
|
| 178 | + $this->_writer->startObjectScope(); |
|
| 179 | + |
|
| 180 | + if ($link->isCollection) { |
|
| 181 | + $this->_writer |
|
| 182 | + ->writeName($this->dataArrayName) |
|
| 183 | + ->startArrayScope(); |
|
| 184 | + $this->writeFeed($link->expandedResult); |
|
| 185 | + $this->_writer->endScope(); |
|
| 186 | + } else { |
|
| 187 | + $this->writeEntry($link->expandedResult); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + $this->_writer->endScope(); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | \ No newline at end of file |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | $parts = explode(";", $contentType); |
| 51 | 51 | |
| 52 | 52 | //special case, in v3 verbose is the v2 writer |
| 53 | - if($responseVersion == Version::v3()){ |
|
| 53 | + if ($responseVersion == Version::v3()) { |
|
| 54 | 54 | return in_array(MimeTypes::MIME_APPLICATION_JSON, $parts) && in_array('odata=verbose', $parts); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if($responseVersion != Version::v2()){ |
|
| 57 | + if ($responseVersion != Version::v2()) { |
|
| 58 | 58 | return false; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return JsonODataV1Writer |
| 72 | 72 | */ |
| 73 | - public function write($model){ |
|
| 73 | + public function write($model) { |
|
| 74 | 74 | // { "d" : |
| 75 | 75 | $this->_writer |
| 76 | 76 | ->startObjectScope() |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | $this->writeFeed($model); |
| 97 | 97 | $this->_writer->endScope(); |
| 98 | 98 | |
| 99 | - }elseif ($model instanceof ODataEntry) { |
|
| 99 | + } elseif ($model instanceof ODataEntry) { |
|
| 100 | 100 | $this->writeEntry($model); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -3,9 +3,7 @@ |
||
| 3 | 3 | namespace POData\Writers\Json; |
| 4 | 4 | |
| 5 | 5 | |
| 6 | -use MyCLabs\Enum\Enum; |
|
| 7 | 6 | use POData\Writers\Json\IndentedTextWriter; |
| 8 | -use POData\Common\ODataConstants; |
|
| 9 | 7 | |
| 10 | 8 | /** |
| 11 | 9 | * Class JsonWriter |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | private $_jsonDateTimeFormat = "\/Date(%s)\/"; |
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 23 | + /** |
|
| 24 | 24 | * Writer to write text into |
| 25 | 25 | * |
| 26 | 26 | */ |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | public function endScope() |
| 58 | 58 | { |
| 59 | 59 | $this->_writer |
| 60 | - ->writeLine() |
|
| 61 | - ->decreaseIndent(); |
|
| 60 | + ->writeLine() |
|
| 61 | + ->decreaseIndent(); |
|
| 62 | 62 | |
| 63 | 63 | if (array_pop($this->_scopes)->type == $this->_scopeType['Array']) { |
| 64 | 64 | $this->_writer->writeValue("]"); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->_writer->writeValue("}"); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - return $this; |
|
| 69 | + return $this; |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | public function startArrayScope() |
| 79 | 79 | { |
| 80 | 80 | $this->_startScope($this->_scopeType['Array']); |
| 81 | - return $this; |
|
| 81 | + return $this; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function writeDataArrayName() |
| 91 | 91 | { |
| 92 | 92 | $this->writeName($this->dataArrayName); |
| 93 | - return $this; |
|
| 93 | + return $this; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | public function startObjectScope() |
| 102 | 102 | { |
| 103 | 103 | $this->_startScope($this->_scopeType['Object']); |
| 104 | - return $this; |
|
| 104 | + return $this; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $this->_writeCore($name, true /*quotes*/); |
| 126 | 126 | $this->_writer->writeTrimmed(": "); |
| 127 | 127 | |
| 128 | - return $this; |
|
| 128 | + return $this; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -139,62 +139,62 @@ discard block |
||
| 139 | 139 | public function writeValue($value, $type = null) |
| 140 | 140 | { |
| 141 | 141 | switch ($type) { |
| 142 | - case 'Edm.Boolean': |
|
| 143 | - case 'Edm.Int16': |
|
| 144 | - case 'Edm.Int32': |
|
| 145 | - case 'Edm.Byte': |
|
| 146 | - case 'Edm.SByte': |
|
| 147 | - $this->_writeCore($value, /* quotes */ false); |
|
| 148 | - break; |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - case 'Edm.Int64': |
|
| 152 | - case 'Edm.Guid': |
|
| 153 | - case 'Edm.Decimal': |
|
| 154 | - case 'Edm.Binary': |
|
| 155 | - $this->_writeCore($value, /* quotes */ true); |
|
| 156 | - break; |
|
| 157 | - |
|
| 158 | - case 'Edm.Single': |
|
| 159 | - case 'Edm.Double': |
|
| 160 | - if (is_infinite($value) || is_nan($value)) { |
|
| 161 | - $this->_writeCore("null", /* quotes */ true); |
|
| 162 | - } else { |
|
| 163 | - $this->_writeCore($value, /* quotes */ false); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - break; |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - case 'Edm.DateTime': |
|
| 170 | - $dateTime = new \DateTime($value, new \DateTimeZone('UTC')); |
|
| 171 | - $formattedDateTime = $dateTime->format('Y-m-d\TH:i:s'); |
|
| 172 | - $this->_writeCore($formattedDateTime, /* quotes */ true); |
|
| 173 | - break; |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - case 'Edm.String': |
|
| 177 | - if ($value == null) { |
|
| 178 | - $this->_writeCore("null", /* quotes */ false); |
|
| 179 | - } else { |
|
| 180 | - $jsonEncoded = json_encode($value); |
|
| 181 | - //json_encode always escapes a solidus (forward slash, %x2F), |
|
| 182 | - //this will be a problem when encoding urls |
|
| 183 | - //JSON_UNESCAPED_SLASHES not available in earlier versions of php 5.3 |
|
| 184 | - //So removing escaping forward slashes manually |
|
| 185 | - $jsonEncoded = str_replace('\\/', '/', $jsonEncoded); |
|
| 186 | - //since json_encode is already appending chords |
|
| 187 | - //there is no need to set it again |
|
| 188 | - $this->_writeCore($jsonEncoded, /* quotes */ false); |
|
| 189 | - } |
|
| 190 | - break; |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - default: |
|
| 194 | - $this->_writeCore($this->_quoteJScriptString($value), /* quotes */ true); |
|
| 142 | + case 'Edm.Boolean': |
|
| 143 | + case 'Edm.Int16': |
|
| 144 | + case 'Edm.Int32': |
|
| 145 | + case 'Edm.Byte': |
|
| 146 | + case 'Edm.SByte': |
|
| 147 | + $this->_writeCore($value, /* quotes */ false); |
|
| 148 | + break; |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + case 'Edm.Int64': |
|
| 152 | + case 'Edm.Guid': |
|
| 153 | + case 'Edm.Decimal': |
|
| 154 | + case 'Edm.Binary': |
|
| 155 | + $this->_writeCore($value, /* quotes */ true); |
|
| 156 | + break; |
|
| 157 | + |
|
| 158 | + case 'Edm.Single': |
|
| 159 | + case 'Edm.Double': |
|
| 160 | + if (is_infinite($value) || is_nan($value)) { |
|
| 161 | + $this->_writeCore("null", /* quotes */ true); |
|
| 162 | + } else { |
|
| 163 | + $this->_writeCore($value, /* quotes */ false); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + break; |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + case 'Edm.DateTime': |
|
| 170 | + $dateTime = new \DateTime($value, new \DateTimeZone('UTC')); |
|
| 171 | + $formattedDateTime = $dateTime->format('Y-m-d\TH:i:s'); |
|
| 172 | + $this->_writeCore($formattedDateTime, /* quotes */ true); |
|
| 173 | + break; |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + case 'Edm.String': |
|
| 177 | + if ($value == null) { |
|
| 178 | + $this->_writeCore("null", /* quotes */ false); |
|
| 179 | + } else { |
|
| 180 | + $jsonEncoded = json_encode($value); |
|
| 181 | + //json_encode always escapes a solidus (forward slash, %x2F), |
|
| 182 | + //this will be a problem when encoding urls |
|
| 183 | + //JSON_UNESCAPED_SLASHES not available in earlier versions of php 5.3 |
|
| 184 | + //So removing escaping forward slashes manually |
|
| 185 | + $jsonEncoded = str_replace('\\/', '/', $jsonEncoded); |
|
| 186 | + //since json_encode is already appending chords |
|
| 187 | + //there is no need to set it again |
|
| 188 | + $this->_writeCore($jsonEncoded, /* quotes */ false); |
|
| 189 | + } |
|
| 190 | + break; |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + default: |
|
| 194 | + $this->_writeCore($this->_quoteJScriptString($value), /* quotes */ true); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - return $this; |
|
| 197 | + return $this; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | $this->_writer |
| 281 | - ->increaseIndent() |
|
| 281 | + ->increaseIndent() |
|
| 282 | 282 | ->writeLine(); |
| 283 | 283 | } |
| 284 | 284 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | public function __construct($type) |
| 322 | 322 | { |
| 323 | 323 | $this->type = $type; |
| 324 | - $this->objectCount = 0; |
|
| 324 | + $this->objectCount = 0; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | } |
| 328 | 328 | \ No newline at end of file |
@@ -211,7 +211,7 @@ |
||
| 211 | 211 | // Escape ( " \ / \n \r \t \b \f) characters with a backslash. |
| 212 | 212 | $search = array('\\', "\n", "\t", "\r", "\b", "\f", '"'); |
| 213 | 213 | $replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'); |
| 214 | - $processedString = str_replace($search, $replace, $string); |
|
| 214 | + $processedString = str_replace($search, $replace, $string); |
|
| 215 | 215 | // Escape some ASCII characters(0x08, 0x0c) |
| 216 | 216 | $processedString = str_replace(array(chr(0x08), chr(0x0C)), array('\b', '\f'), $processedString); |
| 217 | 217 | return $processedString; |