public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { if ($type !== self::MASTER_REQUEST) { throw new \LogicException('Wordpress\\HttpKernel cannot handle SUB_REQUESTS'); } unset($type); $this->catch = $catch; unset($catch); $this->timezone = date_default_timezone_get(); $this->startOutputBuffer(); try { $wp_the_query = null; $this->storeGlobals(); $request->overrideGlobals(); if ($globalNames = @(include $this->wordpressGlobalNamesCacheFile)) { foreach ($globalNames ?: array() as $name) { @eval('global $' . $name . ';'); } } else { throw new \RuntimeException('The global names cache file has to be generated with "app/console startplatz:wordpress-integration:build-global-names-cache"'); } define('WP_USE_THEMES', true); $time_start = microtime(true); require_once "{$this->wordpressRootDir}/wp-load.php"; global $wp_query; $wp_query = $wp_the_query; \wp(); require_once "{$this->wordpressRootDir}/wp-includes/template-loader.php"; $content = $this->endOutputBuffer(); $statusCode = is_404() ? 404 : 200; $headers = $this->flushHeaders(); $this->restoreGlobals(); date_default_timezone_set($this->timezone); return new Response($content, $statusCode, $headers); } catch (\Exception $e) { $this->endOutputBuffer(); $this->flushHeaders(); $this->restoreGlobals(); date_default_timezone_set($this->timezone); if ($this->catch) { return new Response($e->getMessage(), 500); } else { throw $e; } } }
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { $request->overrideGlobals(); $app = \Yii::app(); $app->setComponent('request', new YiiRequest()); $app->request->inject($request->files->all()); $hasError = false; ob_start(); try { $app->processRequest(); } catch (YiiExitException $e) { } catch (Exception $e) { $hasError = true; } $content = ob_get_contents(); ob_end_clean(); $headers = $this->getHeaders(); $sessionId = session_id(); if (empty($sessionId)) { session_regenerate_id(); $app->session->open(); } return new Response($content, $this->getStatusCode($headers, $hasError), $headers); }
public function testOverrideGlobals() { $request = new Request(); $request->initialize(array('foo' => 'bar')); // as the Request::overrideGlobals really work, it erase $_SERVER, so we must backup it $server = $_SERVER; $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_GET); $request->initialize(array(), array('foo' => 'bar')); $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_POST); $this->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); $request->headers->set('X_FORWARDED_PROTO', 'https'); Request::setTrustedProxies(array('1.1.1.1')); $this->assertFalse($request->isSecure()); $request->server->set('REMOTE_ADDR', '1.1.1.1'); $this->assertTrue($request->isSecure()); Request::setTrustedProxies(array()); $request->overrideGlobals(); $this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); $request->headers->set('CONTENT_TYPE', 'multipart/form-data'); $request->headers->set('CONTENT_LENGTH', 12345); $request->overrideGlobals(); $this->assertArrayHasKey('CONTENT_TYPE', $_SERVER); $this->assertArrayHasKey('CONTENT_LENGTH', $_SERVER); $request->initialize(array('foo' => 'bar', 'baz' => 'foo')); $request->query->remove('baz'); $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_GET); $this->assertEquals('foo=bar', $_SERVER['QUERY_STRING']); $this->assertEquals('foo=bar', $request->server->get('QUERY_STRING')); // restore initial $_SERVER array $_SERVER = $server; }
public function testOverrideGlobals() { $request = new Request(); $request->initialize(array('foo' => 'bar')); // as the Request::overrideGlobals really work, it erase $_SERVER, so we must backup it $server = $_SERVER; $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_GET); $request->initialize(array(), array('foo' => 'bar')); $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_POST); $this->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); $this->startTrustingProxyData(); $request->headers->set('X_FORWARDED_PROTO', 'https'); $this->assertTrue($request->isSecure()); $this->stopTrustingProxyData(); $request->overrideGlobals(); $this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); // restore initial $_SERVER array $_SERVER = $server; }
/** * @param SymfonyRequest $request * @return EnlightRequest */ public function transformSymfonyRequestToEnlightRequest(SymfonyRequest $request) { // Overwrite superglobals with state of the SymfonyRequest $request->overrideGlobals(); // Create englight request from global state $enlightRequest = new EnlightRequest(); // Set commandline args as request uri // This is used for legacy cronjob routing. // e.g: /usr/bin/php shopware.php /backend/cron if (PHP_SAPI === 'cli' && is_array($argv = $request->server->get('argv')) && isset($argv[1])) { $enlightRequest->setRequestUri($argv[1]); } // Let the symfony request handle the trusted proxies $enlightRequest->setRemoteAddress($request->getClientIp()); $enlightRequest->setSecure($request->isSecure()); return $enlightRequest; }
/** * @param Symfony\Component\HttpFoundation\Request $request * @return \Enlight_Controller_Request_RequestHttp */ public function createRequest(Request $request) { $request->overrideGlobals(); $request = new ControllerRequest( str_replace(" ","+",$request->getUri()) ); $request->setQuery($request->getQuery()); return $request; }
public function testOverrideGlobals() { $time = $_SERVER['REQUEST_TIME']; // fix for phpunit timer $request = new Request(); $request->initialize(array('foo' => 'bar')); $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_GET); $request->initialize(array(), array('foo' => 'bar')); $request->overrideGlobals(); $this->assertEquals(array('foo' => 'bar'), $_POST); $this->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); $request->headers->set('X_FORWARDED_PROTO', 'https'); $this->assertTrue($request->isSecure()); $request->overrideGlobals(); $this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER); $_SERVER['REQUEST_TIME'] = $time; // fix for phpunit timer }