From 94b381a6ba86e741a1090b33e05a58d8c814bc1c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 22 Aug 2019 05:27:55 +0000 Subject: [PATCH 1/4] Bump phpgt/database from 1.0.0 to 1.0.2 Bumps [phpgt/database](https://github.com/PhpGt/Database) from 1.0.0 to 1.0.2. - [Release notes](https://github.com/PhpGt/Database/releases) - [Commits](https://github.com/PhpGt/Database/compare/v1.0.0...v1.0.2) Signed-off-by: dependabot-preview[bot] --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index ef0946f0..5ff7327f 100644 --- a/composer.lock +++ b/composer.lock @@ -648,16 +648,16 @@ }, { "name": "phpgt/database", - "version": "v1.0.0", + "version": "v1.0.2", "source": { "type": "git", "url": "https://github.com/PhpGt/Database.git", - "reference": "dc702c85f3153364378da84d73f3b613c9d27a9a" + "reference": "c23b8902627328c5847c37b636c6774fbda0540e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/Database/zipball/dc702c85f3153364378da84d73f3b613c9d27a9a", - "reference": "dc702c85f3153364378da84d73f3b613c9d27a9a", + "url": "https://api.github.com/repos/PhpGt/Database/zipball/c23b8902627328c5847c37b636c6774fbda0540e", + "reference": "c23b8902627328c5847c37b636c6774fbda0540e", "shasum": "" }, "require": { @@ -697,7 +697,7 @@ } ], "description": "Database API organisation.", - "time": "2019-02-08T12:23:01+00:00" + "time": "2019-08-21T21:40:07+00:00" }, { "name": "phpgt/dom", From a6cfe388217077672d319ee8e6c30610cb247216 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2019 05:17:47 +0000 Subject: [PATCH 2/4] Bump phpgt/domtemplate from 1.1.1 to 1.2.2 Bumps [phpgt/domtemplate](https://github.com/PhpGt/DomTemplate) from 1.1.1 to 1.2.2. - [Release notes](https://github.com/PhpGt/DomTemplate/releases) - [Commits](https://github.com/PhpGt/DomTemplate/compare/v1.1.1...v1.2.2) Signed-off-by: dependabot-preview[bot] --- composer.lock | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/composer.lock b/composer.lock index ef0946f0..8930d008 100644 --- a/composer.lock +++ b/composer.lock @@ -782,16 +782,16 @@ }, { "name": "phpgt/domtemplate", - "version": "v1.1.1", + "version": "v1.2.2", "source": { "type": "git", "url": "https://github.com/PhpGt/DomTemplate.git", - "reference": "16ae8a7651d3839d287eb3302dcd5c472e0c1f10" + "reference": "3468817bd99f013ad2d786fc8c177f4c00a8829d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/DomTemplate/zipball/16ae8a7651d3839d287eb3302dcd5c472e0c1f10", - "reference": "16ae8a7651d3839d287eb3302dcd5c472e0c1f10", + "url": "https://api.github.com/repos/PhpGt/DomTemplate/zipball/3468817bd99f013ad2d786fc8c177f4c00a8829d", + "reference": "3468817bd99f013ad2d786fc8c177f4c00a8829d", "shasum": "" }, "require": { @@ -799,6 +799,7 @@ "phpgt/dom": "*" }, "require-dev": { + "ext-intl": "*", "phpunit/phpunit": "8.*" }, "type": "library", @@ -812,7 +813,7 @@ "MIT" ], "description": "Bind dynamic data to reusable HTML components.", - "time": "2019-07-31T15:35:29+00:00" + "time": "2019-09-02T07:25:58+00:00" }, { "name": "phpgt/fetch", @@ -2510,18 +2511,18 @@ "authors": [ { "name": "Arne Blankerts", - "role": "Developer", - "email": "arne@blankerts.de" + "email": "arne@blankerts.de", + "role": "Developer" }, { "name": "Sebastian Heuer", - "role": "Developer", - "email": "sebastian@phpeople.de" + "email": "sebastian@phpeople.de", + "role": "Developer" }, { "name": "Sebastian Bergmann", - "role": "Developer", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "Developer" } ], "description": "Library for handling version information and constraints", @@ -2792,8 +2793,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", @@ -2843,8 +2844,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "FilterIterator implementation that filters files based on a list of suffixes.", @@ -2885,8 +2886,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "Simple template engine.", @@ -2934,8 +2935,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "Utility class for timing", @@ -3064,8 +3065,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "The PHP Unit Testing framework.", @@ -3730,8 +3731,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "Collection of value objects that represent the types of the PHP type system", @@ -3773,8 +3774,8 @@ "authors": [ { "name": "Sebastian Bergmann", - "role": "lead", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", From 945461f22dd78439eb321fd85acad1d88277a11e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2019 08:35:08 +0000 Subject: [PATCH 3/4] Bump phpunit/phpunit from 8.2.5 to 8.3.4 Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 8.2.5 to 8.3.4. - [Release notes](https://github.com/sebastianbergmann/phpunit/releases) - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-8.3.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/8.2.5...8.3.4) Signed-off-by: dependabot-preview[bot] --- composer.lock | 83 +++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/composer.lock b/composer.lock index 8930d008..62a8e823 100644 --- a/composer.lock +++ b/composer.lock @@ -1386,16 +1386,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -1407,7 +1407,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -1423,13 +1423,13 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -1440,20 +1440,20 @@ "polyfill", "portable" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", "shasum": "" }, "require": { @@ -1461,8 +1461,7 @@ "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "extra": { @@ -1491,7 +1490,7 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2019-08-24T08:43:50+00:00" }, { "name": "webmozart/glob", @@ -2380,16 +2379,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.9.1", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72" + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", "shasum": "" }, "require": { @@ -2424,7 +2423,7 @@ "object", "object graph" ], - "time": "2019-04-07T13:18:21+00:00" + "time": "2019-08-09T12:45:53+00:00" }, { "name": "phar-io/manifest", @@ -2997,16 +2996,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.2.5", + "version": "8.3.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c1b8534b3730f20f58600124129197bf1183dc92" + "reference": "e31cce0cf4499c0ccdbbb211a3280d36ab341e36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c1b8534b3730f20f58600124129197bf1183dc92", - "reference": "c1b8534b3730f20f58600124129197bf1183dc92", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e31cce0cf4499c0ccdbbb211a3280d36ab341e36", + "reference": "e31cce0cf4499c0ccdbbb211a3280d36ab341e36", "shasum": "" }, "require": { @@ -3022,7 +3021,7 @@ "phar-io/version": "^2.0.1", "php": "^7.2", "phpspec/prophecy": "^1.8.1", - "phpunit/php-code-coverage": "^7.0.5", + "phpunit/php-code-coverage": "^7.0.7", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.1.2", @@ -3050,7 +3049,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.2-dev" + "dev-master": "8.3-dev" } }, "autoload": { @@ -3076,7 +3075,7 @@ "testing", "xunit" ], - "time": "2019-07-15T06:26:24+00:00" + "time": "2019-08-11T06:56:55+00:00" }, { "name": "psr/container", @@ -3387,16 +3386,16 @@ }, { "name": "sebastian/exporter", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + "reference": "06a9a5947f47b3029d76118eb5c22802e5869687" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/06a9a5947f47b3029d76118eb5c22802e5869687", + "reference": "06a9a5947f47b3029d76118eb5c22802e5869687", "shasum": "" }, "require": { @@ -3423,6 +3422,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -3431,17 +3434,13 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, { "name": "Adam Harvey", "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -3450,7 +3449,7 @@ "export", "exporter" ], - "time": "2017-04-03T13:19:02+00:00" + "time": "2019-08-11T12:43:14+00:00" }, { "name": "sebastian/global-state", From 80318456ac901dd30c2bd30799c409503575f513 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Fri, 6 Sep 2019 18:26:47 +0100 Subject: [PATCH 4/4] Process API requests and pass back correct content-type header --- composer.json | 1 + src/Dispatch/Dispatcher.php | 6 +++++ src/Lifecycle.php | 7 ++++++ src/Refactor/ObjectDocument.php | 41 ++++++++++++++++++++++++++++----- src/Route/Router.php | 13 ++++++++++- src/Route/RouterFactory.php | 18 ++++++++++----- 6 files changed, 73 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 435d53d5..771f2259 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "require": { "ext-posix": "*", "ext-dom": "*", + "ext-json": "*", "php": ">=7.2", "phpgt/build": "*", "phpgt/cli": "*", diff --git a/src/Dispatch/Dispatcher.php b/src/Dispatch/Dispatcher.php index 65b5aae1..c4933208 100644 --- a/src/Dispatch/Dispatcher.php +++ b/src/Dispatch/Dispatcher.php @@ -36,6 +36,8 @@ abstract class Dispatcher implements RequestHandlerInterface { protected $appNamespace; /** @var TokenStore */ protected $csrfProtection; + /** @var string */ + protected $contentType; /** @var bool True if the current execution of `handle` is an error */ protected $errorHandlingFlag; /** @var LogicPropertyStore|null */ @@ -136,6 +138,10 @@ public function handle(ServerRequestInterface $request):ResponseInterface { } $view->stream(); + $response = $response->withHeader( + "Content-type", + $this->router->getContentType() + ); return $response; } diff --git a/src/Lifecycle.php b/src/Lifecycle.php index a3dc8a15..b7c150ba 100644 --- a/src/Lifecycle.php +++ b/src/Lifecycle.php @@ -120,6 +120,10 @@ public function start():void { ); $response = $this->process($request, $dispatcher); + $response = $response->withHeader( + "Content-type", + $router->getContentType() + ); $this->finish($response); } @@ -223,6 +227,9 @@ public function process( * finally output to the client, followed by any tidy-up code required. */ public static function finish(ResponseInterface $response):void { + foreach($response->getHeaders() as $key => $value) { + header("$key: $value"); + } echo $response->getBody(); } } diff --git a/src/Refactor/ObjectDocument.php b/src/Refactor/ObjectDocument.php index c8a50b6a..fb8168d1 100644 --- a/src/Refactor/ObjectDocument.php +++ b/src/Refactor/ObjectDocument.php @@ -11,11 +11,10 @@ class ObjectDocument extends Document { protected $type; - public function __construct(string $document = "", string $type) { + public function __construct(string $document, string $type) { parent::__construct(); $this->type = $type; - if($this->isJsonString($document)) { $this->loadJSON($document); } @@ -28,7 +27,7 @@ public function __construct(string $document = "", string $type) { } public function isJsonString(string $document):bool { - return $this->isFirstNonWhiteSpaceCharacter($document, "{"); + return $this->isFirstNonWhiteSpaceCharacter($document, "{["); } public function isXmlString(string $document):bool { @@ -37,15 +36,23 @@ public function isXmlString(string $document):bool { protected function isFirstNonWhiteSpaceCharacter( string $document, - string $firstChar + string $firstCharMatch ):bool { $i = 0; do { $char = $document[$i]; + $i++; }while(trim($char) === ""); - return $char === $firstChar; + for($i = 0; $i < strlen($firstCharMatch); $i++) { + $charMatch = $firstCharMatch[$i]; + if($char === $charMatch) { + return true; + } + } + + return false; } /** @@ -56,7 +63,10 @@ public function loadJSON(string $jsonString):void { $json = json_decode($jsonString); foreach($json as $key => $value) { - $node = $this->createElement($key, $value); + $valueType = gettype($value); + $stringValue = $this->getStringValue($valueType, $value); + + $node = $this->createElement($key, $stringValue); $this->appendChild($node); } } @@ -83,4 +93,23 @@ protected function saveJSON():string { return json_encode($json); } + + protected function getStringValue($type, $value):string { + switch($type) { + case "bool": + case "boolean": + return $value ? "true" : "false"; + + case "object": + // TODO: Recursively load. + return "(object)"; + + case "int": + case "integer": + case "float": + case "double": + default: + return (string)$value; + } + } } \ No newline at end of file diff --git a/src/Route/Router.php b/src/Route/Router.php index 65e2aaa3..0ba60fba 100644 --- a/src/Route/Router.php +++ b/src/Route/Router.php @@ -18,15 +18,22 @@ abstract class Router { /** @var string */ protected $documentRoot; /** @var string */ + protected $contentType; + /** @var string */ protected $baseViewLogicPath; /** @var string */ protected $viewLogicPath; /** @var string|null */ protected $viewLogicBasename; - public function __construct(RequestInterface $request, string $documentRoot) { + public function __construct( + RequestInterface $request, + string $documentRoot, + string $contentType + ) { $this->request = $request; $this->documentRoot = $documentRoot; + $this->contentType = $contentType; $uri = $request->getUri(); $this->baseViewLogicPath = $this->getBaseViewLogicPath(); @@ -101,6 +108,10 @@ public function getLogicAssembly():Assembly { ); } + public function getContentType():string { + return $this->contentType; + } + /** * The view-logic sub-path is the path on disk to the directory * containing the requested View and Logic files, diff --git a/src/Route/RouterFactory.php b/src/Route/RouterFactory.php index dc31119c..279f453f 100644 --- a/src/Route/RouterFactory.php +++ b/src/Route/RouterFactory.php @@ -25,22 +25,24 @@ public static function create( RequestInterface $request, string $documentRoot ):Router { - $type = self::getBestType($request->getHeaderLine("accept")); + $type = self::getType($request->getHeaderLine("accept")); + $routerClass = self::getRouterClassForType($type); /** @var Router $router */ - $router = new $type( + $router = new $routerClass( $request, - $documentRoot + $documentRoot, + $type ); return $router; } - protected static function getBestType(string $accept = null):string { + protected static function getType(string $accept = null):string { if(empty($accept)) { $accept = "text/html"; } - + $negotiator = new Negotiator(); /** @var Accept $acceptHeader */ $acceptHeader = $negotiator->getBest( @@ -52,8 +54,12 @@ protected static function getBestType(string $accept = null):string { $type = self::TYPE_DEFAULT; } + return $type; + } + + protected static function getRouterClassForType(string $type):string { if(!array_key_exists($type, self::TYPE_MAP)) { - throw new RoutingException("Accept header has no route: $accept"); + throw new RoutingException("Accept header has no route: $type"); } return self::TYPE_MAP[$type];