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


PHP Request::env方法代码示例

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


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

示例1: _testEnabled

 private function _testEnabled($method = 'GET')
 {
     $request = new Request();
     $request->env('REQUEST_METHOD', $method);
     $request->here = '/pages/home';
     $response = new Response();
     $View = new View($request, $response);
     $View->loadHelper('ViewMemcached.ViewMemcached', ['cacheConfig' => TEST_CACHE_CONFIG]);
     $View->viewPath = 'Pages';
     $View->set('test', 'value');
     $View->render('home', 'default');
     return $View->ViewMemcached->enabled();
 }
开发者ID:chnvcode,项目名称:cakephp-viewmemcached,代码行数:13,代码来源:ViewMemcachedHelperTest.php

示例2: testAutoPostRedirectRefererNotWhitelisted

 /**
  * @return void
  */
 public function testAutoPostRedirectRefererNotWhitelisted()
 {
     $this->request->env('HTTP_REFERER', 'http://localhost/my_controller/wrong');
     $is = $this->Controller->Common->autoPostRedirect(['controller' => 'MyController', 'action' => 'foo'], true);
     $is = $this->Controller->response->header();
     $this->assertSame('http://localhost/my_controller/foo', $is['Location']);
     $this->assertSame(302, $this->Controller->response->statusCode());
 }
开发者ID:dereuromark,项目名称:cakephp-tools,代码行数:11,代码来源:CommonComponentTest.php

示例3: testAuthenticateTokenHeader

 /**
  * test authenticate token as request header
  *
  * @return void
  */
 public function testAuthenticateTokenHeader()
 {
     $request = new Request('posts/index');
     $expected = ['id' => 1, 'user_name' => 'mariano', 'email' => 'mariano@example.com', 'token' => '12345', 'created' => new Time('2007-03-17 01:16:23'), 'updated' => new Time('2007-03-17 01:18:31')];
     $request->env('HTTP_X_APITOKEN', '12345');
     $result = $this->auth->getUser($request, $this->response);
     $this->assertEquals($expected, $result);
     $request->env('HTTP_X_APITOKEN', '66666');
     $result = $this->auth->getUser($request, $this->response);
     $this->assertFalse($result);
 }
开发者ID:friendsofcake,项目名称:authenticate,代码行数:16,代码来源:TokenAuthenticateTest.php

示例4: setUp

 /**
  * setup create a request object to get out of router later.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     $request = new Request();
     $request->base = '';
     $request->env('HTTP_REFERER', '/referer');
     Router::setRequestInfo($request);
     Configure::write('debug', true);
     $this->_logger = $this->getMock('Psr\\Log\\LoggerInterface');
     Log::reset();
     Log::config('error_test', ['engine' => $this->_logger]);
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:18,代码来源:ErrorHandlerTest.php

示例5: startup

 /**
  * Startup event to trace the user on the website.
  *
  * @param Event $event The event that was fired.
  *
  * @return void
  */
 public function startup(Event $event)
 {
     if (empty($this->_session->id())) {
         $this->_session->start();
         return;
     }
     $sessions = TableRegistry::get('Sessions');
     $prefix = isset($this->_request['prefix']) ? $this->_request['prefix'] . '/' : '';
     $controller = $prefix . $this->_request['controller'];
     $action = $this->_request['action'];
     $params = serialize($this->_request->pass);
     $expires = time() + ini_get('session.gc_maxlifetime');
     //@codingStandardsIgnoreStart
     $user_id = $this->_session->read('Auth.User.id');
     $user_agent = $this->_request->env('HTTP_USER_AGENT');
     $user_ip = $this->_request->clientIp();
     $full_url = $this->_request->url;
     //@codingStandardIgnoreEnd
     $modified = new Time();
     $record = compact('controller', 'action', 'params', 'expires', 'user_id', 'user_agent', 'user_ip', 'full_url', 'modified');
     $record[$sessions->primaryKey()] = $this->_session->id();
     $sessions->save(new Entity($record));
 }
开发者ID:Xety,项目名称:Xeta,代码行数:30,代码来源:SessionsActivityComponent.php

示例6: testParamsRedirect

 public function testParamsRedirect()
 {
     $request = new Request(['url' => 'controller_posts/index', 'action' => 'index', '_method' => 'POST']);
     $request->env('REQUEST_METHOD', 'POST');
     $request->action = 'index';
     $request->data['Filter'] = ['Posts' => ['title' => 'foo', 'body' => 'bar', 'multi' => [1, 2]]];
     $controller = new Controller($request);
     $controller->listFilters = ['index' => ['fields' => ['Posts.title' => ['searchType' => 'wildcard', 'options' => []], 'Posts.body' => ['searchType' => 'wildcard'], 'Posts.multi' => ['searchType' => 'multipleselect', 'options' => [1 => 'one', 2 => 'two']]]]];
     $ListFilter = new ListFilterComponent($controller->components(), []);
     $event = new Event('Controller.startup', $controller);
     $ListFilter->startup($event);
     $this->assertEquals(array_keys($controller->listFilters['index']['fields']), array_keys($ListFilter->getFilters()['fields']));
     // Check if the request is being redirected properly
     $redirectUrl = parse_url($controller->response->header()['Location']);
     $this->assertEquals(urldecode($redirectUrl['query']), 'Filter-Posts-title=foo&Filter-Posts-body=bar&Filter-Posts-multi[0]=1&Filter-Posts-multi[1]=2');
 }
开发者ID:codekanzlei,项目名称:cake-list-filter,代码行数:16,代码来源:ListFilterComponentTest.php

示例7: _getToken

 /**
  * Get token from header or query string.
  *
  * @param \Cake\Network\Request $request Request object.
  * @return string|bool Token string if found else false.
  */
 protected function _getToken($request)
 {
     $token = $request->env('HTTP_AUTHORIZATION');
     // @codeCoverageIgnoreStart
     if (!$token && function_exists('getallheaders')) {
         $headers = array_change_key_case(getallheaders());
         if (isset($headers['authorization']) && substr($headers['authorization'], 0, 7) === 'Bearer ') {
             $token = $headers['authorization'];
         }
     }
     // @codeCoverageIgnoreEnd
     if ($token) {
         return substr($token, 7);
     }
     if (!empty($this->_config['parameter']) && isset($request->query[$this->_config['parameter']])) {
         $token = $request->query($this->_config['parameter']);
     }
     return $token ? $token : false;
 }
开发者ID:oxenti,项目名称:user,代码行数:25,代码来源:JwtComponent.php

示例8: _deliverAsset

 /**
  * Sends an asset file to the client
  *
  * @param \Cake\Network\Request $request The request object to use.
  * @param \Cake\Network\Response $response The response object to use.
  * @param string $assetFile Path to the asset file in the file system
  * @param string $ext The extension of the file to determine its mime type
  * @return void
  */
 protected function _deliverAsset(Request $request, Response $response, $assetFile, $ext)
 {
     $compressionEnabled = $response->compress();
     if ($response->type($ext) === $ext) {
         $contentType = 'application/octet-stream';
         $agent = $request->env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $response->type($contentType);
     }
     if (!$compressionEnabled) {
         $response->header('Content-Length', filesize($assetFile));
     }
     // $response->cache(filemtime($assetFile), $this->_cacheTime);
     $response->sendHeaders();
     readfile($assetFile);
     if ($compressionEnabled) {
         ob_end_flush();
     }
 }
开发者ID:scherersoftware,项目名称:cake-cms,代码行数:30,代码来源:WidgetAssetFilter.php

示例9: requestedWith

 /**
  * Determines the content type of the data the client has sent (i.e. in a POST request)
  *
  * @param string|array $type Can be null (or no parameter), a string type name, or an array of types
  * @return mixed If a single type is supplied a boolean will be returned. If no type is provided
  *   The mapped value of CONTENT_TYPE will be returned. If an array is supplied the first type
  *   in the request content type will be returned.
  */
 public function requestedWith($type = null)
 {
     if (!$this->request->is('post') && !$this->request->is('put')) {
         return null;
     }
     if (is_array($type)) {
         foreach ($type as $t) {
             if ($this->requestedWith($t)) {
                 return $t;
             }
         }
         return false;
     }
     list($contentType) = explode(';', $this->request->env('CONTENT_TYPE'));
     if ($contentType === '') {
         list($contentType) = explode(';', $this->request->header('CONTENT_TYPE'));
     }
     if (!$type) {
         return $this->response->mapType($contentType);
     }
     if (is_string($type)) {
         return $type === $this->response->mapType($contentType);
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:32,代码来源:RequestHandlerComponent.php

示例10: testAuthenticateFailReChallenge

    /**
     * test scope failure.
     *
     * @expectedException \Cake\Network\Exception\UnauthorizedException
     * @expectedExceptionCode 401
     * @return void
     */
    public function testAuthenticateFailReChallenge()
    {
        $this->auth->config('scope.username', 'nate');
        $request = new Request(['url' => 'posts/index', 'environment' => ['REQUEST_METHOD' => 'GET']]);
        $request->addParams(array('pass' => array()));
        $digest = <<<DIGEST
Digest username="mariano",
realm="localhost",
nonce="123",
uri="/dir/index.html",
qop=auth,
nc=1,
cnonce="123",
response="6629fae49393a05397450978507c4ef1",
opaque="123abc"
DIGEST;
        $request->env('PHP_AUTH_DIGEST', $digest);
        $this->auth->unauthenticated($request, $this->response);
    }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:26,代码来源:DigestAuthenticateTest.php

示例11: _deliverCacheFile

 /**
  * Sends an asset file to the client
  *
  * @param \Cake\Network\Request $request The request object to use.
  * @param \Cake\Network\Response $response The response object to use.
  * @param string $assetFile Path to the asset file in the file system
  * @param string $ext The extension of the file to determine its mime type
  * @return void
  */
 protected function _deliverCacheFile(Request $request, Response $response, $file, $ext)
 {
     $compressionEnabled = $response->compress();
     if ($response->type($ext) === $ext) {
         $contentType = 'application/octet-stream';
         $agent = $request->env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $response->type($contentType);
     }
     if (!$compressionEnabled) {
         $response->header('Content-Length', filesize($file));
     }
     $content = file_get_contents($file);
     $cacheInfo = $this->extractCacheInfo($content);
     $modifiedTime = filemtime($file);
     $cacheTime = $cacheInfo['time'];
     if (!$cacheTime) {
         $cacheTime = $this->_cacheTime;
     }
     $response->cache($modifiedTime, $cacheTime);
     $response->type($cacheInfo['ext']);
     if (Configure::read('debug') || $this->config('debug')) {
         if ($cacheInfo['ext'] === 'html') {
             $content = '<!--created:' . $modifiedTime . '-->' . $content;
         }
     }
     $response->body($content);
 }
开发者ID:jxav,项目名称:cakephp-cache,代码行数:39,代码来源:CacheFilter.php

示例12: get_server_value

 /**
  * Get a $_SERVER variable value.
  * 
  * Get the value even if the $_SERVER index name is prefixed by some "REDIRECT_" (due to mod_rewrite) 
  * 
  * @param string $name
  */
 protected function get_server_value(Request $request, $attribute_name)
 {
     $repeat = 0;
     $value = null;
     while (!isset($value) && $repeat < 5) {
         $value = $request->env($this->mod_rewrite_prefix . $attribute_name);
         if (isset($value)) {
             return $value;
         }
         $attribute_name = $this->mod_rewrite_prefix . $attribute_name;
         $repeat++;
     }
     return null;
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:21,代码来源:ShibbolethAuthenticate.php

示例13: testGenerateWithSslInSsl

 /**
  * Test ssl option when the current request is ssl.
  *
  * @return void
  */
 public function testGenerateWithSslInSsl()
 {
     Router::connect('/:controller/:action/*');
     $request = new Request();
     $request->env('HTTP_HOST', 'localhost');
     $request->env('HTTPS', 'on');
     Router::pushRequest($request->addParams(['plugin' => null, 'controller' => 'images', 'action' => 'index'])->addPaths(['base' => '', 'here' => '/images/index', 'webroot' => '/']));
     $result = Router::url(['_ssl' => false]);
     $this->assertEquals('http://localhost/images/index', $result);
     $result = Router::url(['_ssl' => true]);
     $this->assertEquals('https://localhost/images/index', $result);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:17,代码来源:RouterTest.php

示例14: testAuthenticateNoCookie

 /**
  * test
  *
  * @return void
  */
 public function testAuthenticateNoCookie()
 {
     $request = new Request('/');
     $request->env('HTTP_USER_AGENT', 'user-agent');
     $mockCookie = $this->getMockBuilder('Cake\\Controller\\Component\\CookieComponent')->disableOriginalConstructor()->setMethods(['check', 'read'])->getMock();
     $mockCookie->expects($this->once())->method('read')->with('remember_me')->will($this->returnValue(null));
     $registry = new ComponentRegistry($this->controller);
     $registry->set('Cookie', $mockCookie);
     $this->rememberMe = new RememberMeAuthenticate($registry);
     $result = $this->rememberMe->authenticate($request, new Response());
     $this->assertFalse($result);
 }
开发者ID:cakedc,项目名称:users,代码行数:17,代码来源:RememberMeAuthenticateTest.php

示例15: testCors

 /**
  * Test CORS
  *
  * @dataProvider corsData
  * @param Request $request
  * @param string $origin
  * @param string|array $domains
  * @param string|array $methods
  * @param string|array $headers
  * @param string|bool $expectedOrigin
  * @param string|bool $expectedMethods
  * @param string|bool $expectedHeaders
  * @return void
  */
 public function testCors($request, $origin, $domains, $methods, $headers, $expectedOrigin, $expectedMethods = false, $expectedHeaders = false)
 {
     $request->env('HTTP_ORIGIN', $origin);
     $response = $this->getMock('Cake\\Network\\Response', ['header']);
     $method = $response->expects(!$expectedOrigin ? $this->never() : $this->at(0))->method('header');
     $expectedOrigin && $method->with('Access-Control-Allow-Origin', $expectedOrigin ? $expectedOrigin : $this->anything());
     $i = 1;
     if ($expectedMethods) {
         $response->expects($this->at($i++))->method('header')->with('Access-Control-Allow-Methods', $expectedMethods ? $expectedMethods : $this->anything());
     }
     if ($expectedHeaders) {
         $response->expects($this->at($i++))->method('header')->with('Access-Control-Allow-Headers', $expectedHeaders ? $expectedHeaders : $this->anything());
     }
     $response->cors($request, $domains, $methods, $headers);
     unset($_SERVER['HTTP_ORIGIN']);
 }
开发者ID:kfer10,项目名称:excel,代码行数:30,代码来源:ResponseTest.php


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