當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::isBanana方法代碼示例

本文整理匯總了PHP中Cake\Network\Request::isBanana方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::isBanana方法的具體用法?PHP Request::isBanana怎麽用?PHP Request::isBanana使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Network\Request的用法示例。


在下文中一共展示了Request::isBanana方法的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::isBanana方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。