本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::overrideGlobals方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::overrideGlobals方法的具体用法?PHP Request::overrideGlobals怎么用?PHP Request::overrideGlobals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::overrideGlobals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
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;
}
}
}
示例2: handle
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);
}
示例3: testOverrideGlobals
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;
}
示例4: testOverrideGlobals
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;
}
示例5: transformSymfonyRequestToEnlightRequest
/**
* @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;
}
示例6: createRequest
/**
* @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;
}
示例7: testOverrideGlobals
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
}