├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json ├── composer.lock ├── examples └── basic_server.php ├── lib ├── Adapter │ └── Guzzle │ │ └── Factory.php ├── Server.php └── ServerMiddleware │ ├── CallableServerMiddleware.php │ ├── ErrorHandler.php │ ├── GZip.php │ └── HSTS.php └── spec ├── FactoryInterface.php ├── ServerFrameInterface.php └── ServerMiddlewareInterface.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Anthony Ferrara 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Tari-PHP 2 | ======== 3 | A PSR-7 Middleware Interface proof-of-concept for PHP. 4 | 5 | # Requirements 6 | * PHP 7.0 7 | 8 | Yes, that's the only hard requirement 9 | 10 | # Usage As An End User 11 | 12 | To use this runner, you need to pick a PSR-7 Library. We'll use Guzzle's. 13 | 14 | First, install it: `composer require guzzle/psr7` 15 | 16 | Now, we need a factory instance for the PSR-7 Library; 17 | 18 | ```php 19 | $factory = new Tari\Adapter\Guzzle\Factory; 20 | ``` 21 | 22 | Next, we boot up the "Server": 23 | 24 | ```php 25 | $server = new Tari\Server($factory); 26 | ``` 27 | 28 | Next, append whatever middleware we want to. In this case, let's add the error handler and the HSTS middleware: 29 | 30 | ```php 31 | $server->append(new Tari\ServerMiddleware\ErrorHandler); 32 | $server->append(new Tari\ServerMiddleware\HSTS(300 /* Max-age in seconds */)); 33 | ``` 34 | 35 | We can also add middleware as closures (Notice we don't need types): 36 | 37 | ```php 38 | $server->append(function($request, $frame) { 39 | $response = $frame->next($request); 40 | return $response->withHeader('X-Powered-By', 'Tari-PHP'); 41 | }); 42 | ``` 43 | 44 | We also need a "default" action to take: 45 | 46 | ```php 47 | $default = function($request) use ($factory) { 48 | // Default to a 404 NOT FOUND response 49 | return $factory->createResponse("Not Found", 404); 50 | }; 51 | ``` 52 | 53 | Finally, we can run out stack: 54 | 55 | ```php 56 | $request = new Guzzle\Psr7\ServerRequest("http://www.example.com/foo", "GET"); 57 | $response = $server->run($request, $default); 58 | ``` 59 | 60 | And that's all there is to it... 61 | 62 | # Usage As A Library Builder (Server Mode) 63 | 64 | To use this middleware as a library author, simply implement the `Tari\MiddlewareInterface` interface. It's as easy as that: 65 | 66 | ```php 67 | use Tari\ServerMiddlewareInterface; 68 | use Tari\ServerFrameInterface; 69 | 70 | use Psr\Http\Message\ServerRequestInterface; 71 | use Psr\Http\Message\ResponseInterface; 72 | 73 | class Foo implements ServerMiddlewareInterface { 74 | public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface { 75 | // Do your modifications to the request here 76 | $response = $frame->next($request); 77 | // Do your modifications to the response here 78 | return $response; 79 | } 80 | } 81 | ``` 82 | 83 | It's as simple as that. 84 | 85 | ## Aborting a request 86 | 87 | Sometimes, you don't want to continue with a request. If you detect that situation in your middleware, simply create a new response: 88 | 89 | ```php 90 | use Tari\ServerMiddlewareInterface; 91 | use Tari\ServerFrameInterface; 92 | 93 | use Psr\Http\Message\ServerRequestInterface; 94 | use Psr\Http\Message\ResponseInterface; 95 | 96 | class Foo implements ServerMiddlewareInterface { 97 | public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface { 98 | if ($this->isBadRequest($request)) { 99 | return $frame->factory()->createResponse("Bad Request", 400); 100 | } 101 | return $frame->next($request); 102 | } 103 | } 104 | ``` 105 | 106 | # Interfaces 107 | 108 | Tari defines 3 consumable interfaces: 109 | 110 | ## ServerMiddlewareInterface 111 | 112 | ```php 113 | interface ServerMiddlewareInterface { 114 | public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface; 115 | } 116 | ``` 117 | 118 | Used for Server request processing 119 | 120 | ## ServerFrameInterface 121 | 122 | ```php 123 | interface ServerFrameInterface { 124 | public function next(ServerRequestInterface $request): ResponseInterface; 125 | public function factory(): FactoryInterface; 126 | } 127 | ``` 128 | 129 | This is used for processing server requests 130 | 131 | ## FactoryInterface 132 | 133 | ```php 134 | interface FactoryInterface { 135 | 136 | public function createRequest( 137 | UriInterface $uri = null, 138 | string $method = '', 139 | array $headers = [], 140 | $body = null 141 | ): RequestInterface; 142 | 143 | public function createServerRequest( 144 | UriInterface $uri = null, 145 | string $method = '', 146 | array $headers = [], 147 | $body = null 148 | ): ServerRequestInterface; 149 | 150 | public function createResponse( 151 | int $status = 200, 152 | array $headers = [], 153 | $body = null 154 | ): ResponseInterface; 155 | 156 | public function createStream($data = null): StreamInterface; 157 | 158 | public function createUri(string $uri = ''): UriInterface; 159 | 160 | public function createUploadedFile( 161 | $data, 162 | int $size, 163 | int $error, 164 | string $clientFile = '', 165 | string $clientMediaType = '' 166 | ): UploadedFileInterface; 167 | } 168 | ``` 169 | 170 | There's a lot more going on here, but it's still extremely straight forward and simple. 171 | 172 | Each method creates a PSR-7 object, and initializes it. 173 | 174 | # License 175 | 176 | MIT 177 | 178 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ircmaxell/tari-php", 3 | "description": "A Middleware Proof-Of-Concept Library For PHP", 4 | "type": "library", 5 | "require": { 6 | "php": "^7", 7 | "psr/http-message": "^1.0" 8 | }, 9 | "require-dev": { 10 | "guzzlehttp/psr7": "^1.3", 11 | "phpunit/phpunit": "^5.3" 12 | }, 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "Anthony Ferrara", 17 | "email": "ircmaxell@gmail.com" 18 | } 19 | ], 20 | "autoload": { 21 | "psr-4": {"Tari\\": ["lib/", "spec/"]} 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "94dc2c224e7f379530293d5ace083ffe", 8 | "content-hash": "ce7777104e92cfdf03b6557c93c5c18e", 9 | "packages": [ 10 | { 11 | "name": "psr/http-message", 12 | "version": "1.0", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/php-fig/http-message.git", 16 | "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", 21 | "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "php": ">=5.3.0" 26 | }, 27 | "type": "library", 28 | "extra": { 29 | "branch-alias": { 30 | "dev-master": "1.0.x-dev" 31 | } 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Psr\\Http\\Message\\": "src/" 36 | } 37 | }, 38 | "notification-url": "https://packagist.org/downloads/", 39 | "license": [ 40 | "MIT" 41 | ], 42 | "authors": [ 43 | { 44 | "name": "PHP-FIG", 45 | "homepage": "http://www.php-fig.org/" 46 | } 47 | ], 48 | "description": "Common interface for HTTP messages", 49 | "keywords": [ 50 | "http", 51 | "http-message", 52 | "psr", 53 | "psr-7", 54 | "request", 55 | "response" 56 | ], 57 | "time": "2015-05-04 20:22:00" 58 | } 59 | ], 60 | "packages-dev": [ 61 | { 62 | "name": "doctrine/instantiator", 63 | "version": "1.0.5", 64 | "source": { 65 | "type": "git", 66 | "url": "https://github.com/doctrine/instantiator.git", 67 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" 68 | }, 69 | "dist": { 70 | "type": "zip", 71 | "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", 72 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", 73 | "shasum": "" 74 | }, 75 | "require": { 76 | "php": ">=5.3,<8.0-DEV" 77 | }, 78 | "require-dev": { 79 | "athletic/athletic": "~0.1.8", 80 | "ext-pdo": "*", 81 | "ext-phar": "*", 82 | "phpunit/phpunit": "~4.0", 83 | "squizlabs/php_codesniffer": "~2.0" 84 | }, 85 | "type": "library", 86 | "extra": { 87 | "branch-alias": { 88 | "dev-master": "1.0.x-dev" 89 | } 90 | }, 91 | "autoload": { 92 | "psr-4": { 93 | "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" 94 | } 95 | }, 96 | "notification-url": "https://packagist.org/downloads/", 97 | "license": [ 98 | "MIT" 99 | ], 100 | "authors": [ 101 | { 102 | "name": "Marco Pivetta", 103 | "email": "ocramius@gmail.com", 104 | "homepage": "http://ocramius.github.com/" 105 | } 106 | ], 107 | "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", 108 | "homepage": "https://github.com/doctrine/instantiator", 109 | "keywords": [ 110 | "constructor", 111 | "instantiate" 112 | ], 113 | "time": "2015-06-14 21:17:01" 114 | }, 115 | { 116 | "name": "guzzlehttp/psr7", 117 | "version": "1.3.0", 118 | "source": { 119 | "type": "git", 120 | "url": "https://github.com/guzzle/psr7.git", 121 | "reference": "31382fef2889136415751badebbd1cb022a4ed72" 122 | }, 123 | "dist": { 124 | "type": "zip", 125 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72", 126 | "reference": "31382fef2889136415751badebbd1cb022a4ed72", 127 | "shasum": "" 128 | }, 129 | "require": { 130 | "php": ">=5.4.0", 131 | "psr/http-message": "~1.0" 132 | }, 133 | "provide": { 134 | "psr/http-message-implementation": "1.0" 135 | }, 136 | "require-dev": { 137 | "phpunit/phpunit": "~4.0" 138 | }, 139 | "type": "library", 140 | "extra": { 141 | "branch-alias": { 142 | "dev-master": "1.0-dev" 143 | } 144 | }, 145 | "autoload": { 146 | "psr-4": { 147 | "GuzzleHttp\\Psr7\\": "src/" 148 | }, 149 | "files": [ 150 | "src/functions_include.php" 151 | ] 152 | }, 153 | "notification-url": "https://packagist.org/downloads/", 154 | "license": [ 155 | "MIT" 156 | ], 157 | "authors": [ 158 | { 159 | "name": "Michael Dowling", 160 | "email": "mtdowling@gmail.com", 161 | "homepage": "https://github.com/mtdowling" 162 | } 163 | ], 164 | "description": "PSR-7 message implementation", 165 | "keywords": [ 166 | "http", 167 | "message", 168 | "stream", 169 | "uri" 170 | ], 171 | "time": "2016-04-13 19:56:01" 172 | }, 173 | { 174 | "name": "myclabs/deep-copy", 175 | "version": "1.5.1", 176 | "source": { 177 | "type": "git", 178 | "url": "https://github.com/myclabs/DeepCopy.git", 179 | "reference": "a8773992b362b58498eed24bf85005f363c34771" 180 | }, 181 | "dist": { 182 | "type": "zip", 183 | "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/a8773992b362b58498eed24bf85005f363c34771", 184 | "reference": "a8773992b362b58498eed24bf85005f363c34771", 185 | "shasum": "" 186 | }, 187 | "require": { 188 | "php": ">=5.4.0" 189 | }, 190 | "require-dev": { 191 | "doctrine/collections": "1.*", 192 | "phpunit/phpunit": "~4.1" 193 | }, 194 | "type": "library", 195 | "autoload": { 196 | "psr-4": { 197 | "DeepCopy\\": "src/DeepCopy/" 198 | } 199 | }, 200 | "notification-url": "https://packagist.org/downloads/", 201 | "license": [ 202 | "MIT" 203 | ], 204 | "description": "Create deep copies (clones) of your objects", 205 | "homepage": "https://github.com/myclabs/DeepCopy", 206 | "keywords": [ 207 | "clone", 208 | "copy", 209 | "duplicate", 210 | "object", 211 | "object graph" 212 | ], 213 | "time": "2015-11-20 12:04:31" 214 | }, 215 | { 216 | "name": "phpdocumentor/reflection-docblock", 217 | "version": "2.0.4", 218 | "source": { 219 | "type": "git", 220 | "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", 221 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" 222 | }, 223 | "dist": { 224 | "type": "zip", 225 | "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", 226 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", 227 | "shasum": "" 228 | }, 229 | "require": { 230 | "php": ">=5.3.3" 231 | }, 232 | "require-dev": { 233 | "phpunit/phpunit": "~4.0" 234 | }, 235 | "suggest": { 236 | "dflydev/markdown": "~1.0", 237 | "erusev/parsedown": "~1.0" 238 | }, 239 | "type": "library", 240 | "extra": { 241 | "branch-alias": { 242 | "dev-master": "2.0.x-dev" 243 | } 244 | }, 245 | "autoload": { 246 | "psr-0": { 247 | "phpDocumentor": [ 248 | "src/" 249 | ] 250 | } 251 | }, 252 | "notification-url": "https://packagist.org/downloads/", 253 | "license": [ 254 | "MIT" 255 | ], 256 | "authors": [ 257 | { 258 | "name": "Mike van Riel", 259 | "email": "mike.vanriel@naenius.com" 260 | } 261 | ], 262 | "time": "2015-02-03 12:10:50" 263 | }, 264 | { 265 | "name": "phpspec/prophecy", 266 | "version": "v1.6.0", 267 | "source": { 268 | "type": "git", 269 | "url": "https://github.com/phpspec/prophecy.git", 270 | "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972" 271 | }, 272 | "dist": { 273 | "type": "zip", 274 | "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972", 275 | "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972", 276 | "shasum": "" 277 | }, 278 | "require": { 279 | "doctrine/instantiator": "^1.0.2", 280 | "php": "^5.3|^7.0", 281 | "phpdocumentor/reflection-docblock": "~2.0", 282 | "sebastian/comparator": "~1.1", 283 | "sebastian/recursion-context": "~1.0" 284 | }, 285 | "require-dev": { 286 | "phpspec/phpspec": "~2.0" 287 | }, 288 | "type": "library", 289 | "extra": { 290 | "branch-alias": { 291 | "dev-master": "1.5.x-dev" 292 | } 293 | }, 294 | "autoload": { 295 | "psr-0": { 296 | "Prophecy\\": "src/" 297 | } 298 | }, 299 | "notification-url": "https://packagist.org/downloads/", 300 | "license": [ 301 | "MIT" 302 | ], 303 | "authors": [ 304 | { 305 | "name": "Konstantin Kudryashov", 306 | "email": "ever.zet@gmail.com", 307 | "homepage": "http://everzet.com" 308 | }, 309 | { 310 | "name": "Marcello Duarte", 311 | "email": "marcello.duarte@gmail.com" 312 | } 313 | ], 314 | "description": "Highly opinionated mocking framework for PHP 5.3+", 315 | "homepage": "https://github.com/phpspec/prophecy", 316 | "keywords": [ 317 | "Double", 318 | "Dummy", 319 | "fake", 320 | "mock", 321 | "spy", 322 | "stub" 323 | ], 324 | "time": "2016-02-15 07:46:21" 325 | }, 326 | { 327 | "name": "phpunit/php-code-coverage", 328 | "version": "3.3.1", 329 | "source": { 330 | "type": "git", 331 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git", 332 | "reference": "2431befdd451fac43fbcde94d1a92fb3b8b68f86" 333 | }, 334 | "dist": { 335 | "type": "zip", 336 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2431befdd451fac43fbcde94d1a92fb3b8b68f86", 337 | "reference": "2431befdd451fac43fbcde94d1a92fb3b8b68f86", 338 | "shasum": "" 339 | }, 340 | "require": { 341 | "php": "^5.6 || ^7.0", 342 | "phpunit/php-file-iterator": "~1.3", 343 | "phpunit/php-text-template": "~1.2", 344 | "phpunit/php-token-stream": "^1.4.2", 345 | "sebastian/code-unit-reverse-lookup": "~1.0", 346 | "sebastian/environment": "^1.3.2", 347 | "sebastian/version": "~1.0|~2.0" 348 | }, 349 | "require-dev": { 350 | "ext-xdebug": ">=2.1.4", 351 | "phpunit/phpunit": "~5" 352 | }, 353 | "suggest": { 354 | "ext-dom": "*", 355 | "ext-xdebug": ">=2.4.0", 356 | "ext-xmlwriter": "*" 357 | }, 358 | "type": "library", 359 | "extra": { 360 | "branch-alias": { 361 | "dev-master": "3.3.x-dev" 362 | } 363 | }, 364 | "autoload": { 365 | "classmap": [ 366 | "src/" 367 | ] 368 | }, 369 | "notification-url": "https://packagist.org/downloads/", 370 | "license": [ 371 | "BSD-3-Clause" 372 | ], 373 | "authors": [ 374 | { 375 | "name": "Sebastian Bergmann", 376 | "email": "sb@sebastian-bergmann.de", 377 | "role": "lead" 378 | } 379 | ], 380 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", 381 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage", 382 | "keywords": [ 383 | "coverage", 384 | "testing", 385 | "xunit" 386 | ], 387 | "time": "2016-04-08 08:14:53" 388 | }, 389 | { 390 | "name": "phpunit/php-file-iterator", 391 | "version": "1.4.1", 392 | "source": { 393 | "type": "git", 394 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git", 395 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" 396 | }, 397 | "dist": { 398 | "type": "zip", 399 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 400 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 401 | "shasum": "" 402 | }, 403 | "require": { 404 | "php": ">=5.3.3" 405 | }, 406 | "type": "library", 407 | "extra": { 408 | "branch-alias": { 409 | "dev-master": "1.4.x-dev" 410 | } 411 | }, 412 | "autoload": { 413 | "classmap": [ 414 | "src/" 415 | ] 416 | }, 417 | "notification-url": "https://packagist.org/downloads/", 418 | "license": [ 419 | "BSD-3-Clause" 420 | ], 421 | "authors": [ 422 | { 423 | "name": "Sebastian Bergmann", 424 | "email": "sb@sebastian-bergmann.de", 425 | "role": "lead" 426 | } 427 | ], 428 | "description": "FilterIterator implementation that filters files based on a list of suffixes.", 429 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", 430 | "keywords": [ 431 | "filesystem", 432 | "iterator" 433 | ], 434 | "time": "2015-06-21 13:08:43" 435 | }, 436 | { 437 | "name": "phpunit/php-text-template", 438 | "version": "1.2.1", 439 | "source": { 440 | "type": "git", 441 | "url": "https://github.com/sebastianbergmann/php-text-template.git", 442 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" 443 | }, 444 | "dist": { 445 | "type": "zip", 446 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 447 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 448 | "shasum": "" 449 | }, 450 | "require": { 451 | "php": ">=5.3.3" 452 | }, 453 | "type": "library", 454 | "autoload": { 455 | "classmap": [ 456 | "src/" 457 | ] 458 | }, 459 | "notification-url": "https://packagist.org/downloads/", 460 | "license": [ 461 | "BSD-3-Clause" 462 | ], 463 | "authors": [ 464 | { 465 | "name": "Sebastian Bergmann", 466 | "email": "sebastian@phpunit.de", 467 | "role": "lead" 468 | } 469 | ], 470 | "description": "Simple template engine.", 471 | "homepage": "https://github.com/sebastianbergmann/php-text-template/", 472 | "keywords": [ 473 | "template" 474 | ], 475 | "time": "2015-06-21 13:50:34" 476 | }, 477 | { 478 | "name": "phpunit/php-timer", 479 | "version": "1.0.8", 480 | "source": { 481 | "type": "git", 482 | "url": "https://github.com/sebastianbergmann/php-timer.git", 483 | "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" 484 | }, 485 | "dist": { 486 | "type": "zip", 487 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", 488 | "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", 489 | "shasum": "" 490 | }, 491 | "require": { 492 | "php": ">=5.3.3" 493 | }, 494 | "require-dev": { 495 | "phpunit/phpunit": "~4|~5" 496 | }, 497 | "type": "library", 498 | "autoload": { 499 | "classmap": [ 500 | "src/" 501 | ] 502 | }, 503 | "notification-url": "https://packagist.org/downloads/", 504 | "license": [ 505 | "BSD-3-Clause" 506 | ], 507 | "authors": [ 508 | { 509 | "name": "Sebastian Bergmann", 510 | "email": "sb@sebastian-bergmann.de", 511 | "role": "lead" 512 | } 513 | ], 514 | "description": "Utility class for timing", 515 | "homepage": "https://github.com/sebastianbergmann/php-timer/", 516 | "keywords": [ 517 | "timer" 518 | ], 519 | "time": "2016-05-12 18:03:57" 520 | }, 521 | { 522 | "name": "phpunit/php-token-stream", 523 | "version": "1.4.8", 524 | "source": { 525 | "type": "git", 526 | "url": "https://github.com/sebastianbergmann/php-token-stream.git", 527 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" 528 | }, 529 | "dist": { 530 | "type": "zip", 531 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", 532 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", 533 | "shasum": "" 534 | }, 535 | "require": { 536 | "ext-tokenizer": "*", 537 | "php": ">=5.3.3" 538 | }, 539 | "require-dev": { 540 | "phpunit/phpunit": "~4.2" 541 | }, 542 | "type": "library", 543 | "extra": { 544 | "branch-alias": { 545 | "dev-master": "1.4-dev" 546 | } 547 | }, 548 | "autoload": { 549 | "classmap": [ 550 | "src/" 551 | ] 552 | }, 553 | "notification-url": "https://packagist.org/downloads/", 554 | "license": [ 555 | "BSD-3-Clause" 556 | ], 557 | "authors": [ 558 | { 559 | "name": "Sebastian Bergmann", 560 | "email": "sebastian@phpunit.de" 561 | } 562 | ], 563 | "description": "Wrapper around PHP's tokenizer extension.", 564 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/", 565 | "keywords": [ 566 | "tokenizer" 567 | ], 568 | "time": "2015-09-15 10:49:45" 569 | }, 570 | { 571 | "name": "phpunit/phpunit", 572 | "version": "5.3.4", 573 | "source": { 574 | "type": "git", 575 | "url": "https://github.com/sebastianbergmann/phpunit.git", 576 | "reference": "00dd95ffb48805503817ced06399017df315fe5c" 577 | }, 578 | "dist": { 579 | "type": "zip", 580 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/00dd95ffb48805503817ced06399017df315fe5c", 581 | "reference": "00dd95ffb48805503817ced06399017df315fe5c", 582 | "shasum": "" 583 | }, 584 | "require": { 585 | "ext-dom": "*", 586 | "ext-json": "*", 587 | "ext-pcre": "*", 588 | "ext-reflection": "*", 589 | "ext-spl": "*", 590 | "myclabs/deep-copy": "~1.3", 591 | "php": "^5.6 || ^7.0", 592 | "phpspec/prophecy": "^1.3.1", 593 | "phpunit/php-code-coverage": "^3.3.0", 594 | "phpunit/php-file-iterator": "~1.4", 595 | "phpunit/php-text-template": "~1.2", 596 | "phpunit/php-timer": "^1.0.6", 597 | "phpunit/phpunit-mock-objects": "^3.1", 598 | "sebastian/comparator": "~1.1", 599 | "sebastian/diff": "~1.2", 600 | "sebastian/environment": "~1.3", 601 | "sebastian/exporter": "~1.2", 602 | "sebastian/global-state": "~1.0", 603 | "sebastian/object-enumerator": "~1.0", 604 | "sebastian/resource-operations": "~1.0", 605 | "sebastian/version": "~1.0|~2.0", 606 | "symfony/yaml": "~2.1|~3.0" 607 | }, 608 | "suggest": { 609 | "phpunit/php-invoker": "~1.1" 610 | }, 611 | "bin": [ 612 | "phpunit" 613 | ], 614 | "type": "library", 615 | "extra": { 616 | "branch-alias": { 617 | "dev-master": "5.3.x-dev" 618 | } 619 | }, 620 | "autoload": { 621 | "classmap": [ 622 | "src/" 623 | ] 624 | }, 625 | "notification-url": "https://packagist.org/downloads/", 626 | "license": [ 627 | "BSD-3-Clause" 628 | ], 629 | "authors": [ 630 | { 631 | "name": "Sebastian Bergmann", 632 | "email": "sebastian@phpunit.de", 633 | "role": "lead" 634 | } 635 | ], 636 | "description": "The PHP Unit Testing framework.", 637 | "homepage": "https://phpunit.de/", 638 | "keywords": [ 639 | "phpunit", 640 | "testing", 641 | "xunit" 642 | ], 643 | "time": "2016-05-11 13:28:45" 644 | }, 645 | { 646 | "name": "phpunit/phpunit-mock-objects", 647 | "version": "3.1.3", 648 | "source": { 649 | "type": "git", 650 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", 651 | "reference": "151c96874bff6fe61a25039df60e776613a61489" 652 | }, 653 | "dist": { 654 | "type": "zip", 655 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/151c96874bff6fe61a25039df60e776613a61489", 656 | "reference": "151c96874bff6fe61a25039df60e776613a61489", 657 | "shasum": "" 658 | }, 659 | "require": { 660 | "doctrine/instantiator": "^1.0.2", 661 | "php": ">=5.6", 662 | "phpunit/php-text-template": "~1.2", 663 | "sebastian/exporter": "~1.2" 664 | }, 665 | "require-dev": { 666 | "phpunit/phpunit": "~5" 667 | }, 668 | "suggest": { 669 | "ext-soap": "*" 670 | }, 671 | "type": "library", 672 | "extra": { 673 | "branch-alias": { 674 | "dev-master": "3.1.x-dev" 675 | } 676 | }, 677 | "autoload": { 678 | "classmap": [ 679 | "src/" 680 | ] 681 | }, 682 | "notification-url": "https://packagist.org/downloads/", 683 | "license": [ 684 | "BSD-3-Clause" 685 | ], 686 | "authors": [ 687 | { 688 | "name": "Sebastian Bergmann", 689 | "email": "sb@sebastian-bergmann.de", 690 | "role": "lead" 691 | } 692 | ], 693 | "description": "Mock Object library for PHPUnit", 694 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", 695 | "keywords": [ 696 | "mock", 697 | "xunit" 698 | ], 699 | "time": "2016-04-20 14:39:26" 700 | }, 701 | { 702 | "name": "sebastian/code-unit-reverse-lookup", 703 | "version": "1.0.0", 704 | "source": { 705 | "type": "git", 706 | "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", 707 | "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe" 708 | }, 709 | "dist": { 710 | "type": "zip", 711 | "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe", 712 | "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe", 713 | "shasum": "" 714 | }, 715 | "require": { 716 | "php": ">=5.6" 717 | }, 718 | "require-dev": { 719 | "phpunit/phpunit": "~5" 720 | }, 721 | "type": "library", 722 | "extra": { 723 | "branch-alias": { 724 | "dev-master": "1.0.x-dev" 725 | } 726 | }, 727 | "autoload": { 728 | "classmap": [ 729 | "src/" 730 | ] 731 | }, 732 | "notification-url": "https://packagist.org/downloads/", 733 | "license": [ 734 | "BSD-3-Clause" 735 | ], 736 | "authors": [ 737 | { 738 | "name": "Sebastian Bergmann", 739 | "email": "sebastian@phpunit.de" 740 | } 741 | ], 742 | "description": "Looks up which function or method a line of code belongs to", 743 | "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", 744 | "time": "2016-02-13 06:45:14" 745 | }, 746 | { 747 | "name": "sebastian/comparator", 748 | "version": "1.2.0", 749 | "source": { 750 | "type": "git", 751 | "url": "https://github.com/sebastianbergmann/comparator.git", 752 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" 753 | }, 754 | "dist": { 755 | "type": "zip", 756 | "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", 757 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", 758 | "shasum": "" 759 | }, 760 | "require": { 761 | "php": ">=5.3.3", 762 | "sebastian/diff": "~1.2", 763 | "sebastian/exporter": "~1.2" 764 | }, 765 | "require-dev": { 766 | "phpunit/phpunit": "~4.4" 767 | }, 768 | "type": "library", 769 | "extra": { 770 | "branch-alias": { 771 | "dev-master": "1.2.x-dev" 772 | } 773 | }, 774 | "autoload": { 775 | "classmap": [ 776 | "src/" 777 | ] 778 | }, 779 | "notification-url": "https://packagist.org/downloads/", 780 | "license": [ 781 | "BSD-3-Clause" 782 | ], 783 | "authors": [ 784 | { 785 | "name": "Jeff Welch", 786 | "email": "whatthejeff@gmail.com" 787 | }, 788 | { 789 | "name": "Volker Dusch", 790 | "email": "github@wallbash.com" 791 | }, 792 | { 793 | "name": "Bernhard Schussek", 794 | "email": "bschussek@2bepublished.at" 795 | }, 796 | { 797 | "name": "Sebastian Bergmann", 798 | "email": "sebastian@phpunit.de" 799 | } 800 | ], 801 | "description": "Provides the functionality to compare PHP values for equality", 802 | "homepage": "http://www.github.com/sebastianbergmann/comparator", 803 | "keywords": [ 804 | "comparator", 805 | "compare", 806 | "equality" 807 | ], 808 | "time": "2015-07-26 15:48:44" 809 | }, 810 | { 811 | "name": "sebastian/diff", 812 | "version": "1.4.1", 813 | "source": { 814 | "type": "git", 815 | "url": "https://github.com/sebastianbergmann/diff.git", 816 | "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" 817 | }, 818 | "dist": { 819 | "type": "zip", 820 | "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", 821 | "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", 822 | "shasum": "" 823 | }, 824 | "require": { 825 | "php": ">=5.3.3" 826 | }, 827 | "require-dev": { 828 | "phpunit/phpunit": "~4.8" 829 | }, 830 | "type": "library", 831 | "extra": { 832 | "branch-alias": { 833 | "dev-master": "1.4-dev" 834 | } 835 | }, 836 | "autoload": { 837 | "classmap": [ 838 | "src/" 839 | ] 840 | }, 841 | "notification-url": "https://packagist.org/downloads/", 842 | "license": [ 843 | "BSD-3-Clause" 844 | ], 845 | "authors": [ 846 | { 847 | "name": "Kore Nordmann", 848 | "email": "mail@kore-nordmann.de" 849 | }, 850 | { 851 | "name": "Sebastian Bergmann", 852 | "email": "sebastian@phpunit.de" 853 | } 854 | ], 855 | "description": "Diff implementation", 856 | "homepage": "https://github.com/sebastianbergmann/diff", 857 | "keywords": [ 858 | "diff" 859 | ], 860 | "time": "2015-12-08 07:14:41" 861 | }, 862 | { 863 | "name": "sebastian/environment", 864 | "version": "1.3.7", 865 | "source": { 866 | "type": "git", 867 | "url": "https://github.com/sebastianbergmann/environment.git", 868 | "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716" 869 | }, 870 | "dist": { 871 | "type": "zip", 872 | "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716", 873 | "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716", 874 | "shasum": "" 875 | }, 876 | "require": { 877 | "php": ">=5.3.3" 878 | }, 879 | "require-dev": { 880 | "phpunit/phpunit": "~4.4" 881 | }, 882 | "type": "library", 883 | "extra": { 884 | "branch-alias": { 885 | "dev-master": "1.3.x-dev" 886 | } 887 | }, 888 | "autoload": { 889 | "classmap": [ 890 | "src/" 891 | ] 892 | }, 893 | "notification-url": "https://packagist.org/downloads/", 894 | "license": [ 895 | "BSD-3-Clause" 896 | ], 897 | "authors": [ 898 | { 899 | "name": "Sebastian Bergmann", 900 | "email": "sebastian@phpunit.de" 901 | } 902 | ], 903 | "description": "Provides functionality to handle HHVM/PHP environments", 904 | "homepage": "http://www.github.com/sebastianbergmann/environment", 905 | "keywords": [ 906 | "Xdebug", 907 | "environment", 908 | "hhvm" 909 | ], 910 | "time": "2016-05-17 03:18:57" 911 | }, 912 | { 913 | "name": "sebastian/exporter", 914 | "version": "1.2.1", 915 | "source": { 916 | "type": "git", 917 | "url": "https://github.com/sebastianbergmann/exporter.git", 918 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e" 919 | }, 920 | "dist": { 921 | "type": "zip", 922 | "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", 923 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e", 924 | "shasum": "" 925 | }, 926 | "require": { 927 | "php": ">=5.3.3", 928 | "sebastian/recursion-context": "~1.0" 929 | }, 930 | "require-dev": { 931 | "phpunit/phpunit": "~4.4" 932 | }, 933 | "type": "library", 934 | "extra": { 935 | "branch-alias": { 936 | "dev-master": "1.2.x-dev" 937 | } 938 | }, 939 | "autoload": { 940 | "classmap": [ 941 | "src/" 942 | ] 943 | }, 944 | "notification-url": "https://packagist.org/downloads/", 945 | "license": [ 946 | "BSD-3-Clause" 947 | ], 948 | "authors": [ 949 | { 950 | "name": "Jeff Welch", 951 | "email": "whatthejeff@gmail.com" 952 | }, 953 | { 954 | "name": "Volker Dusch", 955 | "email": "github@wallbash.com" 956 | }, 957 | { 958 | "name": "Bernhard Schussek", 959 | "email": "bschussek@2bepublished.at" 960 | }, 961 | { 962 | "name": "Sebastian Bergmann", 963 | "email": "sebastian@phpunit.de" 964 | }, 965 | { 966 | "name": "Adam Harvey", 967 | "email": "aharvey@php.net" 968 | } 969 | ], 970 | "description": "Provides the functionality to export PHP variables for visualization", 971 | "homepage": "http://www.github.com/sebastianbergmann/exporter", 972 | "keywords": [ 973 | "export", 974 | "exporter" 975 | ], 976 | "time": "2015-06-21 07:55:53" 977 | }, 978 | { 979 | "name": "sebastian/global-state", 980 | "version": "1.1.1", 981 | "source": { 982 | "type": "git", 983 | "url": "https://github.com/sebastianbergmann/global-state.git", 984 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" 985 | }, 986 | "dist": { 987 | "type": "zip", 988 | "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", 989 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", 990 | "shasum": "" 991 | }, 992 | "require": { 993 | "php": ">=5.3.3" 994 | }, 995 | "require-dev": { 996 | "phpunit/phpunit": "~4.2" 997 | }, 998 | "suggest": { 999 | "ext-uopz": "*" 1000 | }, 1001 | "type": "library", 1002 | "extra": { 1003 | "branch-alias": { 1004 | "dev-master": "1.0-dev" 1005 | } 1006 | }, 1007 | "autoload": { 1008 | "classmap": [ 1009 | "src/" 1010 | ] 1011 | }, 1012 | "notification-url": "https://packagist.org/downloads/", 1013 | "license": [ 1014 | "BSD-3-Clause" 1015 | ], 1016 | "authors": [ 1017 | { 1018 | "name": "Sebastian Bergmann", 1019 | "email": "sebastian@phpunit.de" 1020 | } 1021 | ], 1022 | "description": "Snapshotting of global state", 1023 | "homepage": "http://www.github.com/sebastianbergmann/global-state", 1024 | "keywords": [ 1025 | "global state" 1026 | ], 1027 | "time": "2015-10-12 03:26:01" 1028 | }, 1029 | { 1030 | "name": "sebastian/object-enumerator", 1031 | "version": "1.0.0", 1032 | "source": { 1033 | "type": "git", 1034 | "url": "https://github.com/sebastianbergmann/object-enumerator.git", 1035 | "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" 1036 | }, 1037 | "dist": { 1038 | "type": "zip", 1039 | "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", 1040 | "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", 1041 | "shasum": "" 1042 | }, 1043 | "require": { 1044 | "php": ">=5.6", 1045 | "sebastian/recursion-context": "~1.0" 1046 | }, 1047 | "require-dev": { 1048 | "phpunit/phpunit": "~5" 1049 | }, 1050 | "type": "library", 1051 | "extra": { 1052 | "branch-alias": { 1053 | "dev-master": "1.0.x-dev" 1054 | } 1055 | }, 1056 | "autoload": { 1057 | "classmap": [ 1058 | "src/" 1059 | ] 1060 | }, 1061 | "notification-url": "https://packagist.org/downloads/", 1062 | "license": [ 1063 | "BSD-3-Clause" 1064 | ], 1065 | "authors": [ 1066 | { 1067 | "name": "Sebastian Bergmann", 1068 | "email": "sebastian@phpunit.de" 1069 | } 1070 | ], 1071 | "description": "Traverses array structures and object graphs to enumerate all referenced objects", 1072 | "homepage": "https://github.com/sebastianbergmann/object-enumerator/", 1073 | "time": "2016-01-28 13:25:10" 1074 | }, 1075 | { 1076 | "name": "sebastian/recursion-context", 1077 | "version": "1.0.2", 1078 | "source": { 1079 | "type": "git", 1080 | "url": "https://github.com/sebastianbergmann/recursion-context.git", 1081 | "reference": "913401df809e99e4f47b27cdd781f4a258d58791" 1082 | }, 1083 | "dist": { 1084 | "type": "zip", 1085 | "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", 1086 | "reference": "913401df809e99e4f47b27cdd781f4a258d58791", 1087 | "shasum": "" 1088 | }, 1089 | "require": { 1090 | "php": ">=5.3.3" 1091 | }, 1092 | "require-dev": { 1093 | "phpunit/phpunit": "~4.4" 1094 | }, 1095 | "type": "library", 1096 | "extra": { 1097 | "branch-alias": { 1098 | "dev-master": "1.0.x-dev" 1099 | } 1100 | }, 1101 | "autoload": { 1102 | "classmap": [ 1103 | "src/" 1104 | ] 1105 | }, 1106 | "notification-url": "https://packagist.org/downloads/", 1107 | "license": [ 1108 | "BSD-3-Clause" 1109 | ], 1110 | "authors": [ 1111 | { 1112 | "name": "Jeff Welch", 1113 | "email": "whatthejeff@gmail.com" 1114 | }, 1115 | { 1116 | "name": "Sebastian Bergmann", 1117 | "email": "sebastian@phpunit.de" 1118 | }, 1119 | { 1120 | "name": "Adam Harvey", 1121 | "email": "aharvey@php.net" 1122 | } 1123 | ], 1124 | "description": "Provides functionality to recursively process PHP variables", 1125 | "homepage": "http://www.github.com/sebastianbergmann/recursion-context", 1126 | "time": "2015-11-11 19:50:13" 1127 | }, 1128 | { 1129 | "name": "sebastian/resource-operations", 1130 | "version": "1.0.0", 1131 | "source": { 1132 | "type": "git", 1133 | "url": "https://github.com/sebastianbergmann/resource-operations.git", 1134 | "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" 1135 | }, 1136 | "dist": { 1137 | "type": "zip", 1138 | "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", 1139 | "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", 1140 | "shasum": "" 1141 | }, 1142 | "require": { 1143 | "php": ">=5.6.0" 1144 | }, 1145 | "type": "library", 1146 | "extra": { 1147 | "branch-alias": { 1148 | "dev-master": "1.0.x-dev" 1149 | } 1150 | }, 1151 | "autoload": { 1152 | "classmap": [ 1153 | "src/" 1154 | ] 1155 | }, 1156 | "notification-url": "https://packagist.org/downloads/", 1157 | "license": [ 1158 | "BSD-3-Clause" 1159 | ], 1160 | "authors": [ 1161 | { 1162 | "name": "Sebastian Bergmann", 1163 | "email": "sebastian@phpunit.de" 1164 | } 1165 | ], 1166 | "description": "Provides a list of PHP built-in functions that operate on resources", 1167 | "homepage": "https://www.github.com/sebastianbergmann/resource-operations", 1168 | "time": "2015-07-28 20:34:47" 1169 | }, 1170 | { 1171 | "name": "sebastian/version", 1172 | "version": "2.0.0", 1173 | "source": { 1174 | "type": "git", 1175 | "url": "https://github.com/sebastianbergmann/version.git", 1176 | "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5" 1177 | }, 1178 | "dist": { 1179 | "type": "zip", 1180 | "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", 1181 | "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", 1182 | "shasum": "" 1183 | }, 1184 | "require": { 1185 | "php": ">=5.6" 1186 | }, 1187 | "type": "library", 1188 | "extra": { 1189 | "branch-alias": { 1190 | "dev-master": "2.0.x-dev" 1191 | } 1192 | }, 1193 | "autoload": { 1194 | "classmap": [ 1195 | "src/" 1196 | ] 1197 | }, 1198 | "notification-url": "https://packagist.org/downloads/", 1199 | "license": [ 1200 | "BSD-3-Clause" 1201 | ], 1202 | "authors": [ 1203 | { 1204 | "name": "Sebastian Bergmann", 1205 | "email": "sebastian@phpunit.de", 1206 | "role": "lead" 1207 | } 1208 | ], 1209 | "description": "Library that helps with managing the version number of Git-hosted PHP projects", 1210 | "homepage": "https://github.com/sebastianbergmann/version", 1211 | "time": "2016-02-04 12:56:52" 1212 | }, 1213 | { 1214 | "name": "symfony/yaml", 1215 | "version": "v3.0.6", 1216 | "source": { 1217 | "type": "git", 1218 | "url": "https://github.com/symfony/yaml.git", 1219 | "reference": "0047c8366744a16de7516622c5b7355336afae96" 1220 | }, 1221 | "dist": { 1222 | "type": "zip", 1223 | "url": "https://api.github.com/repos/symfony/yaml/zipball/0047c8366744a16de7516622c5b7355336afae96", 1224 | "reference": "0047c8366744a16de7516622c5b7355336afae96", 1225 | "shasum": "" 1226 | }, 1227 | "require": { 1228 | "php": ">=5.5.9" 1229 | }, 1230 | "type": "library", 1231 | "extra": { 1232 | "branch-alias": { 1233 | "dev-master": "3.0-dev" 1234 | } 1235 | }, 1236 | "autoload": { 1237 | "psr-4": { 1238 | "Symfony\\Component\\Yaml\\": "" 1239 | }, 1240 | "exclude-from-classmap": [ 1241 | "/Tests/" 1242 | ] 1243 | }, 1244 | "notification-url": "https://packagist.org/downloads/", 1245 | "license": [ 1246 | "MIT" 1247 | ], 1248 | "authors": [ 1249 | { 1250 | "name": "Fabien Potencier", 1251 | "email": "fabien@symfony.com" 1252 | }, 1253 | { 1254 | "name": "Symfony Community", 1255 | "homepage": "https://symfony.com/contributors" 1256 | } 1257 | ], 1258 | "description": "Symfony Yaml Component", 1259 | "homepage": "https://symfony.com", 1260 | "time": "2016-03-04 07:55:57" 1261 | } 1262 | ], 1263 | "aliases": [], 1264 | "minimum-stability": "stable", 1265 | "stability-flags": [], 1266 | "prefer-stable": false, 1267 | "prefer-lowest": false, 1268 | "platform": { 1269 | "php": "^7" 1270 | }, 1271 | "platform-dev": [] 1272 | } 1273 | -------------------------------------------------------------------------------- /examples/basic_server.php: -------------------------------------------------------------------------------- 1 | append(new Tari\ServerMiddleware\ErrorHandler(true)); 10 | 11 | // Append GZIP encoding 12 | $server->append(new Tari\ServerMiddleware\GZip); 13 | 14 | // We append as early as possible a HSTS redirection 15 | $server->append(new Tari\ServerMiddleware\HSTS(300)); 16 | 17 | // And we append a header adding in a callback 18 | $server->append(function($request, $frame) { 19 | $response = $frame->next($request); 20 | return $response->withHeader("X-Powered-By", "Tari"); 21 | }); 22 | 23 | 24 | // Here's the test and debugging output 25 | $request = new GuzzleHttp\Psr7\ServerRequest('GET', 'http://example.com', []); 26 | 27 | $response = $server->run($request, function($request) { 28 | return new GuzzleHttp\Psr7\Response(200, [], "Found"); 29 | }); 30 | 31 | echo "Status: " . $response->getStatusCode() . "\n"; 32 | echo "Headers: \n"; 33 | foreach ($response->getHeaders() as $name => $header) { 34 | echo "\t$name: " . implode(", ", $header) . "\n"; 35 | } 36 | echo "Body: \n"; 37 | echo $response->getBody(); 38 | echo "\n"; 39 | -------------------------------------------------------------------------------- /lib/Adapter/Guzzle/Factory.php: -------------------------------------------------------------------------------- 1 | factory = $factory; 15 | array_map([$this, 'append'], $middleware); 16 | } 17 | 18 | /** 19 | * Append a middleware onto the stack 20 | * 21 | * @param MiddlewareInterface|callable(RequestInterface,FrameInterface):ResponseInterface 22 | * 23 | * @return void 24 | */ 25 | public function append($middleware) { 26 | $this->stack[] = $this->normalize($middleware); 27 | } 28 | 29 | /** 30 | * Append a middleware onto the stack 31 | * 32 | * @param MiddlewareInterface|callable(RequestInterface,FrameInterface):ResponseInterface The Middleware 33 | * 34 | * @return void 35 | */ 36 | public function prepend($middleware) { 37 | array_unshift($this->stack, $this->normalize($middleware)); 38 | } 39 | 40 | private function normalize($middleware): ServerMiddlewareInterface { 41 | if ($middleware instanceof ServerMiddlewareInterface) { 42 | return $middleware; 43 | } elseif (is_callable($middleware)) { 44 | return new ServerMiddleware\CallableServerMiddleware($middleware); 45 | } 46 | throw new \InvalidArgumentException("Invalid Middleware Detected"); 47 | } 48 | 49 | public function run(ServerRequestInterface $request, callable $default): ResponseInterface { 50 | return (new class($this->stack, $this->factory, $default) implements ServerFrameInterface { 51 | private $stack; 52 | private $index = 0; 53 | private $factory; 54 | private $default; 55 | public function __construct(array $stack, FactoryInterface $factory, callable $default) { 56 | $this->stack = $stack; 57 | $this->factory = $factory; 58 | $this->default = $default; 59 | } 60 | public function next(ServerRequestInterface $request): ResponseInterface { 61 | if (!isset($this->stack[$this->index])) { 62 | return ($this->default)($request); 63 | } 64 | return $this->stack[$this->index]->handle($request, $this->nextFrame()); 65 | } 66 | public function factory(): FactoryInterface { 67 | return $this->factory; 68 | } 69 | 70 | private function nextFrame() { 71 | $new = clone $this; 72 | $new->index++; 73 | return $new; 74 | } 75 | })->next($request); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/ServerMiddleware/CallableServerMiddleware.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 16 | } 17 | 18 | public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface { 19 | return ($this->callback)($request, $frame); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/ServerMiddleware/ErrorHandler.php: -------------------------------------------------------------------------------- 1 | debug = $debug; 17 | } 18 | 19 | public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface { 20 | try { 21 | return $frame->next($request); 22 | } catch (\Throwable $exception) { 23 | return $frame->factory()->createResponse(500, [], $this->debug ? $exception : "Internal Server Error"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/ServerMiddleware/GZip.php: -------------------------------------------------------------------------------- 1 | next($request); 15 | if ($response->hasHeader("Content-Encoding") || !$this->isAcceptableServerRequest($request)) { 16 | // Do not double-encode 17 | return $response; 18 | } 19 | $response = $response->withHeader('Content-Encoding', 'gzip'); 20 | $stream = $response->getBody(); 21 | return $response->withBody($frame->factory()->createStream(gzcompress($stream))); 22 | } 23 | 24 | private function isAcceptableServerRequest(ServerRequestInterface $request): bool { 25 | if (!$request->hasHeader("Accept-encoding")) { 26 | return false; 27 | } 28 | $accept = $request->getHeaderLine("Accept-encoding"); 29 | if (strpos($accept, '*') !== false) { 30 | return true; 31 | } 32 | if (strpos($accept, 'gzip') !== false) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/ServerMiddleware/HSTS.php: -------------------------------------------------------------------------------- 1 | maxAge = $maxAge; 18 | $this->includeSubdomains = $includeSubdomains; 19 | } 20 | 21 | public function handle(ServerRequestInterface $request, ServerFrameInterface $frame): ResponseInterface { 22 | $uri = $request->getUri(); 23 | if (strtolower($uri->getScheme()) !== 'https') { 24 | return $frame->factory()->createResponse( 25 | 301, 26 | [ 27 | "Location" => $uri->withScheme('https'), 28 | ] 29 | ); 30 | } 31 | $response = $frame->next($request); 32 | $suffix = $this->includeSubdomains ? ';includeSubDomains' : ''; 33 | return $response->withHeader("Strict-Transport-Security", "max-age=" . $this->maxAge . $suffix); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spec/FactoryInterface.php: -------------------------------------------------------------------------------- 1 |