当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::createFromGlobals方法代码示例

本文整理汇总了PHP中Cake\Network\Request::createFromGlobals方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::createFromGlobals方法的具体用法?PHP Request::createFromGlobals怎么用?PHP Request::createFromGlobals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Network\Request的用法示例。


在下文中一共展示了Request::createFromGlobals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: build

 /**
  * @param \Cake\Network\Response $response The response.
  * @return \Cake\Network\Response
  */
 protected function build($response)
 {
     $cakeRequest = Request::createFromGlobals();
     $builder = new ViewBuilder();
     $templateName = $this->config('templateFileName');
     $templatePath = $this->config('templatePath');
     $view = $builder->className($this->config('className'))->templatePath(Inflector::camelize($templatePath))->layout($this->config('templateLayout'))->build([], $cakeRequest);
     $view->_ext = $this->config('templateExtension');
     $bodyString = $view->render($templateName);
     $response = $response->withHeader('Retry-After', (string) HOUR)->withHeader('Content-Type', $this->config('contentType'))->withStatus($this->config('statusCode'));
     $body = $response->getBody();
     $body->write($bodyString);
     return $response;
 }
开发者ID:dereuromark,项目名称:cakephp-setup,代码行数:18,代码来源:MaintenanceMiddleware.php

示例2: dirname

/**
 * The Front Controller for handling every request
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
// for built-in server
if (php_sapi_name() === 'cli-server') {
    $_SERVER['PHP_SELF'] = '/' . basename(__FILE__);
    $url = parse_url(urldecode($_SERVER['REQUEST_URI']));
    $file = __DIR__ . $url['path'];
    if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) {
        return false;
    }
}
require dirname(__DIR__) . '/config/bootstrap.php';
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\DispatcherFactory;
$dispatcher = DispatcherFactory::create();
$dispatcher->dispatch(Request::createFromGlobals(), new Response());
开发者ID:alexswider,项目名称:dropup,代码行数:30,代码来源:index.php

示例3: initialize

 /**
  * Initialize config data and properties.
  *
  * @param array $config The config data.
  * @return void
  */
 public function initialize(array $config)
 {
     if (!$this->_config['key']) {
         $this->config('key', Security::salt());
     }
     $controller = $this->_registry->getController();
     if ($controller && isset($controller->request)) {
         $this->_request = $controller->request;
     } else {
         $this->_request = Request::createFromGlobals();
     }
     if (empty($this->_config['path'])) {
         $this->config('path', $this->_request->base ?: '/');
     }
     if ($controller && isset($controller->response)) {
         $this->_response = $controller->response;
     } else {
         $this->_response = new Response();
     }
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:26,代码来源:CookieComponent.php

示例4: _getController

 /**
  * Get the controller instance to handle the exception.
  * Override this method in subclasses to customize the controller used.
  * This method returns the built in `ErrorController` normally, or if an error is repeated
  * a bare controller will be used.
  *
  * @return \Cake\Controller\Controller
  * @triggers Controller.startup $controller
  */
 protected function _getController()
 {
     if (!($request = Router::getRequest(true))) {
         $request = Request::createFromGlobals();
     }
     $response = new Response();
     try {
         $class = App::className('Error', 'Controller', 'Controller');
         $controller = new $class($request, $response);
         $controller->startupProcess();
         $startup = true;
     } catch (Exception $e) {
         $startup = false;
     }
     // Retry RequestHandler, as another aspect of startupProcess()
     // could have failed. Ignore any exceptions out of startup, as
     // there could be userland input data parsers.
     if ($startup === false && !empty($controller) && isset($controller->RequestHandler)) {
         try {
             $event = new Event('Controller.startup', $controller);
             $controller->RequestHandler->startup($event);
         } catch (Exception $e) {
         }
     }
     if (empty($controller)) {
         $controller = new Controller($request, $response);
     }
     return $controller;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:38,代码来源:ExceptionRenderer.php

示例5: testContentType

 /**
  * Test the content type method.
  *
  * @return void
  */
 public function testContentType()
 {
     $_SERVER['HTTP_CONTENT_TYPE'] = 'application/json';
     $request = Request::createFromGlobals();
     $this->assertEquals('application/json', $request->contentType());
     $_SERVER['CONTENT_TYPE'] = 'application/xml';
     $request = Request::createFromGlobals();
     $this->assertEquals('application/xml', $request->contentType(), 'prefer non http header.');
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:14,代码来源:RequestTest.php

示例6: parse

 /**
  * Checks to see if the given URL can be parsed by this route.
  *
  * If the route can be parsed an array of parameters will be returned; if not
  * false will be returned. String URLs are parsed if they match a routes regular expression.
  *
  * @param string $url The URL to attempt to parse.
  * @return array|false Boolean false on failure, otherwise an array of parameters.
  */
 public function parse($url)
 {
     $request = Router::getRequest(true) ?: Request::createFromGlobals();
     if (empty($this->_compiledRoute)) {
         $this->compile();
     }
     list($url, $ext) = $this->_parseExtension($url);
     if (!preg_match($this->_compiledRoute, urldecode($url), $route)) {
         return false;
     }
     if (isset($this->defaults['_method'])) {
         $method = $request->env('REQUEST_METHOD');
         if (!in_array($method, (array) $this->defaults['_method'], true)) {
             return false;
         }
     }
     array_shift($route);
     $count = count($this->keys);
     for ($i = 0; $i <= $count; $i++) {
         unset($route[$i]);
     }
     $route['pass'] = [];
     // Assign defaults, set passed args to pass
     foreach ($this->defaults as $key => $value) {
         if (isset($route[$key])) {
             continue;
         }
         if (is_int($key)) {
             $route['pass'][] = $value;
             continue;
         }
         $route[$key] = $value;
     }
     if (isset($route['_args_'])) {
         $pass = $this->_parseArgs($route['_args_'], $route);
         $route['pass'] = array_merge($route['pass'], $pass);
         unset($route['_args_']);
     }
     if (isset($route['_trailing_'])) {
         $route['pass'][] = $route['_trailing_'];
         unset($route['_trailing_']);
     }
     if (!empty($ext)) {
         $route['_ext'] = $ext;
     }
     // restructure 'pass' key route params
     if (isset($this->options['pass'])) {
         $j = count($this->options['pass']);
         while ($j--) {
             if (isset($route[$this->options['pass'][$j]])) {
                 array_unshift($route['pass'], $route[$this->options['pass'][$j]]);
             }
         }
     }
     return $route;
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:65,代码来源:Route.php

示例7: _getController

 /**
  * Get the controller instance to handle the exception.
  * Override this method in subclasses to customize the controller used.
  * This method returns the built in `ErrorController` normally, or if an error is repeated
  * a bare controller will be used.
  *
  * @return \Cake\Controller\Controller
  */
 protected function _getController()
 {
     if (!($request = Router::getRequest(true))) {
         $request = Request::createFromGlobals();
     }
     $response = new Response();
     try {
         $controller = new ErrorController($request, $response);
         $controller->startupProcess();
     } catch (Exception $e) {
         if (!empty($controller) && isset($controller->RequestHandler)) {
             $event = new Event('Controller.startup', $controller);
             $controller->RequestHandler->startup($event);
         }
     }
     if (empty($controller)) {
         $controller = new Controller($request, $response);
         $controller->viewPath = 'Error';
     }
     return $controller;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:29,代码来源:ExceptionRenderer.php

示例8: explode

DispatcherFactory::add('ControllerFactory');
/**
 * Enable immutable time objects in the ORM.
 *
 * You can enable default locale format parsing by adding calls
 * to `useLocaleParser()`. This enables the automatic conversion of
 * locale specific date formats. For details see
 * @link http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
 */
Type::build('time')->useImmutable();
Type::build('date')->useImmutable();
Type::build('datetime')->useImmutable();
/**
 * Bootstrap & load Site plugin
 */
$Request = Request::createFromGlobals();
$url = explode('/', $Request->url);
$website_dir = 'websites';
$website_default = 'default';
$website_name = trim($url[0]) != '' ? trim($url[0]) : $website_default;
$website_fullpath = ROOT . DS . $website_dir . DS . $website_name . DS;
if (file_exists($website_fullpath)) {
    $plugins = [];
    if (Configure::check(['plugins'])) {
        $plugins = Configure::read(['plugins']);
    }
    $plugins['Site'] = $website_fullpath;
    Configure::write('plugins', $plugins);
    // Define default Site variables
    define('APP_WEBROOT', $Request->webroot);
    define('APP_BASE_URL', $Request->base);
开发者ID:aoliverio,项目名称:content-app,代码行数:31,代码来源:bootstrap.php

示例9: initialize

 /**
  * Initialize config data and properties.
  *
  * @param array $config The config data.
  * @return void
  */
 public function initialize(array $config)
 {
     if (!$this->_config['key']) {
         $this->config('key', Security::salt());
     }
     $controller = $this->_registry->getController();
     if ($controller !== null) {
         $this->_response =& $controller->response;
     }
     if ($controller === null) {
         $this->request = Request::createFromGlobals();
         $this->_response = new Response();
     }
     if (empty($this->_config['path'])) {
         $this->config('path', $this->request->webroot);
     }
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:23,代码来源:CookieComponent.php

示例10: parse

 /**
  * Checks to see if the given URL can be parsed by this route.
  *
  * If the route can be parsed an array of parameters will be returned; if not
  * false will be returned. String URLs are parsed if they match a routes regular expression.
  *
  * @param string $url The URL to attempt to parse.
  * @return mixed Boolean false on failure, otherwise an array or parameters
  */
 public function parse($url)
 {
     $request = Router::getRequest(true) ?: Request::createFromGlobals();
     if (!$this->compiled()) {
         $this->compile();
     }
     list($url, $ext) = $this->_parseExtension($url);
     if (!preg_match($this->_compiledRoute, urldecode($url), $route)) {
         return false;
     }
     foreach ($this->defaults as $key => $val) {
         $key = (string) $key;
         if ($key[0] === '[' && preg_match('/^\\[(\\w+)\\]$/', $key, $header)) {
             if (isset($this->_headerMap[$header[1]])) {
                 $header = $this->_headerMap[$header[1]];
             } else {
                 $header = 'http_' . $header[1];
             }
             $header = strtoupper($header);
             $val = (array) $val;
             $h = false;
             foreach ($val as $v) {
                 if ($request->env($header) === $v) {
                     $h = true;
                 }
             }
             if (!$h) {
                 return false;
             }
         }
     }
     array_shift($route);
     $count = count($this->keys);
     for ($i = 0; $i <= $count; $i++) {
         unset($route[$i]);
     }
     $route['pass'] = [];
     // Assign defaults, set passed args to pass
     foreach ($this->defaults as $key => $value) {
         if (isset($route[$key])) {
             continue;
         }
         if (is_int($key)) {
             $route['pass'][] = $value;
             continue;
         }
         $route[$key] = $value;
     }
     if (isset($route['_args_'])) {
         $pass = $this->_parseArgs($route['_args_'], $route);
         $route['pass'] = array_merge($route['pass'], $pass);
         unset($route['_args_']);
     }
     if (isset($route['_trailing_'])) {
         $route['pass'][] = $route['_trailing_'];
         unset($route['_trailing_']);
     }
     if (!empty($ext)) {
         $route['_ext'] = $ext;
     }
     // restructure 'pass' key route params
     if (isset($this->options['pass'])) {
         $j = count($this->options['pass']);
         while ($j--) {
             if (isset($route[$this->options['pass'][$j]])) {
                 array_unshift($route['pass'], $route[$this->options['pass'][$j]]);
             }
         }
     }
     return $route;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:80,代码来源:Route.php

示例11: _render

 /**
  * Build and set all the view properties needed to render the layout and template.
  *
  * @return array The rendered template wrapped in layout.
  */
 protected function _render()
 {
     $viewClass = $this->viewRender();
     $viewClass = App::className($viewClass, 'View', $viewClass == 'View' ? '' : 'View');
     $View = new $viewClass(Request::createFromGlobals());
     $View->viewVars = $this->_viewVars;
     $View->theme = $this->_theme;
     $View->layoutPath = 'pdf';
     $View->viewPath = 'Pdf';
     $View->view = $this->_template;
     $View->layout = $this->_layout;
     $View->helpers = $this->_helpers;
     $View->loadHelpers();
     return $View->render();
 }
开发者ID:Iteracode,项目名称:CakePdf,代码行数:20,代码来源:CakePdf.php

示例12: __construct

 /**
  * Constructor
  *
  * @param ComponentRegistry $collection A ComponentRegistry for this component
  * @param array $config Array of config.
  */
 public function __construct(ComponentRegistry $collection, array $config = array())
 {
     parent::__construct($collection, $config);
     if (!$this->_config['key']) {
         $this->config('key', Configure::read('Security.salt'));
     }
     if ($this->_config['time']) {
         $this->_expire($this->_config['time']);
     }
     $controller = $collection->getController();
     if ($controller && isset($controller->request)) {
         $this->_request = $controller->request;
     } else {
         $this->_request = Request::createFromGlobals();
     }
     if ($controller && isset($controller->response)) {
         $this->_response = $controller->response;
     } else {
         $this->_response = new Response();
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:27,代码来源:CookieComponent.php

示例13: testEnvironmentDetection

 /**
  * Test environment detection
  *
  * @dataProvider environmentGenerator
  * @param $name
  * @param $env
  * @param $expected
  * @return void
  */
 public function testEnvironmentDetection($name, $env, $expected)
 {
     $_GET = array();
     $this->_loadEnvironment($env);
     $request = Request::createFromGlobals();
     $this->assertEquals($expected['url'], $request->url, "url error");
     $this->assertEquals($expected['base'], $request->base, "base error");
     $this->assertEquals($expected['webroot'], $request->webroot, "webroot error");
     if (isset($expected['urlParams'])) {
         $this->assertEquals($expected['urlParams'], $request->query, "GET param mismatch");
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:21,代码来源:RequestTest.php

示例14: testSession

 /**
  * Tests getting the sessions from the request
  *
  * @return void
  */
 public function testSession()
 {
     $session = new Session();
     $request = new Request(['session' => $session]);
     $this->assertSame($session, $request->session());
     $request = Request::createFromGlobals();
     $this->assertEquals($session, $request->session());
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:13,代码来源:RequestTest.php

示例15: currentUser

 public function currentUser()
 {
     $request = Request::createFromGlobals();
     $session = $request->session();
     return ['id' => $session->read('Auth.User.id'), 'ip' => $request->env('REMOTE_ADDR'), 'url' => $request->here(), 'description' => $session->read('Auth.User.username')];
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:6,代码来源:CurrentUserTrait.php


注:本文中的Cake\Network\Request::createFromGlobals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。