From 64ba9872020466f335ce631b1397f0030e7ef44d Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 11:55:28 -0800 Subject: [PATCH 01/16] Correct setting of server vars to recognize cli environment variables. --- Bridges/DrupalKernel.php | 289 ++++++++++++++++++++------------------- 1 file changed, 152 insertions(+), 137 deletions(-) diff --git a/Bridges/DrupalKernel.php b/Bridges/DrupalKernel.php index a690123..d401dfe 100644 --- a/Bridges/DrupalKernel.php +++ b/Bridges/DrupalKernel.php @@ -1,155 +1,170 @@ application) { - return; - } - - $content = ''; - $headers = $request->getHeaders(); - $contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0; - - $request->on('data', function($data) - use ($request, $response, &$content, $contentLength) - { - // read data (may be empty for GET request) - $content .= $data; - - // handle request after receive - if (strlen($content) >= $contentLength) { - $syRequest = self::mapRequest($request, $content); - - try { - $syResponse = $this->application->handle($syRequest); - } catch (\Exception $exception) { - $response->writeHead(500); // internal server error - $response->end(); - return; - } - - self::mapResponse($response, $syResponse); - - if ($this->application instanceof TerminableInterface) { - $this->application->terminate($syRequest, $syResponse); - } - } - }); - } - - /** - * Convert React\Http\Request to Symfony\Component\HttpFoundation\Request - * - * @param ReactRequest $reactRequest - * @return SymfonyRequest $syRequest - */ - protected static function mapRequest(ReactRequest $reactRequest, $content) - { - $method = $reactRequest->getMethod(); - $headers = $reactRequest->getHeaders(); - $query = $reactRequest->getQuery(); - $post = array(); - - // parse body? - if (isset($headers['Content-Type']) && (0 === strpos($headers['Content-Type'], 'application/x-www-form-urlencoded')) - && in_array(strtoupper($method), array('POST', 'PUT', 'DELETE', 'PATCH')) - ) { - parse_str($content, $post); - } - - $cookies = array(); - if (isset($headers['Cookie'])) { - $headersCookie = explode(';', $headers['Cookie']); - foreach ($headersCookie as $cookie) { - list($name, $value) = explode('=', trim($cookie)); - $cookies[$name] = $value; +/** + * PHP-PM bridge adapter for DrupalKernel. + * + * Extends `\PHPPM\Bridges\HttpKernel` to populate various request + * meta-variables specified by CGI/1.1 (RFC 3875). + * + * @see http://www.faqs.org/rfcs/rfc3875.html + * @see http://php.net/manual/en/reserved.variables.server.php + */ +class DrupalKernel extends SymfonyBridge implements BridgeInterface { + + /** + * Handle a request using a HttpKernelInterface implementing application. + * + * @param \React\Http\Request $request + * @param \React\Http\Response $response + */ + public function onRequest(ReactRequest $request, ReactResponse $response) + { + if (null === $this->application) { + return; + } + + $content = ''; + $headers = $request->getHeaders(); + $contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0; + + $request->on('data', function($data) + use ($request, $response, &$content, $contentLength) + { + // read data (may be empty for GET request) + $content .= $data; + + // handle request after receive + if (strlen($content) >= $contentLength) { + $syRequest = self::mapRequest($request, $content); + + try { + $syResponse = $this->application->handle($syRequest); + } catch (\Exception $exception) { + $response->writeHead(500); // internal server error + $response->end(); + return; + } + + self::mapResponse($response, $syResponse); + + if ($this->application instanceof TerminableInterface) { + $this->application->terminate($syRequest, $syResponse); + } } + }); + } + + /** + * Convert React\Http\Request to Symfony\Component\HttpFoundation\Request + * + * @param ReactRequest $reactRequest + * @return SymfonyRequest $syRequest + */ + protected static function mapRequest(ReactRequest $reactRequest, $content) + { + $method = $reactRequest->getMethod(); + $headers = $reactRequest->getHeaders(); + $query = $reactRequest->getQuery(); + $post = array(); + + // parse body? + if (isset($headers['Content-Type']) && (0 === strpos($headers['Content-Type'], 'application/x-www-form-urlencoded')) + && in_array(strtoupper($method), array('POST', 'PUT', 'DELETE', 'PATCH')) + ) { + parse_str($content, $post); + } + + $cookies = array(); + if (isset($headers['Cookie'])) { + $headersCookie = explode(';', $headers['Cookie']); + foreach ($headersCookie as $cookie) { + list($name, $value) = explode('=', trim($cookie)); + $cookies[$name] = $value; } - - $parameters = - in_array(strtoupper($method), array('POST', 'PUT', 'DELETE', 'PATCH')) - ? $post - : $query; - $syRequest = SymfonyRequest::create( - // $uri, $method, $parameters, $cookies, $files, $server, $content - $reactRequest->getPath(), - $method, - $parameters, - $cookies, - array(), - array(), - $content - ); - $syRequest->headers->replace($headers); - - // Set CGI/1.1 (RFC 3875) server vars. - // @see http://php.net/manual/en/reserved.variables.server.php - // @see http://www.faqs.org/rfcs/rfc3875.html - $serverVars = array_merge( - $syRequest->server->all(), - array( - 'DOCUMENT_ROOT' => $_SERVER['DOCUMENT_ROOT'], - 'GATEWAY_INTERFACE' => 'CGI/1.1', - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], - // SCRIPT_FILENAME contains the name of the php-pm startup script. - // Must override here. - 'SCRIPT_FILENAME' => $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'], - ) - ); - $syRequest->server->replace($serverVars); - - return $syRequest; - } - - - /** - * Convert Symfony\Component\HttpFoundation\Response to React\Http\Response - * - * @param ReactResponse $reactResponse - * @param SymfonyResponse $syResponse - */ - protected static function mapResponse(ReactResponse $reactResponse, - SymfonyResponse $syResponse) - { - $headers = $syResponse->headers->all(); - $reactResponse->writeHead($syResponse->getStatusCode(), $headers); - - // @TODO convert StreamedResponse in an async manner - if ($syResponse instanceof SymfonyStreamedResponse) { - ob_start(); - $syResponse->sendContent(); - $content = ob_get_contents(); - ob_end_clean(); - } - else { - $content = $syResponse->getContent(); - } - - $reactResponse->end($content); - } + } + + $parameters = + in_array(strtoupper($method), array('POST', 'PUT', 'DELETE', 'PATCH')) + ? $post + : $query; + $syRequest = SymfonyRequest::create( + // $uri, $method, $parameters, $cookies, $files, $server, $content + $reactRequest->getPath(), + $method, + $parameters, + $cookies, + array(), + array(), + $content + ); + $syRequest->headers->replace($headers); + + // Set CGI/1.1 (RFC 3875) server vars. + if (empty($_ENV)) { + // In some cases with cli, $_ENV isn't set, so get with getenv(). + // @todo: Make this more efficient to eliminate running per request. + // Static variable? + $_ENV['DOCUMENT_ROOT'] = getenv('DOCUMENT_ROOT'); + $_ENV['SCRIPT_NAME'] = getenv('SCRIPT_NAME'); + } + $serverVars = array_merge( + $syRequest->server->all(), + array( + 'DOCUMENT_ROOT' => $_ENV['DOCUMENT_ROOT'], + 'GATEWAY_INTERFACE' => 'CGI/1.1', + 'SCRIPT_NAME' => $_ENV['SCRIPT_NAME'], + // SCRIPT_FILENAME contains the name of the php-pm startup script. + // Must override here. + 'SCRIPT_FILENAME' => $_ENV['DOCUMENT_ROOT'] . $_ENV['SCRIPT_NAME'], + ) + ); + $syRequest->server->replace($serverVars); + + return $syRequest; + } + + + /** + * Convert Symfony\Component\HttpFoundation\Response to React\Http\Response + * + * @param ReactResponse $reactResponse + * @param SymfonyResponse $syResponse + */ + protected static function mapResponse(ReactResponse $reactResponse, + SymfonyResponse $syResponse) + { + $headers = $syResponse->headers->all(); + $reactResponse->writeHead($syResponse->getStatusCode(), $headers); + + // @TODO convert StreamedResponse in an async manner + if ($syResponse instanceof SymfonyStreamedResponse) { + ob_start(); + $syResponse->sendContent(); + $content = ob_get_contents(); + ob_end_clean(); + } + else { + $content = $syResponse->getContent(); + } + + $reactResponse->end($content); + } } From 8b19e8f9a2efe9a64ba7a60987fe0186523a8d57 Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 12:15:09 -0800 Subject: [PATCH 02/16] Improve handling of POST method detection / response. Correct some code style errors. Optimized detection & handling by consolidating code & reducing function calls. --- Bridges/DrupalKernel.php | 198 +++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 103 deletions(-) diff --git a/Bridges/DrupalKernel.php b/Bridges/DrupalKernel.php index d401dfe..0a7a600 100644 --- a/Bridges/DrupalKernel.php +++ b/Bridges/DrupalKernel.php @@ -29,83 +29,78 @@ class DrupalKernel extends SymfonyBridge implements BridgeInterface { /** - * Handle a request using a HttpKernelInterface implementing application. - * - * @param \React\Http\Request $request - * @param \React\Http\Response $response + * {@inheritdoc} */ - public function onRequest(ReactRequest $request, ReactResponse $response) - { - if (null === $this->application) { - return; - } + public function onRequest(ReactRequest $request, ReactResponse $response) { + + if (NULL === $this->application) { + return; + } + + $content = ''; + $headers = $request->getHeaders(); + $contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0; + + $request->on('data', function($data) + use ($request, $response, &$content, $contentLength) { + + // Read data (may be empty for GET request). + $content .= $data; + + // Handle request after receive. + if (strlen($content) >= $contentLength) { + $syRequest = self::mapRequest($request, $content); - $content = ''; - $headers = $request->getHeaders(); - $contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0; - - $request->on('data', function($data) - use ($request, $response, &$content, $contentLength) - { - // read data (may be empty for GET request) - $content .= $data; - - // handle request after receive - if (strlen($content) >= $contentLength) { - $syRequest = self::mapRequest($request, $content); - - try { - $syResponse = $this->application->handle($syRequest); - } catch (\Exception $exception) { - $response->writeHead(500); // internal server error - $response->end(); - return; - } - - self::mapResponse($response, $syResponse); - - if ($this->application instanceof TerminableInterface) { - $this->application->terminate($syRequest, $syResponse); - } - } - }); + try { + $syResponse = $this->application->handle($syRequest); + } + catch (\Exception $exception) { + // Internal server error. + $response->writeHead(500); + $response->end(); + return; + } + + self::mapResponse($response, $syResponse); + + if ($this->application instanceof TerminableInterface) { + $this->application->terminate($syRequest, $syResponse); + } + } + }); } /** - * Convert React\Http\Request to Symfony\Component\HttpFoundation\Request - * - * @param ReactRequest $reactRequest - * @return SymfonyRequest $syRequest + * {@inheritdoc} */ - protected static function mapRequest(ReactRequest $reactRequest, $content) - { - $method = $reactRequest->getMethod(); - $headers = $reactRequest->getHeaders(); - $query = $reactRequest->getQuery(); - $post = array(); - - // parse body? - if (isset($headers['Content-Type']) && (0 === strpos($headers['Content-Type'], 'application/x-www-form-urlencoded')) - && in_array(strtoupper($method), array('POST', 'PUT', 'DELETE', 'PATCH')) - ) { - parse_str($content, $post); - } + protected static function mapRequest(ReactRequest $reactRequest, $content) { - $cookies = array(); - if (isset($headers['Cookie'])) { - $headersCookie = explode(';', $headers['Cookie']); - foreach ($headersCookie as $cookie) { - list($name, $value) = explode('=', trim($cookie)); - $cookies[$name] = $value; - } + $method = strtoupper($reactRequest->getMethod()); + $headers = $reactRequest->getHeaders(); + $query = $reactRequest->getQuery(); + $post = array(); + + $requestIsPostType = in_array($method, array('POST', 'PUT', 'DELETE', 'PATCH')); + + // Parse body? + if (isset($headers['Content-Type']) && (0 === strpos($headers['Content-Type'], 'application/x-www-form-urlencoded')) + && $requestIsPostType + ) { + parse_str($content, $post); + } + + $cookies = array(); + if (isset($headers['Cookie'])) { + $headersCookie = explode(';', $headers['Cookie']); + foreach ($headersCookie as $cookie) { + list($name, $value) = explode('=', trim($cookie)); + $cookies[$name] = $value; } + } - $parameters = - in_array(strtoupper($method), array('POST', 'PUT', 'DELETE', 'PATCH')) - ? $post - : $query; - $syRequest = SymfonyRequest::create( - // $uri, $method, $parameters, $cookies, $files, $server, $content + $parameters = $requestIsPostType ? $post : $query; + $syRequest = SymfonyRequest::create( + // $uri, $method, $parameters, $cookies, $files, $server, $content. $reactRequest->getPath(), $method, $parameters, @@ -114,18 +109,18 @@ protected static function mapRequest(ReactRequest $reactRequest, $content) array(), $content ); - $syRequest->headers->replace($headers); - - // Set CGI/1.1 (RFC 3875) server vars. - if (empty($_ENV)) { - // In some cases with cli, $_ENV isn't set, so get with getenv(). - // @todo: Make this more efficient to eliminate running per request. - // Static variable? - $_ENV['DOCUMENT_ROOT'] = getenv('DOCUMENT_ROOT'); - $_ENV['SCRIPT_NAME'] = getenv('SCRIPT_NAME'); - } - $serverVars = array_merge( - $syRequest->server->all(), + $syRequest->headers->replace($headers); + + // Set CGI/1.1 (RFC 3875) server vars. + if (empty($_ENV)) { + // In some cases with cli, $_ENV isn't set, so get with getenv(). + // @todo: Make this more efficient to eliminate running per request. + // Static variable? + $_ENV['DOCUMENT_ROOT'] = getenv('DOCUMENT_ROOT'); + $_ENV['SCRIPT_NAME'] = getenv('SCRIPT_NAME'); + } + $serverVars = array_merge( + $syRequest->server->all(), array( 'DOCUMENT_ROOT' => $_ENV['DOCUMENT_ROOT'], 'GATEWAY_INTERFACE' => 'CGI/1.1', @@ -135,36 +130,33 @@ protected static function mapRequest(ReactRequest $reactRequest, $content) 'SCRIPT_FILENAME' => $_ENV['DOCUMENT_ROOT'] . $_ENV['SCRIPT_NAME'], ) ); - $syRequest->server->replace($serverVars); + $syRequest->server->replace($serverVars); - return $syRequest; + return $syRequest; } /** - * Convert Symfony\Component\HttpFoundation\Response to React\Http\Response - * - * @param ReactResponse $reactResponse - * @param SymfonyResponse $syResponse + * {@inheritdoc} */ protected static function mapResponse(ReactResponse $reactResponse, - SymfonyResponse $syResponse) - { - $headers = $syResponse->headers->all(); - $reactResponse->writeHead($syResponse->getStatusCode(), $headers); - - // @TODO convert StreamedResponse in an async manner - if ($syResponse instanceof SymfonyStreamedResponse) { - ob_start(); - $syResponse->sendContent(); - $content = ob_get_contents(); - ob_end_clean(); - } - else { - $content = $syResponse->getContent(); - } - - $reactResponse->end($content); + SymfonyResponse $syResponse) { + + $headers = $syResponse->headers->all(); + $reactResponse->writeHead($syResponse->getStatusCode(), $headers); + + // @TODO convert StreamedResponse in an async manner + if ($syResponse instanceof SymfonyStreamedResponse) { + ob_start(); + $syResponse->sendContent(); + $content = ob_get_contents(); + ob_end_clean(); + } + else { + $content = $syResponse->getContent(); + } + + $reactResponse->end($content); } } From 5851a4365180dc09ca23d656e261c9c27ea518b5 Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 12:23:11 -0800 Subject: [PATCH 03/16] Documentation. --- Bridges/DrupalKernel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Bridges/DrupalKernel.php b/Bridges/DrupalKernel.php index 0a7a600..4303f61 100644 --- a/Bridges/DrupalKernel.php +++ b/Bridges/DrupalKernel.php @@ -114,6 +114,7 @@ protected static function mapRequest(ReactRequest $reactRequest, $content) { // Set CGI/1.1 (RFC 3875) server vars. if (empty($_ENV)) { // In some cases with cli, $_ENV isn't set, so get with getenv(). + // @see http://stackoverflow.com/questions/8798294/getenv-vs-env-in-php/21473853#21473853 // @todo: Make this more efficient to eliminate running per request. // Static variable? $_ENV['DOCUMENT_ROOT'] = getenv('DOCUMENT_ROOT'); From 65848cf105744346dbdc1d4fba0e28daa21170f7 Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 12:26:28 -0800 Subject: [PATCH 04/16] Code style. --- Bridges/DrupalKernel.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Bridges/DrupalKernel.php b/Bridges/DrupalKernel.php index 4303f61..3697c64 100644 --- a/Bridges/DrupalKernel.php +++ b/Bridges/DrupalKernel.php @@ -80,7 +80,10 @@ protected static function mapRequest(ReactRequest $reactRequest, $content) { $query = $reactRequest->getQuery(); $post = array(); - $requestIsPostType = in_array($method, array('POST', 'PUT', 'DELETE', 'PATCH')); + $requestIsPostType = in_array( + $method, + array('POST', 'PUT', 'DELETE', 'PATCH') + ); // Parse body? if (isset($headers['Content-Type']) && (0 === strpos($headers['Content-Type'], 'application/x-www-form-urlencoded')) From e4084b87137a513057ce5b59f77217797ea6b7af Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 12:30:28 -0800 Subject: [PATCH 05/16] Update README with instructions for DrupalKernel bridge. --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d5978e..f009025 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # PHP-PM HttpKernel Adapter +## Overview + This is a fork of PHP-PM's HttpKernel adapter for integrating Drupal with PHP-PM (therefore, also with ReactPHP). See: @@ -10,7 +12,7 @@ The code is in alpha -- very experimental. Last tested against `drupal-8.0.2`. View / report issues at https://github.com/kentr/php-pm-drupal/issues. -### Setup +### Setup / Usage 1. Install Drupal. @@ -40,3 +42,26 @@ start \ --bridge=httpKernel \ --bootstrap=PHPPM\\Bootstraps\\Drupal ``` + +## DrupalKernel bridge + +`\PHPPM\Bridges\DrupalKernel` extends `\PHPPM\Bridges\HttpKernel` to populate various request meta-variables specified by CGI/1.1 (RFC 3875)[http://www.faqs.org/rfcs/rfc3875.html]. + +### Setup / Usage + + 1. Install as described above. + + 2. Include the environment variables and the `--bridge` option in the php-pm start command: + +Example: + +```bash +SCRIPT_NAME=/index.php \ +REQUEST_METHOD=GET \ +SERVER_NAME=localhost \ +SERVER_ADDRESS=127.0.0.1 \ +DOCUMENT_ROOT=/var/www/html \ +/var/www/html/vendor/bin/ppm start /var/www/html \ +--bridge=PHPPM\\Bridges\\DrupalKernel \ +--bootstrap=PHPPM\\Bootstraps\\Drupal +``` From c02ed88939960622ede97f0a5679bc5dfccde437 Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 12:35:03 -0800 Subject: [PATCH 06/16] Minor improvements to README. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f009025..dae35a1 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,9 @@ start \ ``` ## DrupalKernel bridge +By default, PHP-PM uses the `\PHPPM\Bridges\HttpKernel` bridge to convert a ReactPHP request into a Symfony request and the Symfony response into a ReactPHP response. -`\PHPPM\Bridges\DrupalKernel` extends `\PHPPM\Bridges\HttpKernel` to populate various request meta-variables specified by CGI/1.1 (RFC 3875)[http://www.faqs.org/rfcs/rfc3875.html]. +The included `\PHPPM\Bridges\DrupalKernel` bridge extends `\PHPPM\Bridges\HttpKernel` to populate various request meta-variables specified by [CGI/1.1 (RFC 3875)](http://www.faqs.org/rfcs/rfc3875.html). ### Setup / Usage From 7d6d272c8bbdada0c24140431cae48c3624bd16b Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Tue, 2 Feb 2016 13:57:25 -0800 Subject: [PATCH 07/16] Add explanation of environmental variables for using DrupalKernel bridge. --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dae35a1..c809602 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,18 @@ The included `\PHPPM\Bridges\DrupalKernel` bridge extends `\PHPPM\Bridges\HttpKe 1. Install as described above. - 2. Include the environment variables and the `--bridge` option in the php-pm start command: + 2. Include the environment variables and the `--bridge` option in the php-pm start command. + + Supported environment variables: + * **SCRIPT_NAME:** '/index.php' to emulate a standard setup where web requests execute Drupal's `index.php` script. + * **SERVER_NAME:** Your site's server / domain name. If you're using trusted host settings (`$settings['trusted_host_patterns']` in `settings.php`), this must match one of the trusted hosts. + * **SERVER_ADDRESS:** IP address of the server. + * **DOCUMENT_ROOT:** Absolute filepath of the web root directory. Example: ```bash SCRIPT_NAME=/index.php \ -REQUEST_METHOD=GET \ SERVER_NAME=localhost \ SERVER_ADDRESS=127.0.0.1 \ DOCUMENT_ROOT=/var/www/html \ From 55c466ab2bab827cb248bcf3e961f49077418b32 Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Thu, 11 Feb 2016 08:00:39 -0800 Subject: [PATCH 08/16] Correct page title. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c809602..d83bd8f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP-PM HttpKernel Adapter +# PHP-PM HttpDrupal Adapter ## Overview From 87bf9ed38b02e1c5f102781836d72fd24c586717 Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Thu, 11 Feb 2016 08:37:00 -0800 Subject: [PATCH 09/16] Improve documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d83bd8f..6a2ca1b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This is a fork of PHP-PM's HttpKernel adapter for integrating Drupal with PHP-PM (therefore, also with ReactPHP). +The primary components are a bootstrap and bridge. + See: * https://github.com/php-pm/php-pm * https://github.com/php-pm/php-pm-httpkernel. From f7568c5d54efc4e9035931b67700e7917f79486c Mon Sep 17 00:00:00 2001 From: Kent Richards Date: Thu, 18 Feb 2016 10:43:01 -0800 Subject: [PATCH 10/16] #8: Correct mapRequest() to include query string in $uri. --- Bridges/DrupalKernel.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Bridges/DrupalKernel.php b/Bridges/DrupalKernel.php index 3697c64..0c80b9a 100644 --- a/Bridges/DrupalKernel.php +++ b/Bridges/DrupalKernel.php @@ -101,10 +101,17 @@ protected static function mapRequest(ReactRequest $reactRequest, $content) { } } + // Add any query string to URI so SymfonyRequest::create() can access it. + $uri = $reactRequest->getPath() . + (empty($query) ? '' : '?' . http_build_query($query)); + + // SymfonyRequest::create() expects $parameters to contain either + // $_GET or $_POST. $parameters = $requestIsPostType ? $post : $query; + $syRequest = SymfonyRequest::create( // $uri, $method, $parameters, $cookies, $files, $server, $content. - $reactRequest->getPath(), + $uri, $method, $parameters, $cookies, @@ -124,7 +131,7 @@ protected static function mapRequest(ReactRequest $reactRequest, $content) { $_ENV['SCRIPT_NAME'] = getenv('SCRIPT_NAME'); } $serverVars = array_merge( - $syRequest->server->all(), + $syRequest->server->all(), array( 'DOCUMENT_ROOT' => $_ENV['DOCUMENT_ROOT'], 'GATEWAY_INTERFACE' => 'CGI/1.1', From 81d2ec417249bf0ee737f3eba59207e8762d59ea Mon Sep 17 00:00:00 2001 From: KentR Date: Fri, 19 Feb 2016 12:38:37 -0800 Subject: [PATCH 11/16] Update URL for project issues. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a2ca1b..49a5bd2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ See: The code is in alpha -- very experimental. Last tested against `drupal-8.0.2`. -View / report issues at https://github.com/kentr/php-pm-drupal/issues. +View / report issues at https://github.com/php-pm/php-pm-drupal/issues. ### Setup / Usage From 5bcd7d6a211e0340d25d414289211656f3340e5a Mon Sep 17 00:00:00 2001 From: KentR Date: Fri, 11 Mar 2016 10:07:25 -0800 Subject: [PATCH 12/16] Correct "DrupalKernel" in page headline. Change "HttpDrupal" to "DrupalKernel". Add reference link. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49a5bd2..9b309d2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP-PM HttpDrupal Adapter +# PHP-PM DrupalKernel Adapter ## Overview @@ -8,7 +8,8 @@ The primary components are a bootstrap and bridge. See: * https://github.com/php-pm/php-pm -* https://github.com/php-pm/php-pm-httpkernel. +* https://github.com/php-pm/php-pm-httpkernel +* http://marcjschmidt.de/blog/2014/02/08/php-high-performance.html The code is in alpha -- very experimental. Last tested against `drupal-8.0.2`. From 3631370ceeb5c41f45447ba16d8ea6c69ee933ca Mon Sep 17 00:00:00 2001 From: KentR Date: Wed, 16 Mar 2016 07:28:30 -0700 Subject: [PATCH 13/16] Adjust composer package name See #9. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3f54c01..01c45de 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "kentr/php-pm-drupal-adapter", + "name": "php-pm/php-pm-drupal-adapter", "require": { "php-pm/php-pm": "*", "php-pm/httpkernel-adapter": "*" From a0bdf000ee5c1a1c1a41b73758f1c73e495692eb Mon Sep 17 00:00:00 2001 From: KentR Date: Wed, 16 Mar 2016 07:58:40 -0700 Subject: [PATCH 14/16] Adjust composer package name Per request in #10. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 01c45de..98397a1 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "php-pm/php-pm-drupal-adapter", + "name": "php-pm/drupal-adapter", "require": { "php-pm/php-pm": "*", "php-pm/httpkernel-adapter": "*" From 4737f6917311e8539295f32aa6ba1b06193d1972 Mon Sep 17 00:00:00 2001 From: KentR Date: Wed, 16 Mar 2016 09:08:52 -0700 Subject: [PATCH 15/16] Update composer command. Per #9, #10. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b309d2..9af34c2 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ View / report issues at https://github.com/php-pm/php-pm-drupal/issues. 1. Install Drupal. - 2. From the Drupal web root, install this project with composer: `composer require kentr/php-pm-drupal-adapter`. + 2. From the Drupal web root, install this project with composer: `composer require php-pm/drupal-adapter`. This will also install PHP-PM and the default React <-> Symfony bridge (php-pm/httpkernel-adapter). From 0470250e3e79e05f23ad21ab4c6e86f41f9f94e0 Mon Sep 17 00:00:00 2001 From: KentR Date: Mon, 21 Nov 2016 14:41:52 -0800 Subject: [PATCH 16/16] update patch for 8.3.x Update kentr-allow-repeated-setSitePath-in-DrupalKernel.patch for Drupal 8.3.x. --- .../kentr-allow-repeated-setSitePath-in-DrupalKernel.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/kentr-allow-repeated-setSitePath-in-DrupalKernel.patch b/patches/kentr-allow-repeated-setSitePath-in-DrupalKernel.patch index 43bd297..06f4f0f 100644 --- a/patches/kentr-allow-repeated-setSitePath-in-DrupalKernel.patch +++ b/patches/kentr-allow-repeated-setSitePath-in-DrupalKernel.patch @@ -1,8 +1,8 @@ diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php -index 16b3bac..c84286b 100644 +index 274a3fa..9089a7d 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php -@@ -383,7 +383,7 @@ public static function findSitePath(Request $request, $require_settings = TRUE) +@@ -410,7 +410,7 @@ public static function findSitePath(Request $request, $require_settings = TRUE, * {@inheritdoc} */ public function setSitePath($path) {