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


PHP Request::isCallMe方法代码示例

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


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

示例1: testAddDetector

 /**
  * Test adding detectors and having them work.
  *
  * @return void
  */
 public function testAddDetector()
 {
     $request = new Request();
     Request::addDetector('closure', function ($request) {
         return true;
     });
     $this->assertTrue($request->is('closure'));
     Request::addDetector('get', function ($request) {
         return $request->env('REQUEST_METHOD') === 'GET';
     });
     $request->env('REQUEST_METHOD', 'GET');
     $this->assertTrue($request->is('get'));
     Request::addDetector('compare', ['env' => 'TEST_VAR', 'value' => 'something']);
     $request->env('TEST_VAR', 'something');
     $this->assertTrue($request->is('compare'), 'Value match failed.');
     $request->env('TEST_VAR', 'wrong');
     $this->assertFalse($request->is('compare'), 'Value mis-match failed.');
     Request::addDetector('compareCamelCase', ['env' => 'TEST_VAR', 'value' => 'foo']);
     $request->env('TEST_VAR', 'foo');
     $this->assertTrue($request->is('compareCamelCase'), 'Value match failed.');
     $this->assertTrue($request->is('comparecamelcase'), 'detectors should be case insensitive');
     $this->assertTrue($request->is('COMPARECAMELCASE'), 'detectors should be case insensitive');
     $request->env('TEST_VAR', 'not foo');
     $this->assertFalse($request->is('compareCamelCase'), 'Value match failed.');
     $this->assertFalse($request->is('comparecamelcase'), 'detectors should be case insensitive');
     $this->assertFalse($request->is('COMPARECAMELCASE'), 'detectors should be case insensitive');
     Request::addDetector('banana', ['env' => 'TEST_VAR', 'pattern' => '/^ban.*$/']);
     $request->env('TEST_VAR', 'banana');
     $this->assertTrue($request->isBanana());
     $request->env('TEST_VAR', 'wrong value');
     $this->assertFalse($request->isBanana());
     Request::addDetector('mobile', ['env' => 'HTTP_USER_AGENT', 'options' => ['Imagination']]);
     $request->env('HTTP_USER_AGENT', 'Imagination land');
     $this->assertTrue($request->isMobile());
     Request::addDetector('index', ['param' => 'action', 'value' => 'index']);
     $request->params['action'] = 'index';
     $request->clearDetectorCache();
     $this->assertTrue($request->isIndex());
     $request->params['action'] = 'add';
     $request->clearDetectorCache();
     $this->assertFalse($request->isIndex());
     Request::addDetector('callme', [$this, 'detectCallback']);
     $request->return = true;
     $request->clearDetectorCache();
     $this->assertTrue($request->isCallMe());
     Request::addDetector('extension', ['param' => '_ext', 'options' => ['pdf', 'png', 'txt']]);
     $request->params['_ext'] = 'pdf';
     $request->clearDetectorCache();
     $this->assertTrue($request->is('extension'));
     $request->params['_ext'] = 'exe';
     $request->clearDetectorCache();
     $this->assertFalse($request->isExtension());
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:58,代码来源:RequestTest.php


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