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


PHP Router::getRequest方法代码示例

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


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

示例1: applyHookMethods

 /**
  * Applies methods set from hooks to an object in __construct()
  *
  * @param string $configKey
  */
 public static function applyHookMethods($configKey, &$object = null)
 {
     if (empty($object)) {
         $object = self;
     }
     if ($object instanceof Table) {
         $objectName = $object->alias();
     } else {
         $objectName = $object->name;
     }
     if (php_sapi_name() !== 'cli') {
         $prefix = ($prefix = Router::getRequest()->param('prefix')) ? Inflector::camelize($prefix) . '.' : '';
         $plugin = ($plugin = Router::getRequest()->param('plugin')) ? $plugin . '.' : '';
         $objectName = $prefix . $plugin . $objectName;
         $hookMethods = Configure::read($configKey . '.' . $objectName);
         if (is_array(Configure::read($configKey . '.*'))) {
             $hookMethods = Hash::merge(Configure::read($configKey . '.*'), $hookMethods);
         }
         if (is_array($hookMethods)) {
             foreach ($hookMethods as $method => $values) {
                 if (is_callable([$object, $method])) {
                     foreach ($values as $name => $config) {
                         $object->{$method}($name, $config);
                     }
                 }
             }
         }
     }
 }
开发者ID:mohammadsaleh,项目名称:spider,代码行数:34,代码来源:Hook.php

示例2: testRequestAction

 /**
  * testRequestAction method
  *
  * @return void
  */
 public function testRequestAction()
 {
     $this->assertNull(Router::getRequest(), 'request stack should be empty.');
     $result = $this->object->requestAction('');
     $this->assertFalse($result);
     $result = $this->object->requestAction('/request_action/test_request_action');
     $expected = 'This is a test';
     $this->assertEquals($expected, $result);
     $result = $this->object->requestAction(Configure::read('App.fullBaseUrl') . '/request_action/test_request_action');
     $expected = 'This is a test';
     $this->assertEquals($expected, $result);
     $result = $this->object->requestAction('/request_action/another_ra_test/2/5');
     $expected = 7;
     $this->assertEquals($expected, $result);
     $result = $this->object->requestAction('/tests_apps/index', array('return'));
     $expected = 'This is the TestsAppsController index view ';
     $this->assertEquals($expected, $result);
     $result = $this->object->requestAction('/tests_apps/some_method');
     $expected = 5;
     $this->assertEquals($expected, $result);
     $result = $this->object->requestAction('/request_action/paginate_request_action');
     $this->assertNull($result);
     $result = $this->object->requestAction('/request_action/normal_request_action');
     $expected = 'Hello World';
     $this->assertEquals($expected, $result);
     $this->assertNull(Router::getRequest(), 'requests were not popped off the stack, this will break url generation');
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:32,代码来源:RequestActionTraitTest.php

示例3: beforeDispatch

 /**
  * Prepares the default language to use by the script.
  *
  * ### Detection Methods
  *
  * This method applies the following detection methods when looking for
  * language to use:
  *
  * - GET parameter: If `locale` GET parameter is present in current request, and
  *   if it's a valid language code, then will be used as current language and
  *   also will be persisted on `locale` session for further use.
  *
  * - URL: If current URL is prefixed with a valid language code and
  *   `url_locale_prefix` option is enabled, URL's language code will be used.
  *
  * - Locale session: If `locale` session exists it will be used.
  *
  * - User session: If user is logged in and has selected a valid preferred
  *   language it will be used.
  *
  * - Default: Site's language will be used otherwise.
  *
  * ### Locale Prefix
  *
  * If `url_locale_prefix` option is enabled, and current request's URL is not
  * language prefixed, user will be redirected to a locale-prefixed version of
  * the requested URL (using the language code selected as explained above).
  *
  * For example:
  *
  *     /article/demo-article.html
  *
  * Might redirects to:
  *
  *     /en_US/article/demo-article.html
  *
  * @param \Cake\Event\Event $event containing the request, response and
  *  additional parameters
  * @return void
  * @throws \Cake\Network\Exception\InternalErrorException When no valid request
  *  object could be found
  */
 public function beforeDispatch(Event $event)
 {
     parent::beforeDispatch($event);
     $request = Router::getRequest();
     if (empty($request)) {
         throw new InternalErrorException(__d('cms', 'No request object could be found.'));
     }
     $locales = array_keys(quickapps('languages'));
     $localesPattern = '(' . implode('|', array_map('preg_quote', $locales)) . ')';
     $rawUrl = str_replace_once($request->base, '', env('REQUEST_URI'));
     $normalizedURL = str_replace('//', '/', "/{$rawUrl}");
     if (!empty($request->query['locale']) && in_array($request->query['locale'], $locales)) {
         $request->session()->write('locale', $request->query['locale']);
         I18n::locale($request->session()->read('locale'));
     } elseif (option('url_locale_prefix') && preg_match("/\\/{$localesPattern}\\//", $normalizedURL, $matches)) {
         I18n::locale($matches[1]);
     } elseif ($request->session()->check('locale') && in_array($request->session()->read('locale'), $locales)) {
         I18n::locale($request->session()->read('locale'));
     } elseif ($request->is('userLoggedIn') && in_array(user()->locale, $locales)) {
         I18n::locale(user()->locale);
     } elseif (in_array(option('default_language'), $locales)) {
         I18n::locale(option('default_language'));
     } else {
         I18n::locale(CORE_LOCALE);
     }
     if (option('url_locale_prefix') && !$request->is('home') && !preg_match("/\\/{$localesPattern}\\//", $normalizedURL)) {
         $url = Router::url('/' . I18n::locale() . $normalizedURL, true);
         http_response_code(303);
         header("Location: {$url}");
         die;
     }
 }
开发者ID:quickapps-plugins,项目名称:cms,代码行数:74,代码来源:LanguageFilter.php

示例4: getHtml

 /**
  * get the body for htmll message
  *
  * @access private
  * @author sakuragawa
  */
 private function getHtml($message, $file, $line, $context = null)
 {
     $params = Router::getRequest();
     $trace = Debugger::trace(array('start' => 2, 'format' => 'base'));
     $session = isset($_SESSION) ? $_SESSION : array();
     $msg = array('<p><strong>', $message, '</strong></p>', '<p>', $file . '(' . $line . ')', '</p>', '', '<h2>', 'Backtrace:', '</h2>', '', '<pre>', self::dumper($trace), '</pre>', '', '<h2>', 'Request:', '</h2>', '', '<h3>URL</h3>', $this->url(), '<h3>Client IP</h3>', $this->getClientIp(), '<h3>Referer</h3>', env('HTTP_REFERER'), '<h3>Parameters</h3>', self::dumper($params), '<h3>Cake root</h3>', APP, '', '<h2>', 'Environment:', '</h2>', '', self::dumper($_SERVER), '', '<h2>', 'Session:', '</h2>', '', self::dumper($session), '', '<h2>', 'Cookie:', '</h2>', '', self::dumper($_COOKIE), '', '<h2>', 'Context:', '</h2>', '', self::dumper($context), '');
     return join("", $msg);
 }
开发者ID:fusic,项目名称:encount,代码行数:14,代码来源:Mail.php

示例5: afterLogin

 public function afterLogin($event)
 {
     $entity = $event->data['user'];
     $entity->isNew(false);
     $entity->last_login = new Time();
     $entity->last_ip = Router::getRequest(true)->clientIp();
     TableRegistry::get('users')->save($entity);
 }
开发者ID:ThreeCMS,项目名称:ThreeCMS,代码行数:8,代码来源:UserEvent.php

示例6: _getUrl

 /**
  * Gets content's details page URL.
  *
  * Content's details URL's follows the syntax below:
  *
  *     http://example.com/{content-type-slug}/{content-slug}{CONTENT_EXTENSION}
  *
  * Example:
  *
  *     http://example.com/blog-article/my-first-article.html
  *
  * @return string
  */
 protected function _getUrl()
 {
     $url = Router::getRequest()->base;
     if (option('url_locale_prefix')) {
         $url .= '/' . I18n::locale();
     }
     $url .= "/{$this->content_type_slug}/{$this->slug}";
     return Router::normalize($url) . CONTENT_EXTENSION;
 }
开发者ID:quickapps-plugins,项目名称:content,代码行数:22,代码来源:Content.php

示例7: googleRecaptcha

 /**
  * Validate a google recaptcha.
  *
  * @param string $value The captcha value.
  * @param array $context The form context.
  * @return bool
  */
 public static function googleRecaptcha($value, $context)
 {
     $httpClient = new Client();
     $googleReponse = $httpClient->post('https://www.google.com/recaptcha/api/siteverify', ['secret' => Configure::read('Google.Recaptcha.secret'), 'response' => $value, 'remoteip' => Router::getRequest()->clientIp()]);
     $result = json_decode($googleReponse->body(), true);
     if (!empty($result['error-codes'])) {
         Log::error('Google Recaptcha: ' . $result['error-codes'][0]);
     }
     return (bool) $result['success'];
 }
开发者ID:wasabi-cms,项目名称:core,代码行数:17,代码来源:GoogleRecaptchaValidationProvider.php

示例8: beforeFind

 /**
  * {@inheritDoc}
  *
  * The entity to which this instance is attached to will be removed from
  * resulting result set if its publishing date does not match current date, this
  * constraint is not applied on the backend section of the site.
  */
 public function beforeFind(Field $field, array $options, $primary)
 {
     if ($primary && !Router::getRequest()->isAdmin() && !empty($field->extra['from']['timestamp']) && !empty($field->extra['to']['timestamp'])) {
         $now = time();
         if ($field->extra['from']['timestamp'] > $now || $now > $field->extra['to']['timestamp']) {
             return null;
             // remove entity from result set
         }
     }
     return true;
 }
开发者ID:quickapps-plugins,项目名称:field,代码行数:18,代码来源:PublishDateField.php

示例9: _getAppBase

 /**
  * Return the content of CakePHP App.base.
  * If the App.base value is false, it returns the generated URL automatically
  * by mimicking how CakePHP add the base to its URL.
  *
  * @return string the application base directory
  */
 protected function _getAppBase()
 {
     $baseUrl = Configure::read('App.base');
     if (!$baseUrl) {
         $request = Router::getRequest(true);
         if (!$request) {
             $baseUrl = '';
         } else {
             $baseUrl = $request->base;
         }
     }
     return $baseUrl . '/';
 }
开发者ID:gintonicweb,项目名称:requirejs,代码行数:20,代码来源:RequireHelper.php

示例10: _getController

 /**
  * {@inheritDoc}
  */
 protected function _getController()
 {
     if (!($request = Router::getRequest(true))) {
         $request = new Request();
     }
     $response = new Response();
     try {
         $controller = new TestAppsErrorController($request, $response);
         $controller->layout = 'banana';
     } catch (\Exception $e) {
         $controller = new Controller($request, $response);
         $controller->viewPath = 'Error';
     }
     return $controller;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:18,代码来源:TestAppsExceptionRenderer.php

示例11: read

 /**
  * Read a value from POST data.
  *
  * It reads the first input and removes that value from the stack,
  * so consecutive readings are supported as follow:
  *
  * **Incoming POST data array**
  *
  * ```php
  * [
  *     'input1' => 'value1',
  *     'input2' => 'value2',
  *     'input3' => 'value3',
  * ]
  * ```
  *
  * **Reading from POST**:
  *
  * ```php
  * $this->read(); // returns "value1"
  * $this->read(); // returns "value2"
  * $this->read(); // returns "value3"
  * $this->read(); // returns false
  * ```
  *
  * @return mixed The value from POST data
  */
 public function read()
 {
     $request = Router::getRequest();
     if (!empty($request) && empty($this->_postData)) {
         $this->_postData = (array) $request->data();
     }
     if (!empty($this->_postData)) {
         $keys = array_keys($this->_postData);
         $first = array_shift($keys);
         $value = $this->_postData[$first];
         unset($this->_postData[$first]);
         return $value;
     }
     return false;
 }
开发者ID:quickapps-plugins,项目名称:cms,代码行数:42,代码来源:WebConsoleInput.php

示例12: createJob

 public static function createJob($data)
 {
     //Fill in current Routing details so the queued email can
     //generate correct absolute urls
     $request = Router::getRequest();
     $data['fullBaseUrl'] = Router::fullBaseUrl() . (empty($request) ? null : $request->base);
     $data['settings']['domain'] = empty($request) ? null : $request->host();
     if (Configure::read('debugEmailRedirect')) {
         if (empty($request)) {
             $loggedInUser = [];
         } else {
             //If we're proxied, then make sure to get *actual* login, not
             //proxied
             $loggedInUser = $request->session()->read('proxy.realUser');
             if (empty($loggedInUser)) {
                 $loggedInUser = $request->session()->read('Auth.User');
             }
         }
         if (empty($loggedInUser['emailAddress'])) {
             $to = 'clubs_dev@byu.edu';
         } else {
             if (empty($loggedInUser['name'])) {
                 $to = $loggedInUser['emailAddress'];
             } else {
                 $to = [$loggedInUser['emailAddress'] => $loggedInUser['name']];
             }
         }
         $originalTo = [];
         $toFields = ['to', 'addTo', 'cc', 'addCC', 'bcc', 'addBcc'];
         foreach ($toFields as $toField) {
             if (!empty($data['settings'][$toField])) {
                 foreach ((array) $data['settings'][$toField] as $originalEmail => $originalName) {
                     if (is_int($originalEmail)) {
                         $originalTo[] = $originalName;
                     } else {
                         $originalTo[] = "{$originalName} <{$originalEmail}>";
                     }
                 }
                 unset($data['settings'][$toField]);
             }
         }
         $data['vars']['originalTo'] = implode(', ', $originalTo);
         $data['settings']['to'] = $to;
     }
     return TableRegistry::get('Queue.QueuedTasks')->createJob('BYUEmail', $data);
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:46,代码来源:QueueBYUEmailTask.php

示例13: beforeDispatch

 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and config/routes.php will be run.
  *
  * @param \Cake\Event\Event $event containing the request, response and additional params
  * @return \Cake\Network\Response|null A response will be returned when a redirect route is encountered.
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     if (Router::getRequest(true) !== $request) {
         Router::setRequestInfo($request);
     }
     try {
         if (empty($request->params['controller'])) {
             $params = Router::parse($request->url, $request->method());
             $request->addParams($params);
         }
     } catch (RedirectException $e) {
         $event->stopPropagation();
         $response = $event->data['response'];
         $response->statusCode($e->getCode());
         $response->header('Location', $e->getMessage());
         return $response;
     }
 }
开发者ID:nrother,项目名称:cakephp,代码行数:26,代码来源:RoutingFilter.php

示例14: user

/**
 * Retrieves current user's information (logged in or not) as an entity object.
 *
 * **Usage:**
 *
 * ```php
 * $user = user();
 * echo user()->name;
 * // prints "Anonymous" if not logged in
 * ```
 * @return \User\Model\Entity\UserSession
 */
function user()
{
    static $user = null;
    if ($user instanceof UserSession) {
        return $user;
    }
    $request = Router::getRequest();
    if ($request && $request->is('userLoggedIn')) {
        $properties = $request->session()->read('Auth.User');
        if (!empty($properties['roles'])) {
            foreach ($properties['roles'] as &$role) {
                unset($role['_joinData']);
                $role = new Entity($role);
            }
        } else {
            $properties['roles'] = [];
        }
        $properties['roles'][] = TableRegistry::get('User.Roles')->get(ROLE_ID_AUTHENTICATED, ['cache' => 'default']);
    } else {
        $properties = ['id' => null, 'name' => __d('user', 'Anonymous'), 'username' => __d('user', 'anonymous'), 'email' => __d('user', '(no email)'), 'locale' => I18n::locale(), 'roles' => [TableRegistry::get('User.Roles')->get(ROLE_ID_ANONYMOUS, ['cache' => 'default'])]];
    }
    $user = new UserSession($properties);
    return $user;
}
开发者ID:quickapps-plugins,项目名称:user,代码行数:36,代码来源:bootstrap.php

示例15: dispatch

 /**
  * Dispatches a Request & Response
  *
  * @param \Cake\Network\Request $request The request to dispatch.
  * @param \Cake\Network\Response $response The response to dispatch.
  * @return \Cake\Network\Response a modified/replaced response.
  */
 public function dispatch(Request $request, Response $response)
 {
     if (Router::getRequest(true) !== $request) {
         Router::pushRequest($request);
     }
     $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
     $request = $beforeEvent->data['request'];
     if ($beforeEvent->result instanceof Response) {
         return $beforeEvent->result;
     }
     // Use the controller built by an beforeDispatch
     // event handler if there is one.
     if (isset($beforeEvent->data['controller'])) {
         $controller = $beforeEvent->data['controller'];
     } else {
         $controller = $this->factory->create($request, $response);
     }
     $response = $this->_invoke($controller);
     if (isset($request->params['return'])) {
         return $response;
     }
     $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
     return $afterEvent->data['response'];
 }
开发者ID:aceat64,项目名称:cakephp,代码行数:31,代码来源:ActionDispatcher.php


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