From fd91d88e3fba2ad65649457a3bb09b2f61e46474 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 26 Feb 2018 17:17:45 -0600 Subject: [PATCH 1/8] Refactors to use a response factory instead of prototype Updates to use a response factory instead of a prototype. This alleviates the need for a stream factory, and allows re-use of the `ResponseInterface` service with Expressive v3. It also simplifies the constructors. --- composer.json | 4 +- composer.lock | 337 +++++++++++------- .../InvalidResponseBodyException.php | 29 -- src/HalResponseFactory.php | 54 +-- src/HalResponseFactoryFactory.php | 75 +--- test/HalResponseFactoryFactoryTest.php | 38 +- test/HalResponseFactoryTest.php | 108 ++---- 7 files changed, 272 insertions(+), 373 deletions(-) delete mode 100644 src/Exception/InvalidResponseBodyException.php diff --git a/composer.json b/composer.json index 99336a3..8d6884b 100644 --- a/composer.json +++ b/composer.json @@ -25,15 +25,15 @@ }, "require": { "php": "^7.1", + "http-interop/http-middleware": "^0.5.0", "psr/http-message": "^1.0.1", "psr/http-message-implementation": "^1.0", "psr/link": "^1.0", "willdurand/negotiation": "^2.3.1" }, "require-dev": { - "phpunit/phpunit": "^6.4.3", + "phpunit/phpunit": "^7.0.1", "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-diactoros": "^1.6", "zendframework/zend-expressive-helpers": "^4.2 || ^5.0.0-dev || ^5.0.0", "zendframework/zend-hydrator": "^2.3.1", "zendframework/zend-paginator": "^2.7" diff --git a/composer.lock b/composer.lock index 8acfce6..4e3e5c1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "1ae6038383d96a5ea655303e1f4a509e", + "content-hash": "9243d8b7bf3dee9dd2c6be555d8b8b30", "packages": [ { "name": "psr/http-message", @@ -364,6 +364,7 @@ "request", "response" ], + "abandoned": "http-interop/http-server-middleware", "time": "2017-09-18T15:27:03+00:00" }, { @@ -569,29 +570,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.1.1", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2d3d238c433cf69caeb4842e97a3223a116f94b2", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -610,7 +617,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-08-30T18:51:59+00:00" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -661,16 +668,16 @@ }, { "name": "phpspec/prophecy", - "version": "v1.7.2", + "version": "1.7.5", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6" + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", "shasum": "" }, "require": { @@ -682,7 +689,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { @@ -720,45 +727,44 @@ "spy", "stub" ], - "time": "2017-09-04T11:05:03+00:00" + "time": "2018-02-19T10:16:54+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "5.2.2", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "8ed1902a57849e117b5651fc1a5c48110946c06b" + "reference": "f8ca4b604baf23dab89d87773c28cc07405189ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8ed1902a57849e117b5651fc1a5c48110946c06b", - "reference": "8ed1902a57849e117b5651fc1a5c48110946c06b", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f8ca4b604baf23dab89d87773c28cc07405189ba", + "reference": "f8ca4b604baf23dab89d87773c28cc07405189ba", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.0", + "php": "^7.1", "phpunit/php-file-iterator": "^1.4.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^1.4.11 || ^2.0", + "phpunit/php-token-stream": "^3.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^3.0", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": "^2.5", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^7.0" }, "suggest": { - "ext-xdebug": "^2.5.5" + "ext-xdebug": "^2.6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.2.x-dev" + "dev-master": "6.0-dev" } }, "autoload": { @@ -773,7 +779,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -784,20 +790,20 @@ "testing", "xunit" ], - "time": "2017-08-03T12:40:43+00:00" + "time": "2018-02-02T07:01:41+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -831,7 +837,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -876,28 +882,28 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -912,7 +918,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -921,33 +927,33 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "time": "2018-02-01T13:07:23+00:00" }, { "name": "phpunit/php-token-stream", - "version": "2.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0" + "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9a02332089ac48e704c70f6cefed30c224e3c0b0", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/21ad88bbba7c3d93530d93994e0a33cd45f02ace", + "reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2.4" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -970,20 +976,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-08-20T05:47:52+00:00" + "time": "2018-02-01T13:16:43+00:00" }, { "name": "phpunit/phpunit", - "version": "6.4.3", + "version": "7.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "06b28548fd2b4a20c3cd6e247dc86331a7d4db13" + "reference": "e2f8aa21bc54b6ba218bdd4f9e0dac1e9bc3b4e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/06b28548fd2b4a20c3cd6e247dc86331a7d4db13", - "reference": "06b28548fd2b4a20c3cd6e247dc86331a7d4db13", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e2f8aa21bc54b6ba218bdd4f9e0dac1e9bc3b4e9", + "reference": "e2f8aa21bc54b6ba218bdd4f9e0dac1e9bc3b4e9", "shasum": "" }, "require": { @@ -995,15 +1001,15 @@ "myclabs/deep-copy": "^1.6.1", "phar-io/manifest": "^1.0.1", "phar-io/version": "^1.0", - "php": "^7.0", + "php": "^7.1", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^5.2.2", - "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-code-coverage": "^6.0", + "phpunit/php-file-iterator": "^1.4.3", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^1.0.9", - "phpunit/phpunit-mock-objects": "^4.0.3", - "sebastian/comparator": "^2.0.2", - "sebastian/diff": "^2.0", + "phpunit/php-timer": "^2.0", + "phpunit/phpunit-mock-objects": "^6.0", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^3.0", "sebastian/environment": "^3.1", "sebastian/exporter": "^3.1", "sebastian/global-state": "^2.0", @@ -1011,16 +1017,12 @@ "sebastian/resource-operations": "^1.0", "sebastian/version": "^2.0.1" }, - "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2", - "phpunit/dbunit": "<3.0" - }, "require-dev": { "ext-pdo": "*" }, "suggest": { "ext-xdebug": "*", - "phpunit/php-invoker": "^1.1" + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -1028,7 +1030,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.4.x-dev" + "dev-master": "7.0-dev" } }, "autoload": { @@ -1054,33 +1056,30 @@ "testing", "xunit" ], - "time": "2017-10-16T13:18:59+00:00" + "time": "2018-02-26T07:03:12+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "4.0.4", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "2f789b59ab89669015ad984afa350c4ec577ade0" + "reference": "e3249dedc2d99259ccae6affbc2684eac37c2e53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0", - "reference": "2f789b59ab89669015ad984afa350c4ec577ade0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/e3249dedc2d99259ccae6affbc2684eac37c2e53", + "reference": "e3249dedc2d99259ccae6affbc2684eac37c2e53", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.5", - "php": "^7.0", + "php": "^7.1", "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.0" - }, - "conflict": { - "phpunit/phpunit": "<6.0" + "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^7.0" }, "suggest": { "ext-soap": "*" @@ -1088,7 +1087,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "6.0.x-dev" } }, "autoload": { @@ -1103,7 +1102,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1113,7 +1112,7 @@ "mock", "xunit" ], - "time": "2017-08-03T14:08:16+00:00" + "time": "2018-02-15T05:27:38+00:00" }, { "name": "psr/container", @@ -1211,21 +1210,21 @@ }, { "name": "sebastian/comparator", - "version": "2.1.0", + "version": "2.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158" + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1174d9018191e93cb9d719edec01257fc05f8158", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", "shasum": "" }, "require": { "php": "^7.0", - "sebastian/diff": "^2.0", + "sebastian/diff": "^2.0 || ^3.0", "sebastian/exporter": "^3.1" }, "require-dev": { @@ -1271,32 +1270,33 @@ "compare", "equality" ], - "time": "2017-11-03T07:16:52+00:00" + "time": "2018-02-01T13:46:46+00:00" }, { "name": "sebastian/diff", - "version": "2.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" + "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/e09160918c66281713f1c324c1f4c4c3037ba1e8", + "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2" + "phpunit/phpunit": "^7.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1321,9 +1321,12 @@ "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" ], - "time": "2017-08-03T08:09:46+00:00" + "time": "2018-02-01T13:45:15+00:00" }, { "name": "sebastian/environment", @@ -1841,28 +1844,80 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "time": "2017-04-07T12:08:54+00:00" }, + { + "name": "webimpress/composer-extra-dependency", + "version": "0.2.2", + "source": { + "type": "git", + "url": "https://github.com/webimpress/composer-extra-dependency.git", + "reference": "31fa56391d30f03b1180c87610cbe22254780ad9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webimpress/composer-extra-dependency/zipball/31fa56391d30f03b1180c87610cbe22254780ad9", + "reference": "31fa56391d30f03b1180c87610cbe22254780ad9", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1", + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "composer/composer": "^1.5.2", + "mikey179/vfsstream": "^1.6.5", + "phpunit/phpunit": "^5.7.22 || ^6.4.1", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Webimpress\\ComposerExtraDependency\\Plugin" + }, + "autoload": { + "psr-4": { + "Webimpress\\ComposerExtraDependency\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "description": "Composer plugin to require extra dependencies", + "homepage": "https://github.com/webimpress/composer-extra-dependency", + "keywords": [ + "composer", + "dependency", + "webimpress" + ], + "time": "2017-10-17T17:15:14+00:00" + }, { "name": "webimpress/http-middleware-compatibility", - "version": "0.1.1", + "version": "0.1.4", "source": { "type": "git", "url": "https://github.com/webimpress/http-middleware-compatibility.git", - "reference": "793d21864a0417bbe01437c33f902cac49c1788c" + "reference": "8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webimpress/http-middleware-compatibility/zipball/793d21864a0417bbe01437c33f902cac49c1788c", - "reference": "793d21864a0417bbe01437c33f902cac49c1788c", + "url": "https://api.github.com/repos/webimpress/http-middleware-compatibility/zipball/8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717", + "reference": "8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717", "shasum": "" }, "require": { "http-interop/http-middleware": "^0.1.1 || ^0.2 || ^0.3 || ^0.4.1 || ^0.5", - "php": "^5.6 || ^7.0" + "php": "^5.6 || ^7.0", + "webimpress/composer-extra-dependency": "^0.2.2" }, "require-dev": { - "phpunit/phpunit": "^5.7.22 || ^6.3.1" + "phpunit/phpunit": "^5.7.23 || ^6.4.3" }, "type": "library", + "extra": { + "dependency": [ + "http-interop/http-middleware" + ] + }, "autoload": { "files": [ "autoload/http-middleware.php" @@ -1879,20 +1934,21 @@ "psr-15", "webimpress" ], - "time": "2017-10-05T15:55:30+00:00" + "abandoned": "psr/http-server-middleware", + "time": "2017-10-17T17:31:10+00:00" }, { "name": "webmozart/assert", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", "shasum": "" }, "require": { @@ -1929,7 +1985,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2018-01-29T19:49:41+00:00" }, { "name": "zendframework/zend-coding-standard", @@ -1962,16 +2018,16 @@ }, { "name": "zendframework/zend-expressive-helpers", - "version": "4.2.0", + "version": "dev-develop", "source": { "type": "git", "url": "https://github.com/zendframework/zend-expressive-helpers.git", - "reference": "137d863d4741210d05297b4bb1c30264f100ba8f" + "reference": "0f0967504dfab08ce689d376cf65a2a05896d210" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-expressive-helpers/zipball/137d863d4741210d05297b4bb1c30264f100ba8f", - "reference": "137d863d4741210d05297b4bb1c30264f100ba8f", + "url": "https://api.github.com/repos/zendframework/zend-expressive-helpers/zipball/0f0967504dfab08ce689d376cf65a2a05896d210", + "reference": "0f0967504dfab08ce689d376cf65a2a05896d210", "shasum": "" }, "require": { @@ -1984,7 +2040,7 @@ "require-dev": { "malukenho/docheader": "^0.1.5", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^5.7.22 || ^6.4.1", + "phpunit/phpunit": "^5.7.23 || ^6.5.3", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-diactoros": "^1.3.10" }, @@ -1996,8 +2052,9 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev", - "dev-develop": "4.3-dev" + "dev-master": "4.2.x-dev", + "dev-develop": "4.3.x-dev", + "dev-release-5.0.0": "5.0.x-dev" } }, "autoload": { @@ -2011,26 +2068,29 @@ ], "description": "Helper/Utility classes for Expressive", "keywords": [ + "ZendFramework", "expressive", "http", "middleware", "psr", - "psr-7" + "psr-7", + "zend-expressive", + "zf" ], - "time": "2017-10-09T19:03:01+00:00" + "time": "2017-12-14T15:18:39+00:00" }, { "name": "zendframework/zend-expressive-router", - "version": "2.2.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/zendframework/zend-expressive-router.git", - "reference": "f6eac53d39cdbf7b6db11b3e6bb3565896633de4" + "reference": "eb71000aa7970ad67f252076200bcc1593714f8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-expressive-router/zipball/f6eac53d39cdbf7b6db11b3e6bb3565896633de4", - "reference": "f6eac53d39cdbf7b6db11b3e6bb3565896633de4", + "url": "https://api.github.com/repos/zendframework/zend-expressive-router/zipball/eb71000aa7970ad67f252076200bcc1593714f8d", + "reference": "eb71000aa7970ad67f252076200bcc1593714f8d", "shasum": "" }, "require": { @@ -2041,7 +2101,7 @@ }, "require-dev": { "malukenho/docheader": "^0.1.5", - "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "phpunit/phpunit": "^5.7.23 || ^6.4.3", "zendframework/zend-coding-standard": "~1.0.0" }, "suggest": { @@ -2052,8 +2112,9 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" + "dev-master": "2.3.x-dev", + "dev-develop": "2.4.x-dev", + "dev-release-3.0.0": "3.0.x-dev" } }, "autoload": { @@ -2067,13 +2128,16 @@ ], "description": "Router subcomponent for Expressive", "keywords": [ + "ZendFramework", "expressive", "http", "middleware", "psr", - "psr-7" + "psr-7", + "zend-expressive", + "zf" ], - "time": "2017-10-09T18:44:11+00:00" + "time": "2018-02-01T19:49:45+00:00" }, { "name": "zendframework/zend-hydrator", @@ -2139,28 +2203,28 @@ }, { "name": "zendframework/zend-paginator", - "version": "2.7.0", + "version": "2.8.1", "source": { "type": "git", "url": "https://github.com/zendframework/zend-paginator.git", - "reference": "42211f3e1e8230953c641e91fec5aa9fe964eb95" + "reference": "fd58828c8280a90f133b9e0af2fe1a7885d47206" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-paginator/zipball/42211f3e1e8230953c641e91fec5aa9fe964eb95", - "reference": "42211f3e1e8230953c641e91fec5aa9fe964eb95", + "url": "https://api.github.com/repos/zendframework/zend-paginator/zipball/fd58828c8280a90f133b9e0af2fe1a7885d47206", + "reference": "fd58828c8280a90f133b9e0af2fe1a7885d47206", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", + "php": "^7.0 || ^5.6", "zendframework/zend-stdlib": "^2.7 || ^3.0" }, "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^6.2.1 || ^5.7.15", "zendframework/zend-cache": "^2.6.1", + "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-config": "^2.6.0", - "zendframework/zend-db": "^2.7", + "zendframework/zend-db": "^2.9.2", "zendframework/zend-filter": "^2.6.1", "zendframework/zend-json": "^2.6.1", "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", @@ -2177,8 +2241,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev", - "dev-develop": "2.8-dev" + "dev-master": "2.8-dev", + "dev-develop": "2.9-dev" }, "zf": { "component": "Zend\\Paginator", @@ -2194,12 +2258,13 @@ "license": [ "BSD-3-Clause" ], + "description": "zend-paginator is a flexible component for paginating collections of data and presenting that data to users.", "homepage": "https://github.com/zendframework/zend-paginator", "keywords": [ "paginator", "zf2" ], - "time": "2016-04-11T21:18:13+00:00" + "time": "2018-01-30T15:52:44+00:00" }, { "name": "zendframework/zend-stdlib", diff --git a/src/Exception/InvalidResponseBodyException.php b/src/Exception/InvalidResponseBodyException.php deleted file mode 100644 index 28d3fa1..0000000 --- a/src/Exception/InvalidResponseBodyException.php +++ /dev/null @@ -1,29 +0,0 @@ -responsePrototype = $responsePrototype ?: new Response(); - $this->streamFactory = $streamFactory ?: Closure::fromCallable([$this, 'generateStream']); + // Ensures type safety of the composed factory + $this->responseFactory = function () use ($responseFactory) : ResponseInterface { + return $responseFactory(); + }; $this->jsonRenderer = $jsonRenderer ?: new Renderer\JsonRenderer(); $this->xmlRenderer = $xmlRenderer ?: new Renderer\XmlRenderer(); } @@ -79,33 +72,8 @@ public function createResponse( break; } - $body = ($this->streamFactory)(); - $body->write($renderer->render($resource)); - return $this->responsePrototype - ->withBody($body) - ->withHeader('Content-Type', $mediaType); - } - - /** - * @throws Exception\InvalidResponseBodyException if the stream factory - * does not return a StreamInterface. - * @throws Exception\InvalidResponseBodyException if the stream generated - * by the stream factory is not writable. - */ - public function createStream() : StreamInterface - { - $stream = ($this->streamFactory)(); - if (! $body instanceof StreamInterface) { - throw Exception\InvalidResponseBodyException::forIncorrectStreamType(); - } - if (! $body->isWritable()) { - throw Exception\InvalidResponseBodyException::forNonWritableStream(); - } - return $stream; - } - - private function generateStream() : Stream - { - return new Stream('php://temp', 'wb+'); + $response = ($this->responseFactory)(); + $response->getBody()->write($renderer->render($resource)); + return $response->withHeader('Content-Type', $mediaType); } } diff --git a/src/HalResponseFactoryFactory.php b/src/HalResponseFactoryFactory.php index 1255114..cf05e08 100644 --- a/src/HalResponseFactoryFactory.php +++ b/src/HalResponseFactoryFactory.php @@ -1,32 +1,24 @@ getResponseInstance($container); - $streamFactory = $this->getStreamFactory($container); - $jsonRenderer = $container->has(Renderer\JsonRenderer::class) ? $container->get(Renderer\JsonRenderer::class) : new Renderer\JsonRenderer(); @@ -48,65 +37,9 @@ public function __invoke(ContainerInterface $container) : HalResponseFactory : new Renderer\XmlRenderer(); return new HalResponseFactory( - $response, - $streamFactory, + $container->get(ResponseInterface::class), $jsonRenderer, $xmlRenderer ); } - - /** - * @throws RuntimeException if neither a ResponseInterface service is available - * nor zend-diactoros installed. - */ - private function getResponseInstance(ContainerInterface $container) : ResponseInterface - { - if ($container->has(ResponseInterface::class)) { - return $container->get(ResponseInterface::class); - } - - if (class_exists(Response::class)) { - return new Response(); - } - - throw new RuntimeException(sprintf( - 'The %s implementation requires that you either define a service ' - . '"%s" or have zend-diactoros installed; either create %s service ' - . 'or install zendframework/zend-diactoros.', - self::class, - ResponseInterface::class, - ResponseInterface::class - )); - } - - /** - * @throws RuntimeException if neither a StreamInterface service is available - * nor zend-diactoros installed. - */ - private function getStreamFactory(ContainerInterface $container) : callable - { - if ($container->has(StreamInterface::class)) { - return $container->get(StreamInterface::class); - } - - if (class_exists(Stream::class)) { - return Closure::fromCallable([$this, 'generateStream']); - } - - throw new RuntimeException(sprintf( - 'The %s implementation requires that you either define a service ' - . '"%s" (which should return a callable capable of returning a %s) ' - . 'or have zend-diactoros installed; either create %s service ' - . 'or install zendframework/zend-diactoros.', - self::class, - StreamInterface::class, - StreamInterface::class, - StreamInterface::class - )); - } - - private function generateStream() : Stream - { - return new Stream('php://temp', 'wb+'); - } } diff --git a/test/HalResponseFactoryFactoryTest.php b/test/HalResponseFactoryFactoryTest.php index e10cc0d..c37b5c1 100644 --- a/test/HalResponseFactoryFactoryTest.php +++ b/test/HalResponseFactoryFactoryTest.php @@ -1,7 +1,7 @@ setAccessible(true); + $responseFactory = $r->getValue($factory); + Assert::assertSame($expected, $responseFactory()); + } + public function testReturnsHalResponseFactoryInstance() : void { $jsonRenderer = $this->prophesize(Renderer\JsonRenderer::class)->reveal(); $xmlRenderer = $this->prophesize(Renderer\XmlRenderer::class)->reveal(); $response = $this->prophesize(ResponseInterface::class)->reveal(); - $stream = new class() - { - public function __invoke() - { - } + $responseFactory = function () use ($response) { + return $response; }; $container = $this->prophesize(ContainerInterface::class); + $container->get(ResponseInterface::class)->willReturn($responseFactory); $container->has(Renderer\JsonRenderer::class)->willReturn(true); $container->get(Renderer\JsonRenderer::class)->willReturn($jsonRenderer); $container->has(Renderer\XmlRenderer::class)->willReturn(true); $container->get(Renderer\XmlRenderer::class)->willReturn($xmlRenderer); - $container->has(ResponseInterface::class)->willReturn(true); - $container->get(ResponseInterface::class)->willReturn($response); - $container->has(StreamInterface::class)->willReturn(true); - $container->get(StreamInterface::class)->willReturn($stream); $instance = (new HalResponseFactoryFactory())($container->reveal()); self::assertInstanceOf(HalResponseFactory::class, $instance); self::assertAttributeSame($jsonRenderer, 'jsonRenderer', $instance); self::assertAttributeSame($xmlRenderer, 'xmlRenderer', $instance); - self::assertAttributeSame($response, 'responsePrototype', $instance); - self::assertAttributeSame($stream, 'streamFactory', $instance); + self::assertResponseFactoryReturns($response, $instance); } public function testReturnsHalResponseFactoryInstanceWithoutConfiguredDependencies() : void { + $response = $this->prophesize(ResponseInterface::class)->reveal(); + $responseFactory = function () use ($response) { + return $response; + }; $container = $this->prophesize(ContainerInterface::class); + $container->get(ResponseInterface::class)->willReturn($responseFactory); $container->has(Renderer\JsonRenderer::class)->willReturn(false); $container->has(Renderer\XmlRenderer::class)->willReturn(false); - $container->has(ResponseInterface::class)->willReturn(false); - $container->has(StreamInterface::class)->willReturn(false); $instance = (new HalResponseFactoryFactory())($container->reveal()); self::assertInstanceOf(HalResponseFactory::class, $instance); self::assertAttributeInstanceOf(Renderer\JsonRenderer::class, 'jsonRenderer', $instance); self::assertAttributeInstanceOf(Renderer\XmlRenderer::class, 'xmlRenderer', $instance); - self::assertAttributeInstanceOf(ResponseInterface::class, 'responsePrototype', $instance); - self::assertAttributeInstanceOf(Closure::class, 'streamFactory', $instance); + self::assertResponseFactoryReturns($response, $instance); } } diff --git a/test/HalResponseFactoryTest.php b/test/HalResponseFactoryTest.php index cbac20f..c4f95d9 100644 --- a/test/HalResponseFactoryTest.php +++ b/test/HalResponseFactoryTest.php @@ -1,7 +1,7 @@ request = $this->prophesize(ServerRequestInterface::class); + $this->response = $this->prophesize(ResponseInterface::class); $this->jsonRenderer = $this->prophesize(Renderer\JsonRenderer::class); $this->xmlRenderer = $this->prophesize(Renderer\XmlRenderer::class); $this->factory = new HalResponseFactory( - null, - null, + function () { + return $this->response->reveal(); + }, $this->jsonRenderer->reveal(), $this->xmlRenderer->reveal() ); @@ -42,14 +44,17 @@ public function testReturnsJsonResponseIfNoAcceptHeaderPresent() $this->jsonRenderer->render($resource)->willReturn('{}'); $this->xmlRenderer->render($resource)->shouldNotBeCalled(); $this->request->getHeaderLine('Accept')->willReturn(''); + + $stream = $this->prophesize(StreamInterface::class); + $stream->write('{}')->shouldBeCalled(); + $this->response->getBody()->will([$stream, 'reveal']); + $this->response->withHeader('Content-Type', 'application/hal+json')->will([$this->response, 'reveal']); + $response = $this->factory->createResponse( $this->request->reveal(), $resource ); - $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertContains('application/hal+json', $response->getHeaderLine('Content-Type')); - $json = (string) $response->getBody(); - $this->assertEquals('{}', $json); + $this->assertSame($this->response->reveal(), $response); } public function jsonAcceptHeaders() @@ -70,14 +75,17 @@ public function testReturnsJsonResponseIfAcceptHeaderMatchesJson(string $header) $this->jsonRenderer->render($resource)->willReturn('{}'); $this->xmlRenderer->render($resource)->shouldNotBeCalled(); $this->request->getHeaderLine('Accept')->willReturn($header); + + $stream = $this->prophesize(StreamInterface::class); + $stream->write('{}')->shouldBeCalled(); + $this->response->getBody()->will([$stream, 'reveal']); + $this->response->withHeader('Content-Type', 'application/hal+json')->will([$this->response, 'reveal']); + $response = $this->factory->createResponse( $this->request->reveal(), $resource ); - $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertContains('application/hal+json', $response->getHeaderLine('Content-Type')); - $json = (string) $response->getBody(); - $this->assertEquals('{}', $json); + $this->assertSame($this->response->reveal(), $response); } public function xmlAcceptHeaders() @@ -99,14 +107,17 @@ public function testReturnsXmlResponseIfAcceptHeaderMatchesXml(string $header) $this->xmlRenderer->render($resource)->willReturn(''); $this->jsonRenderer->render($resource)->shouldNotBeCalled(); $this->request->getHeaderLine('Accept')->willReturn($header); + + $stream = $this->prophesize(StreamInterface::class); + $stream->write('')->shouldBeCalled(); + $this->response->getBody()->will([$stream, 'reveal']); + $this->response->withHeader('Content-Type', 'application/hal+xml')->will([$this->response, 'reveal']); + $response = $this->factory->createResponse( $this->request->reveal(), $resource ); - $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertContains('application/hal+xml', $response->getHeaderLine('Content-Type')); - $xml = (string) $response->getBody(); - $this->assertEquals('', $xml); + $this->assertSame($this->response->reveal(), $response); } public function customMediaTypes() @@ -142,70 +153,17 @@ public function testUsesProvidedMediaTypeInReturnedResponseWithMatchedFormatAppe break; } $this->request->getHeaderLine('Accept')->willReturn($header); - $response = $this->factory->createResponse( - $this->request->reveal(), - $resource, - $mediaType - ); - $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertContains($expectedMediaType, $response->getHeaderLine('Content-Type')); - $payload = (string) $response->getBody(); - $this->assertEquals($responseBody, $payload); - } - - public function testAllowsProvidingResponsePrototypeToConstructor() - { - $resource = $this->createExampleResource(); - - $prototype = $this->prophesize(ResponseInterface::class); - $prototype->withBody(Argument::type(StreamInterface::class))->will([$prototype, 'reveal']); - $prototype->withHeader('Content-Type', 'application/hal+json')->will([$prototype, 'reveal']); - - $this->jsonRenderer->render($resource)->willReturn('{}'); - $this->xmlRenderer->render($resource)->shouldNotBeCalled(); - $this->request->getHeaderLine('Accept')->willReturn('application/json'); - - $factory = new HalResponseFactory( - $prototype->reveal(), - null, - $this->jsonRenderer->reveal(), - $this->xmlRenderer->reveal() - ); - $response = $factory->createResponse( - $this->request->reveal(), - $resource - ); - - $this->assertSame($prototype->reveal(), $response); - } - - public function testAllowsProvidingStreamFactoryToConstructor() - { - $resource = $this->createExampleResource(); - - $this->jsonRenderer->render($resource)->willReturn('{}'); - $this->xmlRenderer->render($resource)->shouldNotBeCalled(); - $this->request->getHeaderLine('Accept')->willReturn('application/json'); $stream = $this->prophesize(StreamInterface::class); - $stream->write('{}')->shouldBeCalled(); - - $streamFactory = function () use ($stream) { - return $stream->reveal(); - }; - - $factory = new HalResponseFactory( - null, - $streamFactory, - $this->jsonRenderer->reveal(), - $this->xmlRenderer->reveal() - ); + $stream->write($responseBody)->shouldBeCalled(); + $this->response->getBody()->will([$stream, 'reveal']); + $this->response->withHeader('Content-Type', $expectedMediaType)->will([$this->response, 'reveal']); - $response = $factory->createResponse( + $response = $this->factory->createResponse( $this->request->reveal(), - $resource + $resource, + $mediaType ); - $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertContains('application/hal+json', $response->getHeaderLine('Content-Type')); + $this->assertSame($this->response->reveal(), $response); } } From f5576e3b2e4b916538f339cfea115c43c4b79180 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 26 Feb 2018 17:41:01 -0600 Subject: [PATCH 2/8] Updates dependencies Removes unused dependencies (http-interop/http-middleware, zend-diactoros), and updates the zend-expressive-helpers dependency to require 5.0.0alpha3 or above (to ensure compatibility). To do so, it requires a minimum stability of alpha. --- composer.json | 7 +- composer.lock | 360 +++++++++++++++++++------------------------------- 2 files changed, 141 insertions(+), 226 deletions(-) diff --git a/composer.json b/composer.json index 8d6884b..71705c8 100644 --- a/composer.json +++ b/composer.json @@ -23,18 +23,17 @@ "slack": "https://zendframework-slack.herokuapp.com", "forum": "https://discourse.zendframework.com/c/questions/expressive" }, + "minimum-stability": "alpha", "require": { "php": "^7.1", - "http-interop/http-middleware": "^0.5.0", "psr/http-message": "^1.0.1", - "psr/http-message-implementation": "^1.0", "psr/link": "^1.0", "willdurand/negotiation": "^2.3.1" }, "require-dev": { "phpunit/phpunit": "^7.0.1", "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-expressive-helpers": "^4.2 || ^5.0.0-dev || ^5.0.0", + "zendframework/zend-expressive-helpers": "^5.0.0alpha3", "zendframework/zend-hydrator": "^2.3.1", "zendframework/zend-paginator": "^2.7" }, @@ -43,7 +42,7 @@ }, "suggest": { "psr/container-implementation": "^1.0 in order to use the provided PSR-11 factories", - "zendframework/zend-expressive-helpers": "^4.2 in order to use UrlHelper/ServerUrlHelper-based ExpressiveUrlGenerator with the LinkGenerator", + "zendframework/zend-expressive-helpers": "^5.0 in order to use UrlHelper/ServerUrlHelper-based ExpressiveUrlGenerator with the LinkGenerator", "zendframework/zend-hydrator": "^2.3.1 in order to use the ResourceGenerator to create Resource instances from objects", "zendframework/zend-paginator": "^2.7 in order to provide paginated collections" }, diff --git a/composer.lock b/composer.lock index 4e3e5c1..3267e5e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "9243d8b7bf3dee9dd2c6be555d8b8b30", + "content-hash": "31b30ceef02eaca5633fc50e5bf0ec81", "packages": [ { "name": "psr/http-message", @@ -156,58 +156,6 @@ "negotiation" ], "time": "2017-05-14T17:21:12+00:00" - }, - { - "name": "zendframework/zend-diactoros", - "version": "1.6.0", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-diactoros.git", - "reference": "2faa791b66bac33ca40031d8bce03b7dc8143490" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/2faa791b66bac33ca40031d8bce03b7dc8143490", - "reference": "2faa791b66bac33ca40031d8bce03b7dc8143490", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0", - "psr/http-message": "^1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-dom": "*", - "ext-libxml": "*", - "phpunit/phpunit": "^5.7.16 || ^6.0.8", - "zendframework/zend-coding-standard": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6-dev", - "dev-develop": "1.7-dev" - } - }, - "autoload": { - "psr-4": { - "Zend\\Diactoros\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "PSR HTTP Message implementations", - "homepage": "https://github.com/zendframework/zend-diactoros", - "keywords": [ - "http", - "psr", - "psr-7" - ], - "time": "2017-09-13T14:47:08+00:00" } ], "packages-dev": [ @@ -315,58 +263,6 @@ ], "time": "2017-02-09T16:10:21+00:00" }, - { - "name": "http-interop/http-middleware", - "version": "0.5.0", - "source": { - "type": "git", - "url": "https://github.com/http-interop/http-middleware.git", - "reference": "b49e1f9f6c584e704317b563302e566b8ce11858" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/http-interop/http-middleware/zipball/b49e1f9f6c584e704317b563302e566b8ce11858", - "reference": "b49e1f9f6c584e704317b563302e566b8ce11858", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Interop\\Http\\Server\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP server-side middleware", - "keywords": [ - "http", - "middleware", - "psr", - "psr-15", - "psr-7", - "request", - "response" - ], - "abandoned": "http-interop/http-server-middleware", - "time": "2017-09-18T15:27:03+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.7.0", @@ -1163,6 +1059,112 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "psr/http-server-handler", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-handler.git", + "reference": "439d92054dc06097f2406ec074a2627839955a02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-handler/zipball/439d92054dc06097f2406ec074a2627839955a02", + "reference": "439d92054dc06097f2406ec074a2627839955a02", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side request handler", + "keywords": [ + "handler", + "http", + "http-interop", + "psr", + "psr-15", + "psr-7", + "request", + "response", + "server" + ], + "time": "2018-01-22T17:04:15+00:00" + }, + { + "name": "psr/http-server-middleware", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-middleware.git", + "reference": "ea17eb1fb2c8df6db919cc578451a8013c6a0ae5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-middleware/zipball/ea17eb1fb2c8df6db919cc578451a8013c6a0ae5", + "reference": "ea17eb1fb2c8df6db919cc578451a8013c6a0ae5", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0", + "psr/http-server-handler": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side middleware", + "keywords": [ + "http", + "http-interop", + "middleware", + "psr", + "psr-15", + "psr-7", + "request", + "response" + ], + "time": "2018-01-22T17:08:31+00:00" + }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", @@ -1844,99 +1846,6 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "time": "2017-04-07T12:08:54+00:00" }, - { - "name": "webimpress/composer-extra-dependency", - "version": "0.2.2", - "source": { - "type": "git", - "url": "https://github.com/webimpress/composer-extra-dependency.git", - "reference": "31fa56391d30f03b1180c87610cbe22254780ad9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webimpress/composer-extra-dependency/zipball/31fa56391d30f03b1180c87610cbe22254780ad9", - "reference": "31fa56391d30f03b1180c87610cbe22254780ad9", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1", - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "composer/composer": "^1.5.2", - "mikey179/vfsstream": "^1.6.5", - "phpunit/phpunit": "^5.7.22 || ^6.4.1", - "zendframework/zend-coding-standard": "~1.0.0" - }, - "type": "composer-plugin", - "extra": { - "class": "Webimpress\\ComposerExtraDependency\\Plugin" - }, - "autoload": { - "psr-4": { - "Webimpress\\ComposerExtraDependency\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "Composer plugin to require extra dependencies", - "homepage": "https://github.com/webimpress/composer-extra-dependency", - "keywords": [ - "composer", - "dependency", - "webimpress" - ], - "time": "2017-10-17T17:15:14+00:00" - }, - { - "name": "webimpress/http-middleware-compatibility", - "version": "0.1.4", - "source": { - "type": "git", - "url": "https://github.com/webimpress/http-middleware-compatibility.git", - "reference": "8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webimpress/http-middleware-compatibility/zipball/8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717", - "reference": "8ed1c2c7523dce0035b98bc4f3a73ca9cd1d3717", - "shasum": "" - }, - "require": { - "http-interop/http-middleware": "^0.1.1 || ^0.2 || ^0.3 || ^0.4.1 || ^0.5", - "php": "^5.6 || ^7.0", - "webimpress/composer-extra-dependency": "^0.2.2" - }, - "require-dev": { - "phpunit/phpunit": "^5.7.23 || ^6.4.3" - }, - "type": "library", - "extra": { - "dependency": [ - "http-interop/http-middleware" - ] - }, - "autoload": { - "files": [ - "autoload/http-middleware.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "description": "Compatibility library for Draft PSR-15 HTTP Middleware", - "homepage": "https://github.com/webimpress/http-middleware-compatibility", - "keywords": [ - "middleware", - "psr-15", - "webimpress" - ], - "abandoned": "psr/http-server-middleware", - "time": "2017-10-17T17:31:10+00:00" - }, { "name": "webmozart/assert", "version": "1.3.0", @@ -2018,29 +1927,29 @@ }, { "name": "zendframework/zend-expressive-helpers", - "version": "dev-develop", + "version": "5.0.0alpha3", "source": { "type": "git", "url": "https://github.com/zendframework/zend-expressive-helpers.git", - "reference": "0f0967504dfab08ce689d376cf65a2a05896d210" + "reference": "424d98086041c833c22cc5787c246c56dadff212" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-expressive-helpers/zipball/0f0967504dfab08ce689d376cf65a2a05896d210", - "reference": "0f0967504dfab08ce689d376cf65a2a05896d210", + "url": "https://api.github.com/repos/zendframework/zend-expressive-helpers/zipball/424d98086041c833c22cc5787c246c56dadff212", + "reference": "424d98086041c833c22cc5787c246c56dadff212", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "psr/container": "^1.0", "psr/http-message": "^1.0.1", - "webimpress/http-middleware-compatibility": "^0.1.1", - "zendframework/zend-expressive-router": "^2.2" + "psr/http-server-middleware": "^1.0", + "zendframework/zend-expressive-router": "^3.0.0alpha1 || ^3.0" }, "require-dev": { - "malukenho/docheader": "^0.1.5", + "malukenho/docheader": "^0.1.6", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^5.7.23 || ^6.5.3", + "phpunit/phpunit": "^6.5.5", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-diactoros": "^1.3.10" }, @@ -2055,6 +1964,9 @@ "dev-master": "4.2.x-dev", "dev-develop": "4.3.x-dev", "dev-release-5.0.0": "5.0.x-dev" + }, + "zf": { + "config-provider": "Zend\\Expressive\\Helper\\ConfigProvider" } }, "autoload": { @@ -2077,37 +1989,38 @@ "zend-expressive", "zf" ], - "time": "2017-12-14T15:18:39+00:00" + "time": "2018-02-06T21:16:07+00:00" }, { "name": "zendframework/zend-expressive-router", - "version": "2.3.0", + "version": "3.0.0alpha3", "source": { "type": "git", "url": "https://github.com/zendframework/zend-expressive-router.git", - "reference": "eb71000aa7970ad67f252076200bcc1593714f8d" + "reference": "737f79bffa8900388367d02e66dc0d0bcdba1eed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-expressive-router/zipball/eb71000aa7970ad67f252076200bcc1593714f8d", - "reference": "eb71000aa7970ad67f252076200bcc1593714f8d", + "url": "https://api.github.com/repos/zendframework/zend-expressive-router/zipball/737f79bffa8900388367d02e66dc0d0bcdba1eed", + "reference": "737f79bffa8900388367d02e66dc0d0bcdba1eed", "shasum": "" }, "require": { "fig/http-message-util": "^1.1.2", - "php": "^5.6 || ^7.0", + "php": "^7.1", + "psr/container": "^1.0", "psr/http-message": "^1.0.1", - "webimpress/http-middleware-compatibility": "^0.1.1" + "psr/http-server-middleware": "^1.0" }, "require-dev": { - "malukenho/docheader": "^0.1.5", - "phpunit/phpunit": "^5.7.23 || ^6.4.3", + "malukenho/docheader": "^0.1.6", + "phpunit/phpunit": "^6.5.5", "zendframework/zend-coding-standard": "~1.0.0" }, "suggest": { - "zendframework/zend-expressive-aurarouter": "^1.0 to use the Aura.Router routing adapter", - "zendframework/zend-expressive-fastroute": "^1.2 to use the FastRoute routing adapter", - "zendframework/zend-expressive-zendrouter": "^1.2 to use the zend-router routing adapter" + "zendframework/zend-expressive-aurarouter": "^3.0 to use the Aura.Router routing adapter", + "zendframework/zend-expressive-fastroute": "^3.0 to use the FastRoute routing adapter", + "zendframework/zend-expressive-zendrouter": "^3.0 to use the zend-router routing adapter" }, "type": "library", "extra": { @@ -2115,6 +2028,9 @@ "dev-master": "2.3.x-dev", "dev-develop": "2.4.x-dev", "dev-release-3.0.0": "3.0.x-dev" + }, + "zf": { + "config-provider": "Zend\\Expressive\\Router\\ConfigProvider" } }, "autoload": { @@ -2137,7 +2053,7 @@ "zend-expressive", "zf" ], - "time": "2018-02-01T19:49:45+00:00" + "time": "2018-02-21T18:39:37+00:00" }, { "name": "zendframework/zend-hydrator", @@ -2313,9 +2229,9 @@ } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "alpha", "stability-flags": { - "zendframework/zend-expressive-helpers": 20 + "zendframework/zend-expressive-helpers": 15 }, "prefer-stable": false, "prefer-lowest": false, From a0a0890bfdd56fd1cb91204cc01ba171ea357bf5 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 27 Feb 2018 08:28:46 -0600 Subject: [PATCH 3/8] Updates documentation to reflect changes to HalResponseFactory Also discovered a number of other general changes that were necessary: - Docs were still refering to http-interop; updated to PSR-15. - Docs were detailing middleware, where request handlers were more appropriate. - Docs were using http URIs for PHP-FIG links; updated to https. - Added more links to FIG specifications. --- .../generating-custom-links-in-middleware.md | 2 +- .../cookbook/generating-custom-resources.md | 2 + docs/book/factories.md | 21 +++----- docs/book/intro.md | 53 ++++++++++--------- docs/book/links-and-resources.md | 2 +- docs/book/representations.md | 48 ++++++----------- docs/book/resource-generator.md | 2 +- mkdocs.yml | 2 +- 8 files changed, 57 insertions(+), 75 deletions(-) diff --git a/docs/book/cookbook/generating-custom-links-in-middleware.md b/docs/book/cookbook/generating-custom-links-in-middleware.md index 0ae2eda..d50aea5 100644 --- a/docs/book/cookbook/generating-custom-links-in-middleware.md +++ b/docs/book/cookbook/generating-custom-links-in-middleware.md @@ -1,4 +1,4 @@ -# Generating custom links in middleware +# Generating custom links in middleware and request handlers In most cases, you can rely on the `ResourceGenerator` to generate self relational links, and, in the case of paginated collections, pagination links. diff --git a/docs/book/cookbook/generating-custom-resources.md b/docs/book/cookbook/generating-custom-resources.md index 7717780..4a01065 100644 --- a/docs/book/cookbook/generating-custom-resources.md +++ b/docs/book/cookbook/generating-custom-resources.md @@ -39,6 +39,7 @@ $resourceGenerator->addStrategy(CustomMetadata::class, $strategyInstance); ``` You can also add your strategies via the configuration: + ```php return [ 'zend-expressive-hal' => [ @@ -62,6 +63,7 @@ decide to write your own strategies. In order for the `MetadataMap` to be able to use your `CustomMetadata` you need to register a factory (implementing `Zend\Expressive\Hal\Metadata\MetadataFactoryInterface`) for it. You can register them via the configuration: + ```php return [ 'zend-expressive-hal' => [ diff --git a/docs/book/factories.md b/docs/book/factories.md index 113b38b..34e336a 100644 --- a/docs/book/factories.md +++ b/docs/book/factories.md @@ -1,7 +1,7 @@ # Provided factories This component provides a number of factories for use with -[PSR-11](http://www.php-fig.org/psr/psr-11/), in order to generate fully +[PSR-11](https://www.php-fig.org/psr/psr-11/), in order to generate fully configured instances for your use. ## Zend\Expressive\Hal\HalResponseFactoryFactory @@ -9,24 +9,17 @@ configured instances for your use. - Registered as service: `Zend\Expressive\Hal\HalResponseFactory` - Generates instance of: `Zend\Expressive\Hal\HalResponseFactory` - Depends on: - - `Psr\Http\Message\ResponseInterface` service. If not present, it will - check if zend-diactoros is installed, and use a new `Response` instance - from that library; if not, it raises an exception. - - `Psr\Http\Message\StreamInterface` service. This service must return a - a callable capable of returning a `StreamInterface` instance (in other - words, the service returns a _factory_, and not the stream itself). If th - service is not present, the factory will check if zend-diactoros is - installed, and return a callable that returns a new `Stream` instance from - that library; if not, it raises an exception. + - `Psr\Http\Message\ResponseInterface` service. The service must resolve to + a PHP callable capable of generating a [PSR-7](https://www.php-fig.org/psr/psr-7/) + `ResponseInterface` instance; it must not resolve to a `ResponseInterface` + instance directly. This service is **required**, and must be supplied by + the application. If you are using with zend-expressive v3 and above, the + service will already be registered. - `Zend\Expressive\Hal\Renderer\JsonRenderer` service. If the service is not present, it instantiates an instance itself. - `Zend\Expressive\Hal\Renderer\XmlRenderer` service. If the service is not present, it instantiates an instance itself. -If you want to use a different PSR-7 implementation for the response and stream, -provide services for `Psr\Http\Message\ResponseInterface` and -`Psr\Http\Message\StreamInterface`, as described above. - ## Zend\Expressive\Hal\LinkGeneratorFactory - Registered as service: `Zend\Expressive\Hal\LinkGenerator` diff --git a/docs/book/intro.md b/docs/book/intro.md index 2a24f13..eccf2a2 100644 --- a/docs/book/intro.md +++ b/docs/book/intro.md @@ -14,7 +14,7 @@ These two tools allow you to model payloads of varying complexity. To allow providing _representations_ of these, we provide `Zend\Expressive\Hal\HalResponseFactory`. This factory generates a -[PSR-7](http://www.php-fig.org/psr/psr-7/) response for the provided resource, +[PSR-7](https://www.php-fig.org/psr/psr-7/) response for the provided resource, including its links and any embedded/child resources it composes. Creating link URIs by hand is error-prone, as URI schemas may change; most @@ -150,9 +150,9 @@ MetadataMap::class => [ ### Manually creating and rendering a resource -The following middleware creates a `HalResource` with its associated links, and -then manually renders it using `Zend\Expressive\Hal\Renderer\JsonRenderer`. (An -`XmlRenderer` is also provided, but not demonstrated here.) +The following request handler creates a `HalResource` with its associated links, +and then manually renders it using `Zend\Expressive\Hal\Renderer\JsonRenderer`. +(An `XmlRenderer` is also provided, but not demonstrated here.) We'll assume that `Api\Books\Repository` handles retrieving data from persistent storage. @@ -161,16 +161,16 @@ storage. namespace Api\Books\Action; use Api\Books\Repository; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; use Zend\Diactoros\Response\TextResponse; use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\Link; use Zend\Expressive\Hal\Renderer\JsonRenderer; -class BookAction implements MiddlewareInterface +class BookAction implements RequestHandlerInterface { /** @var JsonRenderer */ private $renderer; @@ -186,7 +186,7 @@ class BookAction implements MiddlewareInterface $this->renderer = $renderer; } - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function handle(ServerRequestInterface $request) : ResponseInterface { $id = $request->getAttribute('id', false); if (! $id) { @@ -223,28 +223,29 @@ instance. As the complexity of your objects increase, and the number of objects you want to represent via HAL increases, you may not want to manually generate them. -### Middleware using the ResourceGenerator and ResponseFactory +### Request handler using the ResourceGenerator and ResponseFactory -In this next example, our middleware will compose a `Zend\Expressive\Hal\ResourceGenerator` -instance for generating a `Zend\Expressive\Hal\HalResource` from our objects, -and a `Zend\Expressive\Hal\HalResponseFactory` for creating a response based on -the returned resource. +In this next example, our request handler will compose a +`Zend\Expressive\Hal\ResourceGenerator` instance for generating a +`Zend\Expressive\Hal\HalResource` from our objects, and a +`Zend\Expressive\Hal\HalResponseFactory` for creating a response based on the +returned resource. -First, we'll look at middleware that displays a single book. We'll assume that +First, we'll look at a handler that displays a single book. We'll assume that `Api\Books\Repository` handles retrieving data from persistent storage. ```php namespace Api\Books\Action; use Api\Books\Repository; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; -use Psr\Http\ServerRequestInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; use Zend\Expressive\Hal\HalResponseFactory; use Zend\Expressive\Hal\ResourceGenerator; -class BookAction +class BookAction implements RequestHandlerInterface { /** @var Repository */ private $repository; @@ -265,7 +266,7 @@ class BookAction $this->responseFactory = $responseFactory; } - public function __invoke(ServerRequestInterface $request, DelegateInterface $delegate) + public function handle(ServerRequestInterface $request) : ResponseInterface { $id = $request->getAttribute('id', false); if (! $id) { @@ -301,9 +302,9 @@ The generated payload might look like the following: } ``` -### Middleware returning a collection +### Request handler returning a collection -Next, we'll create middleware that returns a _collection_ of books. The +Next, we'll create a request handler that returns a _collection_ of books. The collection will be _paginated_ (assume our repository class creates a `BookCollection` backed by an appropriate adapter), and use a query string parameter to determine which page of results to return. @@ -312,14 +313,14 @@ parameter to determine which page of results to return. namespace Api\Books\Action; use Api\Books\Repository; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; -use Psr\Http\ServerRequestInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; use Zend\Expressive\Hal\HalResponseFactory; use Zend\Expressive\Hal\ResourceGenerator; -class BooksAction +class BooksAction implements RequestHandlerInterface { /** @var Repository */ private $repository; @@ -340,7 +341,7 @@ class BooksAction $this->responseFactory = $responseFactory; } - public function __invoke(ServerRequestInterface $request, DelegateInterface $delegate) + public function handle(ServerRequestInterface $request) : ResponseInterface { $page = $request->getQueryParams()['page'] ?? 1; diff --git a/docs/book/links-and-resources.md b/docs/book/links-and-resources.md index a305ad0..45162b9 100644 --- a/docs/book/links-and-resources.md +++ b/docs/book/links-and-resources.md @@ -13,7 +13,7 @@ The basic building blocks of this component are links and resources: > ### PSR-13 > -> zendframework/zend-expressive-hal implements [PSR-13](http://www.php-fig.org/psr/psr-13/), +> zendframework/zend-expressive-hal implements [PSR-13](https://www.php-fig.org/psr/psr-13/), > which provides interfaces for relational links and collections of relational > links. `Zend\Expressive\Hal\Link` implements `Psr\Link\EvolvableLinkInterface`, and > `Zend\Expressive\Hal\HalResource` implements `Psr\Link\EvolvableLinkProviderInterface`. diff --git a/docs/book/representations.md b/docs/book/representations.md index 6a088bb..88fc7e8 100644 --- a/docs/book/representations.md +++ b/docs/book/representations.md @@ -4,9 +4,9 @@ This component provides two renderers, one each for creating JSON and XML payloads. Additionally, as noted in the [introduction](intro.md) examples, this component -provides `Zend\Expressive\Hal\HalResponseFactory` for generating a PSR-7 -response containing the HAL representation. This chapter dives into that with -more detail. +provides `Zend\Expressive\Hal\HalResponseFactory` for generating a +[PSR-7](https://www.php-fig.org/psr/psr-7/) response containing the HAL +representation. This chapter dives into that with more detail. ## Renderers @@ -33,13 +33,13 @@ with `json_encode()`. By default, if none are provided, it uses the value of `JsonRenderer::DEFAULT_JSON_FLAGS`, which evaluates to: ```php -JSON_PRETTY_PRINT -| JSON_UNESCAPED_SLASHES +JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION ``` -This provides human-readable JSON output. +When your application is in "debug" mode, it also adds the `JSON_PRETTY_PRINT` +flag to the default list, in order to provide human-readable JSON output. ### XmlRenderer @@ -50,13 +50,8 @@ constructor arguments at this time. `HalResponseFactory` generates a PSR-7 response containing a representation of the provided `HalResource` instance. In order to keep the component agnostic of -PSR-7 implementation, the factory composes: - -- A PSR-7 response prototype. A zend-diactoros `Response` is used if none is - provided. -- A callable capable of generating an empty, writable, PSR-7 stream instance. - If none is provided, a callable returning a zend-diactoros `Stream` is - provided. +PSR-7 implementation, `HalResponseFactory` itself composes a callable factory +capable of producing an empty PSR-7 response. As an example: @@ -66,30 +61,21 @@ use Slim\Http\Stream; use Zend\Expressive\Hal\HalResponseFactory; $factory = new HalResponseFactory( - new Response(), function () { - return new Stream(fopen('php://temp', 'wb+')); + return new Response(); } ); ``` -> ### Streams -> -> A factory callable is necessary for generating streams as they are usually -> backed by PHP resources, which are not immutable. Sharing instances could -> thus potentially lead to appending or overwriting contents! - -By default, if you pass no arguments to the `HalResponseFactory` constructor, it -assumes the following: +Additionally, the `HalResponseFactory` constructor can accept the following +arguments, with the described defaults if none is provided: -- Usage of `Zend\Diactoros\Response`. -- A callable that returns a new `Zend\Diactoros\Stream` using `php://temp` as - its backing resource. - A `JsonRenderer` instance is created if none is provided. - An `XmlRenderer` instance is created if none is provided. -We provide a PSR-11 compatible factory for generating the `HalResponseFactory` -which uses zend-diactoros by default. +We provide a [PSR-11](https://www.php-fig.org/psr/psr-11) compatible factory for +generating the `HalResponseFactory`, described in [the factories +chapter](factories.md#zendexpressivehalhalresponsefactoryfactory). ## Using the factory @@ -153,9 +139,9 @@ if that's all the car currently has associated with it. To accommodate this, we provide two features. -For links, you may pass a special attribute, `Hal\Link::AS_COLLECTION`, with a -boolean value of `true`; when encountered, this will then be rendered as an -array of links, even if only one link for that relation is present. +For links, you may pass a special attribute, `Zend\Expressive\Hal\Link::AS_COLLECTION`, +with a boolean value of `true`; when encountered, this will then be rendered as +an array of links, even if only one link for that relation is present. ```php $link = new Link( diff --git a/docs/book/resource-generator.md b/docs/book/resource-generator.md index 0514d0d..ea6410f 100644 --- a/docs/book/resource-generator.md +++ b/docs/book/resource-generator.md @@ -81,7 +81,7 @@ $metadataMap->add($booksMetadata); To automate generation of the `MetadataMap`, we provide `Zend\Expressive\Hal\Metadata\MetadataMapFactory`. This factory may be used with any -[PSR-11](http://www.php-fig.org/psr/psr-11/) container. It utilizes the `config` +[PSR-11](https://www.php-fig.org/psr/psr-11/) container. It utilizes the `config` service, and pulls its configuration from a key named after the `Zend\Expressive\Hal\Metadata\MetadataMap` class. diff --git a/mkdocs.yml b/mkdocs.yml index 5ccef67..3079d87 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -11,7 +11,7 @@ pages: - "Representations": representations.md - "Factories": factories.md - Cookbook: - - "Generating Custom Links In Middleware": cookbook/generating-custom-links-in-middleware.md + - "Generating Custom Links In Middleware and Request Handlers": cookbook/generating-custom-links-in-middleware.md site_name: Hypertext Application Language site_description: 'Hypertext Application Language for PSR-7 Applications' repo_url: 'https://github.com/zendframework/zend-expressive-hal' From 026858f791e45546508e58da1774d8ae66b4f450 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 27 Feb 2018 08:32:56 -0600 Subject: [PATCH 4/8] Adds CHANGELOG entries for #31 --- CHANGELOG.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb5bb9..08b4fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,51 @@ All notable changes to this project will be documented in this file, in reverse Versions prior to 0.4.0 were released as the package "weierophinney/hal". +## 1.0.0alpha1 - 2018-02-27 + +### Added + +- Nothing. + +### Changed + +- [#31](https://github.com/zendframework/zend-expressive-hal/pull/31) changes + the constructor signature of `Zend\Expressive\Hal\HalResponseFactory` to read: + + ```php + public function __construct( + callable $responseFactory, + Renderer\JsonRenderer $jsonRenderer = null, + Renderer\XmlRenderer $xmlRenderer = null + ) + ``` + + Previously, the `$responseFactory` argument was a + `Psr\Http\Message\ResponseInterface $responsePrototype`; it is now a PHP + callable capable of producing a new, empty instance of that type. + + Additionally, the signature previously included a callable `$streamFactory`; + this has been removed. + +- [#31](https://github.com/zendframework/zend-expressive-hal/pull/31) updates + the `HalResponseFactoryFactory` to follow the changes made to the + `HalResponseFactory` constructor. It now **requires** that a + `Psr\Http\Message\ResponseInterface` service be registered, and that the + service resolve to a `callable` capable of producing a `ResponseInterface` + instance. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 0.6.2 - 2018-01-03 ### Added From 45203c5ec0d1d4acc75ffce4bb2c3fdde269b5c3 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 12 Mar 2018 17:34:01 -0500 Subject: [PATCH 5/8] Fixes failing test --- test/HalResponseFactoryFactoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/HalResponseFactoryFactoryTest.php b/test/HalResponseFactoryFactoryTest.php index b29ceaf..a68ea20 100644 --- a/test/HalResponseFactoryFactoryTest.php +++ b/test/HalResponseFactoryFactoryTest.php @@ -100,6 +100,5 @@ public function __invoke() self::assertInstanceOf(HalResponseFactory::class, $instance); self::assertAttributeSame($jsonRenderer, 'jsonRenderer', $instance); self::assertAttributeSame($xmlRenderer, 'xmlRenderer', $instance); - self::assertAttributeSame($stream, 'streamFactory', $instance); } } From 0106cc1f5e35b562087d126d0410432b6bb78108 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 15 Mar 2018 10:51:14 +0000 Subject: [PATCH 6/8] Import internal functions and constants --- src/Exception/InvalidObjectException.php | 3 +++ src/Exception/InvalidResourceValueException.php | 5 +++++ src/Exception/InvalidStrategyException.php | 5 +++++ src/Exception/UnknownMetadataTypeException.php | 3 +++ src/HalResource.php | 17 +++++++++++++++++ src/HalResponseFactory.php | 2 ++ src/Link.php | 12 ++++++++++++ src/LinkCollection.php | 3 +++ .../ExpressiveUrlGeneratorFactory.php | 2 ++ .../Exception/DuplicateMetadataException.php | 2 ++ .../Exception/InvalidConfigException.php | 7 +++++++ .../Exception/UndefinedClassException.php | 2 ++ .../Exception/UndefinedMetadataException.php | 2 ++ src/Metadata/MetadataMap.php | 2 ++ src/Metadata/MetadataMapFactory.php | 10 ++++++++++ .../RouteBasedCollectionMetadataFactory.php | 3 +++ .../RouteBasedResourceMetadataFactory.php | 3 +++ src/Metadata/UrlBasedCollectionMetadata.php | 3 +++ .../UrlBasedCollectionMetadataFactory.php | 3 +++ .../UrlBasedResourceMetadataFactory.php | 3 +++ src/Renderer/JsonRenderer.php | 2 ++ src/Renderer/XmlRenderer.php | 7 +++++++ src/ResourceGenerator.php | 8 ++++++++ .../Exception/InvalidCollectionException.php | 5 +++++ .../Exception/InvalidConfigException.php | 5 +++++ .../Exception/InvalidExtractorException.php | 5 +++++ .../UnexpectedMetadataTypeException.php | 3 +++ .../ExtractCollectionTrait.php | 4 ++++ src/ResourceGenerator/ExtractInstanceTrait.php | 3 +++ .../RouteBasedCollectionStrategy.php | 3 +++ .../UrlBasedCollectionStrategy.php | 11 +++++++++++ src/ResourceGeneratorFactory.php | 2 ++ test/Assertions.php | 9 +++++++++ test/ExceptionTest.php | 6 ++++++ test/HalResourceTest.php | 2 ++ test/HalResponseFactoryTest.php | 2 ++ test/Metadata/ExceptionTest.php | 6 ++++++ test/Renderer/JsonRendererTest.php | 2 ++ test/ResourceGenerator/ExceptionTest.php | 6 ++++++ .../NestedCollectionResourceGenerationTest.php | 2 ++ .../RouteBasedCollectionWithRouteParamsTest.php | 2 ++ 41 files changed, 187 insertions(+) diff --git a/src/Exception/InvalidObjectException.php b/src/Exception/InvalidObjectException.php index d7783b5..6aab992 100644 --- a/src/Exception/InvalidObjectException.php +++ b/src/Exception/InvalidObjectException.php @@ -10,6 +10,9 @@ use InvalidArgumentException; use Zend\Expressive\Hal\HalResource; +use function gettype; +use function sprintf; + class InvalidObjectException extends InvalidArgumentException implements ExceptionInterface { /** diff --git a/src/Exception/InvalidResourceValueException.php b/src/Exception/InvalidResourceValueException.php index e085163..7fc6777 100644 --- a/src/Exception/InvalidResourceValueException.php +++ b/src/Exception/InvalidResourceValueException.php @@ -10,6 +10,11 @@ use RuntimeException; use Zend\Expressive\Hal\HalResource; +use function get_class; +use function gettype; +use function is_object; +use function sprintf; + class InvalidResourceValueException extends RuntimeException implements ExceptionInterface { public static function fromValue($value) : self diff --git a/src/Exception/InvalidStrategyException.php b/src/Exception/InvalidStrategyException.php index 87061ce..a88c354 100644 --- a/src/Exception/InvalidStrategyException.php +++ b/src/Exception/InvalidStrategyException.php @@ -10,6 +10,11 @@ use InvalidArgumentException; use Zend\Expressive\Hal\ResourceGenerator\StrategyInterface; +use function get_class; +use function gettype; +use function is_object; +use function sprintf; + class InvalidStrategyException extends InvalidArgumentException implements ExceptionInterface { public static function forType(string $strategy) : self diff --git a/src/Exception/UnknownMetadataTypeException.php b/src/Exception/UnknownMetadataTypeException.php index 42fb2fd..a5fd2ca 100644 --- a/src/Exception/UnknownMetadataTypeException.php +++ b/src/Exception/UnknownMetadataTypeException.php @@ -10,6 +10,9 @@ use RuntimeException; use Zend\Expressive\Hal\Metadata\AbstractMetadata; +use function get_class; +use function sprintf; + class UnknownMetadataTypeException extends RuntimeException implements ExceptionInterface { public static function forMetadata(AbstractMetadata $metadata) : self diff --git a/src/HalResource.php b/src/HalResource.php index 137da10..40b0db3 100644 --- a/src/HalResource.php +++ b/src/HalResource.php @@ -13,6 +13,23 @@ use Psr\Link\LinkInterface; use RuntimeException; +use function array_key_exists; +use function array_keys; +use function array_map; +use function array_merge; +use function array_push; +use function array_reduce; +use function array_shift; +use function array_walk; +use function count; +use function get_class; +use function gettype; +use function in_array; +use function is_array; +use function is_object; +use function sort; +use function sprintf; + /** * Object representation of Hypertext Application Language resource. * diff --git a/src/HalResponseFactory.php b/src/HalResponseFactory.php index a3ddeee..e71bb57 100644 --- a/src/HalResponseFactory.php +++ b/src/HalResponseFactory.php @@ -11,6 +11,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use function strstr; + class HalResponseFactory { /** diff --git a/src/Link.php b/src/Link.php index 7884b90..449d4af 100644 --- a/src/Link.php +++ b/src/Link.php @@ -10,6 +10,18 @@ use InvalidArgumentException; use Psr\Link\EvolvableLinkInterface; +use function array_filter; +use function array_reduce; +use function get_class; +use function gettype; +use function in_array; +use function is_array; +use function is_object; +use function is_scalar; +use function is_string; +use function method_exists; +use function sprintf; + class Link implements EvolvableLinkInterface { const AS_COLLECTION = '__FORCE_COLLECTION__'; diff --git a/src/LinkCollection.php b/src/LinkCollection.php index 7a8ab3f..cb93feb 100644 --- a/src/LinkCollection.php +++ b/src/LinkCollection.php @@ -11,6 +11,9 @@ use Psr\Link\EvolvableLinkProviderInterface; use Traversable; +use function array_filter; +use function in_array; + /** * Properties and methods suitable for an * EvolvableLinkProviderInterface implementation. diff --git a/src/LinkGenerator/ExpressiveUrlGeneratorFactory.php b/src/LinkGenerator/ExpressiveUrlGeneratorFactory.php index 1c95b8f..b422ce9 100644 --- a/src/LinkGenerator/ExpressiveUrlGeneratorFactory.php +++ b/src/LinkGenerator/ExpressiveUrlGeneratorFactory.php @@ -12,6 +12,8 @@ use Zend\Expressive\Helper\ServerUrlHelper; use Zend\Expressive\Helper\UrlHelper; +use function sprintf; + class ExpressiveUrlGeneratorFactory { public function __invoke(ContainerInterface $container) : ExpressiveUrlGenerator diff --git a/src/Metadata/Exception/DuplicateMetadataException.php b/src/Metadata/Exception/DuplicateMetadataException.php index 9bf895b..b1d670a 100644 --- a/src/Metadata/Exception/DuplicateMetadataException.php +++ b/src/Metadata/Exception/DuplicateMetadataException.php @@ -9,6 +9,8 @@ use DomainException; +use function sprintf; + class DuplicateMetadataException extends DomainException implements ExceptionInterface { public static function create(string $class) diff --git a/src/Metadata/Exception/InvalidConfigException.php b/src/Metadata/Exception/InvalidConfigException.php index b313d5c..114831f 100644 --- a/src/Metadata/Exception/InvalidConfigException.php +++ b/src/Metadata/Exception/InvalidConfigException.php @@ -13,6 +13,13 @@ use Zend\Expressive\Hal\Metadata\MetadataMap; use Zend\Expressive\Hal\Metadata\MetadataMapFactory; +use function get_class; +use function gettype; +use function implode; +use function is_object; +use function is_string; +use function sprintf; + class InvalidConfigException extends RuntimeException implements ExceptionInterface { /** diff --git a/src/Metadata/Exception/UndefinedClassException.php b/src/Metadata/Exception/UndefinedClassException.php index c1bba10..4974157 100644 --- a/src/Metadata/Exception/UndefinedClassException.php +++ b/src/Metadata/Exception/UndefinedClassException.php @@ -9,6 +9,8 @@ use UnexpectedValueException; +use function sprintf; + class UndefinedClassException extends UnexpectedValueException implements ExceptionInterface { public static function create($class) diff --git a/src/Metadata/Exception/UndefinedMetadataException.php b/src/Metadata/Exception/UndefinedMetadataException.php index f356c4c..4cd13a0 100644 --- a/src/Metadata/Exception/UndefinedMetadataException.php +++ b/src/Metadata/Exception/UndefinedMetadataException.php @@ -9,6 +9,8 @@ use RuntimeException; +use function sprintf; + class UndefinedMetadataException extends RuntimeException implements ExceptionInterface { public static function create($class) diff --git a/src/Metadata/MetadataMap.php b/src/Metadata/MetadataMap.php index 515bf97..ce1291a 100644 --- a/src/Metadata/MetadataMap.php +++ b/src/Metadata/MetadataMap.php @@ -7,6 +7,8 @@ namespace Zend\Expressive\Hal\Metadata; +use function class_exists; + class MetadataMap { private $map = []; diff --git a/src/Metadata/MetadataMapFactory.php b/src/Metadata/MetadataMapFactory.php index 6df3142..ea1762a 100644 --- a/src/Metadata/MetadataMapFactory.php +++ b/src/Metadata/MetadataMapFactory.php @@ -9,6 +9,16 @@ use Psr\Container\ContainerInterface; +use function array_pop; +use function class_exists; +use function class_implements; +use function class_parents; +use function explode; +use function in_array; +use function is_array; +use function method_exists; +use function sprintf; + /** * Create a MetadataMap based on configuration. * diff --git a/src/Metadata/RouteBasedCollectionMetadataFactory.php b/src/Metadata/RouteBasedCollectionMetadataFactory.php index 2a91e66..0bafad9 100644 --- a/src/Metadata/RouteBasedCollectionMetadataFactory.php +++ b/src/Metadata/RouteBasedCollectionMetadataFactory.php @@ -7,6 +7,9 @@ namespace Zend\Expressive\Hal\Metadata; +use function array_intersect; +use function array_keys; + class RouteBasedCollectionMetadataFactory implements MetadataFactoryInterface { /** diff --git a/src/Metadata/RouteBasedResourceMetadataFactory.php b/src/Metadata/RouteBasedResourceMetadataFactory.php index e846782..328f439 100644 --- a/src/Metadata/RouteBasedResourceMetadataFactory.php +++ b/src/Metadata/RouteBasedResourceMetadataFactory.php @@ -7,6 +7,9 @@ namespace Zend\Expressive\Hal\Metadata; +use function array_intersect; +use function array_keys; + class RouteBasedResourceMetadataFactory implements MetadataFactoryInterface { /** diff --git a/src/Metadata/UrlBasedCollectionMetadata.php b/src/Metadata/UrlBasedCollectionMetadata.php index 5245cda..991d52a 100644 --- a/src/Metadata/UrlBasedCollectionMetadata.php +++ b/src/Metadata/UrlBasedCollectionMetadata.php @@ -9,6 +9,9 @@ use InvalidArgumentException; +use function in_array; +use function sprintf; + class UrlBasedCollectionMetadata extends AbstractCollectionMetadata { /** diff --git a/src/Metadata/UrlBasedCollectionMetadataFactory.php b/src/Metadata/UrlBasedCollectionMetadataFactory.php index 1be0ce5..14432de 100644 --- a/src/Metadata/UrlBasedCollectionMetadataFactory.php +++ b/src/Metadata/UrlBasedCollectionMetadataFactory.php @@ -7,6 +7,9 @@ namespace Zend\Expressive\Hal\Metadata; +use function array_intersect; +use function array_keys; + class UrlBasedCollectionMetadataFactory implements MetadataFactoryInterface { /** diff --git a/src/Metadata/UrlBasedResourceMetadataFactory.php b/src/Metadata/UrlBasedResourceMetadataFactory.php index cba746b..318fd27 100644 --- a/src/Metadata/UrlBasedResourceMetadataFactory.php +++ b/src/Metadata/UrlBasedResourceMetadataFactory.php @@ -7,6 +7,9 @@ namespace Zend\Expressive\Hal\Metadata; +use function array_intersect; +use function array_keys; + class UrlBasedResourceMetadataFactory implements MetadataFactoryInterface { /** diff --git a/src/Renderer/JsonRenderer.php b/src/Renderer/JsonRenderer.php index 5a001fd..e9f6852 100644 --- a/src/Renderer/JsonRenderer.php +++ b/src/Renderer/JsonRenderer.php @@ -9,6 +9,8 @@ use Zend\Expressive\Hal\HalResource; +use function json_encode; + class JsonRenderer implements RendererInterface { // @codingStandardsIgnoreStart diff --git a/src/Renderer/XmlRenderer.php b/src/Renderer/XmlRenderer.php index 65a21da..38c74b6 100644 --- a/src/Renderer/XmlRenderer.php +++ b/src/Renderer/XmlRenderer.php @@ -13,6 +13,13 @@ use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\Exception; +use function array_values; +use function is_array; +use function is_object; +use function is_scalar; +use function method_exists; +use function trim; + class XmlRenderer implements RendererInterface { public function render(HalResource $resource) : string diff --git a/src/ResourceGenerator.php b/src/ResourceGenerator.php index efc1bc4..6693b28 100644 --- a/src/ResourceGenerator.php +++ b/src/ResourceGenerator.php @@ -9,6 +9,14 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; + +use function class_exists; +use function class_implements; +use function class_parents; +use function get_class; +use function in_array; +use function is_object; +use function is_string; use Zend\Hydrator\ExtractionInterface; class ResourceGenerator diff --git a/src/ResourceGenerator/Exception/InvalidCollectionException.php b/src/ResourceGenerator/Exception/InvalidCollectionException.php index 416d3f0..6aca370 100644 --- a/src/ResourceGenerator/Exception/InvalidCollectionException.php +++ b/src/ResourceGenerator/Exception/InvalidCollectionException.php @@ -9,6 +9,11 @@ use RuntimeException; +use function get_class; +use function gettype; +use function is_object; +use function sprintf; + class InvalidCollectionException extends RuntimeException implements ExceptionInterface { /** diff --git a/src/ResourceGenerator/Exception/InvalidConfigException.php b/src/ResourceGenerator/Exception/InvalidConfigException.php index 5f977fd..705d1cd 100644 --- a/src/ResourceGenerator/Exception/InvalidConfigException.php +++ b/src/ResourceGenerator/Exception/InvalidConfigException.php @@ -10,6 +10,11 @@ use RuntimeException; use Zend\Expressive\Hal\ResourceGenerator; +use function get_class; +use function gettype; +use function is_object; +use function sprintf; + class InvalidConfigException extends RuntimeException implements ExceptionInterface { /** diff --git a/src/ResourceGenerator/Exception/InvalidExtractorException.php b/src/ResourceGenerator/Exception/InvalidExtractorException.php index 9a3cfeb..0ef1e42 100644 --- a/src/ResourceGenerator/Exception/InvalidExtractorException.php +++ b/src/ResourceGenerator/Exception/InvalidExtractorException.php @@ -10,6 +10,11 @@ use RuntimeException; use Zend\Hydrator\ExtractionInterface; +use function get_class; +use function gettype; +use function is_object; +use function sprintf; + class InvalidExtractorException extends RuntimeException implements ExceptionInterface { /** diff --git a/src/ResourceGenerator/Exception/UnexpectedMetadataTypeException.php b/src/ResourceGenerator/Exception/UnexpectedMetadataTypeException.php index d43c0c7..85ab38c 100644 --- a/src/ResourceGenerator/Exception/UnexpectedMetadataTypeException.php +++ b/src/ResourceGenerator/Exception/UnexpectedMetadataTypeException.php @@ -11,6 +11,9 @@ use Zend\Expressive\Hal\Metadata\AbstractCollectionMetadata; use Zend\Expressive\Hal\Metadata\AbstractMetadata; +use function get_class; +use function sprintf; + class UnexpectedMetadataTypeException extends RuntimeException implements ExceptionInterface { public static function forMetadata(AbstractMetadata $metadata, string $strategy, string $expected) : self diff --git a/src/ResourceGenerator/ExtractCollectionTrait.php b/src/ResourceGenerator/ExtractCollectionTrait.php index 5216b5c..02a0641 100644 --- a/src/ResourceGenerator/ExtractCollectionTrait.php +++ b/src/ResourceGenerator/ExtractCollectionTrait.php @@ -17,6 +17,10 @@ use Zend\Expressive\Hal\ResourceGenerator\Exception; use Zend\Paginator\Paginator; +use function get_class; +use function in_array; +use function sprintf; + trait ExtractCollectionTrait { private $paginationTypes = [ diff --git a/src/ResourceGenerator/ExtractInstanceTrait.php b/src/ResourceGenerator/ExtractInstanceTrait.php index 173997c..3fdaafe 100644 --- a/src/ResourceGenerator/ExtractInstanceTrait.php +++ b/src/ResourceGenerator/ExtractInstanceTrait.php @@ -14,6 +14,9 @@ use Zend\Expressive\Hal\ResourceGenerator; use Zend\Hydrator\ExtractionInterface; +use function get_class; +use function is_object; + trait ExtractInstanceTrait { /** diff --git a/src/ResourceGenerator/RouteBasedCollectionStrategy.php b/src/ResourceGenerator/RouteBasedCollectionStrategy.php index 4233afe..e423402 100644 --- a/src/ResourceGenerator/RouteBasedCollectionStrategy.php +++ b/src/ResourceGenerator/RouteBasedCollectionStrategy.php @@ -14,6 +14,9 @@ use Zend\Expressive\Hal\Metadata; use Zend\Expressive\Hal\ResourceGenerator; +use function array_merge; +use function get_class; + class RouteBasedCollectionStrategy implements StrategyInterface { use ExtractCollectionTrait; diff --git a/src/ResourceGenerator/UrlBasedCollectionStrategy.php b/src/ResourceGenerator/UrlBasedCollectionStrategy.php index bc263c7..d108473 100644 --- a/src/ResourceGenerator/UrlBasedCollectionStrategy.php +++ b/src/ResourceGenerator/UrlBasedCollectionStrategy.php @@ -14,6 +14,17 @@ use Zend\Expressive\Hal\Metadata; use Zend\Expressive\Hal\ResourceGenerator; +use function get_class; +use function http_build_query; +use function parse_str; +use function parse_url; +use function preg_replace; +use function sprintf; +use function str_replace; + +use const PHP_URL_FRAGMENT; +use const PHP_URL_QUERY; + class UrlBasedCollectionStrategy implements StrategyInterface { use ExtractCollectionTrait; diff --git a/src/ResourceGeneratorFactory.php b/src/ResourceGeneratorFactory.php index 569826d..74d3daf 100644 --- a/src/ResourceGeneratorFactory.php +++ b/src/ResourceGeneratorFactory.php @@ -13,6 +13,8 @@ use Zend\Expressive\Hal\ResourceGenerator\Exception\InvalidConfigException; use Zend\Hydrator\HydratorPluginManager; +use function is_array; + class ResourceGeneratorFactory { public function __invoke(ContainerInterface $container) : ResourceGenerator diff --git a/test/Assertions.php b/test/Assertions.php index 98c1edc..9d6e02d 100644 --- a/test/Assertions.php +++ b/test/Assertions.php @@ -10,6 +10,15 @@ use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\Link; +use function array_shift; +use function count; +use function get_class; +use function gettype; +use function in_array; +use function is_object; +use function sprintf; +use function var_export; + trait Assertions { public static function getLinkByRel(string $rel, HalResource $resource) : Link diff --git a/test/ExceptionTest.php b/test/ExceptionTest.php index a084c01..405d202 100644 --- a/test/ExceptionTest.php +++ b/test/ExceptionTest.php @@ -13,6 +13,12 @@ use PHPUnit\Framework\TestCase; use Zend\Expressive\Hal\Exception\ExceptionInterface; +use function basename; +use function glob; +use function is_a; +use function strrpos; +use function substr; + class ExceptionTest extends TestCase { public function exception() : Generator diff --git a/test/HalResourceTest.php b/test/HalResourceTest.php index ccad532..763eae4 100644 --- a/test/HalResourceTest.php +++ b/test/HalResourceTest.php @@ -13,6 +13,8 @@ use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\Link; +use function array_values; + class HalResourceTest extends TestCase { public function testCanConstructWithData() diff --git a/test/HalResponseFactoryTest.php b/test/HalResponseFactoryTest.php index c4f95d9..9c7cc85 100644 --- a/test/HalResponseFactoryTest.php +++ b/test/HalResponseFactoryTest.php @@ -19,6 +19,8 @@ use Zend\Expressive\Hal\Renderer; use ZendTest\Expressive\Hal\Renderer\TestAsset; +use function strstr; + class HalResponseFactoryTest extends TestCase { use TestAsset; diff --git a/test/Metadata/ExceptionTest.php b/test/Metadata/ExceptionTest.php index a424fd2..39ba49a 100644 --- a/test/Metadata/ExceptionTest.php +++ b/test/Metadata/ExceptionTest.php @@ -14,6 +14,12 @@ use Zend\Expressive\Hal\Exception\ExceptionInterface as HalExceptionInterface; use Zend\Expressive\Hal\Metadata\Exception\ExceptionInterface; +use function basename; +use function glob; +use function is_a; +use function strrpos; +use function substr; + class ExceptionTest extends TestCase { public function testExceptionInterfaceExtendsHalExceptionInterface() : void diff --git a/test/Renderer/JsonRendererTest.php b/test/Renderer/JsonRendererTest.php index 260af60..6df3669 100644 --- a/test/Renderer/JsonRendererTest.php +++ b/test/Renderer/JsonRendererTest.php @@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase; use Zend\Expressive\Hal\Renderer\JsonRenderer; +use function json_encode; + class JsonRendererTest extends TestCase { use TestAsset; diff --git a/test/ResourceGenerator/ExceptionTest.php b/test/ResourceGenerator/ExceptionTest.php index 89ab5a3..8994ef8 100644 --- a/test/ResourceGenerator/ExceptionTest.php +++ b/test/ResourceGenerator/ExceptionTest.php @@ -14,6 +14,12 @@ use Zend\Expressive\Hal\Exception\ExceptionInterface as HalExceptionInterface; use Zend\Expressive\Hal\ResourceGenerator\Exception\ExceptionInterface; +use function basename; +use function glob; +use function is_a; +use function strrpos; +use function substr; + class ExceptionTest extends TestCase { public function testExceptionInterfaceExtendsHalExceptionInterface() : void diff --git a/test/ResourceGenerator/NestedCollectionResourceGenerationTest.php b/test/ResourceGenerator/NestedCollectionResourceGenerationTest.php index eb302c3..ebe334c 100644 --- a/test/ResourceGenerator/NestedCollectionResourceGenerationTest.php +++ b/test/ResourceGenerator/NestedCollectionResourceGenerationTest.php @@ -21,6 +21,8 @@ use ZendTest\Expressive\Hal\Assertions; use ZendTest\Expressive\Hal\TestAsset; +use function array_shift; + class NestedCollectionResourceGenerationTest extends TestCase { use Assertions; diff --git a/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php b/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php index cc7f79b..a77a9b0 100644 --- a/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php +++ b/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php @@ -23,6 +23,8 @@ use ZendTest\Expressive\Hal\Assertions; use ZendTest\Expressive\Hal\TestAsset; +use function sprintf; + class RouteBasedCollectionWithRouteParamsTest extends TestCase { use Assertions; From 04574f25a8c4e8e5dfde87180cc0699fecddca9a Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 15 Mar 2018 10:51:34 +0000 Subject: [PATCH 7/8] Optimize imports - removed unused and alphabetical order --- src/LinkCollection.php | 3 +-- src/Renderer/XmlRenderer.php | 2 +- src/ResourceGenerator.php | 1 - src/ResourceGenerator/ExtractCollectionTrait.php | 1 - src/ResourceGenerator/ExtractInstanceTrait.php | 1 - src/ResourceGenerator/RouteBasedResourceStrategy.php | 1 - test/HalResponseFactoryFactoryTest.php | 3 +-- test/HalResponseFactoryTest.php | 4 ---- test/LinkGenerator/ExpressiveUrlGeneratorTest.php | 1 - test/Renderer/XmlRendererTest.php | 1 - 10 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/LinkCollection.php b/src/LinkCollection.php index cb93feb..eceb762 100644 --- a/src/LinkCollection.php +++ b/src/LinkCollection.php @@ -7,9 +7,8 @@ namespace Zend\Expressive\Hal; -use Psr\Link\LinkInterface; use Psr\Link\EvolvableLinkProviderInterface; -use Traversable; +use Psr\Link\LinkInterface; use function array_filter; use function in_array; diff --git a/src/Renderer/XmlRenderer.php b/src/Renderer/XmlRenderer.php index 38c74b6..f389fa1 100644 --- a/src/Renderer/XmlRenderer.php +++ b/src/Renderer/XmlRenderer.php @@ -10,8 +10,8 @@ use DateTimeInterface; use DOMDocument; use DOMNode; -use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\Exception; +use Zend\Expressive\Hal\HalResource; use function array_values; use function is_array; diff --git a/src/ResourceGenerator.php b/src/ResourceGenerator.php index 6693b28..d29471b 100644 --- a/src/ResourceGenerator.php +++ b/src/ResourceGenerator.php @@ -17,7 +17,6 @@ use function in_array; use function is_object; use function is_string; -use Zend\Hydrator\ExtractionInterface; class ResourceGenerator { diff --git a/src/ResourceGenerator/ExtractCollectionTrait.php b/src/ResourceGenerator/ExtractCollectionTrait.php index 02a0641..e20e34e 100644 --- a/src/ResourceGenerator/ExtractCollectionTrait.php +++ b/src/ResourceGenerator/ExtractCollectionTrait.php @@ -14,7 +14,6 @@ use Zend\Expressive\Hal\Link; use Zend\Expressive\Hal\Metadata\AbstractCollectionMetadata; use Zend\Expressive\Hal\ResourceGenerator; -use Zend\Expressive\Hal\ResourceGenerator\Exception; use Zend\Paginator\Paginator; use function get_class; diff --git a/src/ResourceGenerator/ExtractInstanceTrait.php b/src/ResourceGenerator/ExtractInstanceTrait.php index 3fdaafe..f0ad381 100644 --- a/src/ResourceGenerator/ExtractInstanceTrait.php +++ b/src/ResourceGenerator/ExtractInstanceTrait.php @@ -7,7 +7,6 @@ namespace Zend\Expressive\Hal\ResourceGenerator; -use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Zend\Expressive\Hal\Metadata\AbstractCollectionMetadata; use Zend\Expressive\Hal\Metadata\AbstractMetadata; diff --git a/src/ResourceGenerator/RouteBasedResourceStrategy.php b/src/ResourceGenerator/RouteBasedResourceStrategy.php index 86b52dd..e040851 100644 --- a/src/ResourceGenerator/RouteBasedResourceStrategy.php +++ b/src/ResourceGenerator/RouteBasedResourceStrategy.php @@ -9,7 +9,6 @@ use Psr\Http\Message\ServerRequestInterface; use Zend\Expressive\Hal\HalResource; -use Zend\Expressive\Hal\Link; use Zend\Expressive\Hal\Metadata; use Zend\Expressive\Hal\ResourceGenerator; diff --git a/test/HalResponseFactoryFactoryTest.php b/test/HalResponseFactoryFactoryTest.php index a68ea20..bf92b53 100644 --- a/test/HalResponseFactoryFactoryTest.php +++ b/test/HalResponseFactoryFactoryTest.php @@ -9,14 +9,13 @@ namespace ZendTest\Expressive\Hal; -use Closure; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseInterface; use ReflectionProperty; -use Zend\Expressive\Hal\HalResponseFactoryFactory; use Zend\Expressive\Hal\HalResponseFactory; +use Zend\Expressive\Hal\HalResponseFactoryFactory; use Zend\Expressive\Hal\Renderer; class HalResponseFactoryFactoryTest extends TestCase diff --git a/test/HalResponseFactoryTest.php b/test/HalResponseFactoryTest.php index 9c7cc85..9fa35bf 100644 --- a/test/HalResponseFactoryTest.php +++ b/test/HalResponseFactoryTest.php @@ -8,14 +8,10 @@ namespace ZendTest\Expressive\Hal; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; -use ReflectionProperty; -use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\HalResponseFactory; -use Zend\Expressive\Hal\Link; use Zend\Expressive\Hal\Renderer; use ZendTest\Expressive\Hal\Renderer\TestAsset; diff --git a/test/LinkGenerator/ExpressiveUrlGeneratorTest.php b/test/LinkGenerator/ExpressiveUrlGeneratorTest.php index f4d24a8..e436455 100644 --- a/test/LinkGenerator/ExpressiveUrlGeneratorTest.php +++ b/test/LinkGenerator/ExpressiveUrlGeneratorTest.php @@ -12,7 +12,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; use Zend\Expressive\Hal\LinkGenerator\ExpressiveUrlGenerator; -use Zend\Expressive\Hal\LinkGenerator\UrlGenerator; use Zend\Expressive\Helper\ServerUrlHelper; use Zend\Expressive\Helper\UrlHelper; diff --git a/test/Renderer/XmlRendererTest.php b/test/Renderer/XmlRendererTest.php index 00dca41..51fc8f5 100644 --- a/test/Renderer/XmlRendererTest.php +++ b/test/Renderer/XmlRendererTest.php @@ -9,7 +9,6 @@ use DateTime; use PHPUnit\Framework\TestCase; -use stdClass; use Zend\Expressive\Hal\HalResource; use Zend\Expressive\Hal\Link; use Zend\Expressive\Hal\Renderer\XmlRenderer; From 5d2756150a43eeaa231ce70da4627ff789ff26c6 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 15 Mar 2018 10:17:54 -0500 Subject: [PATCH 8/8] Prepares for 1.0.0 release - Adds branch aliases: - dev-master => 1.0.x-dev - dev-develop => 1.1.x-dev (to be created) - Renames alpha1 entry to 1.0.0 and sets current date in CHANGELOG --- CHANGELOG.md | 2 +- composer.json | 4 ++++ composer.lock | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab3ad7..05eac01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file, in reverse Versions prior to 0.4.0 were released as the package "weierophinney/hal". -## 1.0.0alpha1 - 2018-02-27 +## 1.0.0 - 2018-03-15 ### Added diff --git a/composer.json b/composer.json index 71705c8..b7478b0 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,10 @@ "sort-packages": true }, "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev", + "dev-develop": "1.1.x-dev" + }, "zf": { "config-provider": "Zend\\Expressive\\Hal\\ConfigProvider" } diff --git a/composer.lock b/composer.lock index 3267e5e..b572323 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "31b30ceef02eaca5633fc50e5bf0ec81", + "content-hash": "c5f17243aee12989c223de1905cccd13", "packages": [ { "name": "psr/http-message",