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


PHP CakeRequest::addDetector方法代码示例

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


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

示例1: _apiRequest

 /**
  * Helper method to create an test API request (with the appropriate detector)
  */
 protected function _apiRequest($params)
 {
     $request = new CakeRequest();
     $request->addParams($params);
     $request->addDetector('api', array('callback' => array('CroogoRouter', 'isApiRequest')));
     return $request;
 }
开发者ID:saydulk,项目名称:croogo,代码行数:10,代码来源:CroogoTestCase.php

示例2: _mockClasses

 /**
  * Helper method to generate and mock all the required
  * classes
  *
  * `$hasField` is a field => bool array with what
  * fields should exist according to 'hasField' model check
  *
  * @param array $hasField
  * @return array
  */
 protected function _mockClasses($hasField = array())
 {
     $CrudSubject = new CrudSubject();
     $Crud = $this->CrudMock->disableOriginalConstructor()->setMethods(array('action'))->getMock();
     $Model = $this->ModelMock->setConstructorArgs(array(array('table' => 'models', 'name' => 'Model', 'ds' => 'test')))->setMethods(array('hasField', 'getAssociated'))->getMock();
     $Model->expects($this->any())->method('getAssociated')->will($this->returnValue(array('Sample' => array(), 'Demo' => array(), 'User' => array())));
     $Model->alias = 'Model';
     $Controller = $this->ControllerMock->disableOriginalConstructor()->setMethods(null)->getMock();
     $Controller->Components = new StdClass();
     $Request = new CakeRequest();
     $Request->addDetector('api', array('callback' => function () {
         return true;
     }));
     $Paginator = $this->PaginatorMock->disableOriginalConstructor()->setMethods(null)->getMock();
     $Controller->Paginator = $Paginator;
     $CrudSubject->set(array('crud' => $Crud, 'request' => $Request, 'controller' => $Controller, 'action' => 'add', 'model' => $Model, 'modelClass' => $Model->name, 'args' => array(), 'query' => array('fields' => null, 'contain' => null)));
     $Action = $this->ActionMock->setConstructorArgs(array($CrudSubject))->setMethods(null)->getMock();
     $Listener = new ApiFieldFilterListener($CrudSubject);
     $Event = new CakeEvent('Test', $CrudSubject);
     $Crud->expects($this->any())->method('action')->will($this->returnValue($Action));
     $i = 0;
     foreach ($hasField as $field => $has) {
         $Model->expects($this->at($i))->method('hasField')->with($field)->will($this->returnValue($has));
         $i++;
     }
     return compact('Crud', 'Model', 'Controller', 'Paginator', 'Request', 'CrudSubject', 'Listener', 'Action', 'Event');
 }
开发者ID:linking-arts,项目名称:furry-goggles,代码行数:37,代码来源:ApiFieldFilterListenerTest.php

示例3: configureRequestDetectors

 /**
  * Configure detectors for API requests
  *
  * Add detectors for ->is('api') and ->is('json') on CakeRequest
  *
  * @return void
  */
 protected function configureRequestDetectors()
 {
     // Add detector for json
     $this->request->addDetector('json', array('callback' => function (CakeRequest $request) {
         // The sure solution is to check if the extension is "json"
         if (isset($request->params['ext']) && $request->params['ext'] === 'json') {
             return true;
         }
         // Or try to sniff out the accept header
         return $request->accepts('application/json');
     }));
     // Generic API check
     $this->request->addDetector('api', array('callback' => function (CakeRequest $request) {
         // Currently only checks if a request is JSON - but allows us to easily add other request formats
         return $request->is('json');
     }));
 }
开发者ID:nodesagency,项目名称:Platform-API-plugin,代码行数:24,代码来源:ApiComponent.php

示例4: testAddDetector

 /**
  * Test adding detectors and having them work.
  *
  * @return void
  */
 public function testAddDetector()
 {
     $request = new CakeRequest('some/path');
     $request->addDetector('compare', array('env' => 'TEST_VAR', 'value' => 'something'));
     $_SERVER['TEST_VAR'] = 'something';
     $this->assertTrue($request->is('compare'), 'Value match failed.');
     $_SERVER['TEST_VAR'] = 'wrong';
     $this->assertFalse($request->is('compare'), 'Value mis-match failed.');
     $request->addDetector('compareCamelCase', array('env' => 'TEST_VAR', 'value' => 'foo'));
     $_SERVER['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');
     $_SERVER['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', array('env' => 'TEST_VAR', 'pattern' => '/^ban.*$/'));
     $_SERVER['TEST_VAR'] = 'banana';
     $this->assertTrue($request->isBanana());
     $_SERVER['TEST_VAR'] = 'wrong value';
     $this->assertFalse($request->isBanana());
     $request->addDetector('mobile', array('options' => array('Imagination')));
     $_SERVER['HTTP_USER_AGENT'] = 'Imagination land';
     $this->assertTrue($request->isMobile());
     $_SERVER['HTTP_USER_AGENT'] = 'iPhone 3.0';
     $this->assertTrue($request->isMobile());
     $request->addDetector('callme', array('env' => 'TEST_VAR', 'callback' => array($this, 'detectCallback')));
     $request->addDetector('index', array('param' => 'action', 'value' => 'index'));
     $request->params['action'] = 'index';
     $this->assertTrue($request->isIndex());
     $request->params['action'] = 'add';
     $this->assertFalse($request->isIndex());
     $request->return = true;
     $this->assertTrue($request->isCallMe());
     $request->return = false;
     $this->assertFalse($request->isCallMe());
     $request->addDetector('extension', array('param' => 'ext', 'options' => array('pdf', 'png', 'txt')));
     $request->params['ext'] = 'pdf';
     $this->assertTrue($request->is('extension'));
     $request->params['ext'] = 'exe';
     $this->assertFalse($request->isExtension());
 }
开发者ID:xMyThoLoGyx,项目名称:centremedicaletp3,代码行数:48,代码来源:CakeRequestTest.php

示例5: testHeadHandled

 /**
  * testHeadHandled
  *
  * Simulate app code having handled the head request appropriately
  *
  * @return void
  */
 public function testHeadHandled()
 {
     $filter = new HttpMethodFilter();
     $response = $this->getMock('CakeResponse', array('_sendHeader'));
     $response->header('Content-length', 123);
     $request = new CakeRequest('controller/action/1');
     $request->addDetector('head', array('callback' => function () {
         return true;
     }));
     $event = new CakeEvent('HttpMethodFilterTest', $this, compact('request', 'response'));
     $this->assertSame($response, $filter->afterDispatch($event), 'The HttpMethod filter should return a response');
     $expected = array('Content-length' => '123');
     $this->assertSame($expected, $response->header(), 'The content header should be set');
     $this->assertSame('', $response->body(), 'The body should remain empty');
 }
开发者ID:linking-arts,项目名称:furry-goggles,代码行数:22,代码来源:HttpMethodFilterTest.php

示例6: testAddDetector

 /**
  * test adding detectors and having them work.
  *
  * @return void
  */
 public function testAddDetector()
 {
     $request = new CakeRequest('some/path');
     $request->addDetector('compare', array('env' => 'TEST_VAR', 'value' => 'something'));
     $_SERVER['TEST_VAR'] = 'something';
     $this->assertTrue($request->is('compare'), 'Value match failed.');
     $_SERVER['TEST_VAR'] = 'wrong';
     $this->assertFalse($request->is('compare'), 'Value mis-match failed.');
     $request->addDetector('banana', array('env' => 'TEST_VAR', 'pattern' => '/^ban.*$/'));
     $_SERVER['TEST_VAR'] = 'banana';
     $this->assertTrue($request->isBanana());
     $_SERVER['TEST_VAR'] = 'wrong value';
     $this->assertFalse($request->isBanana());
     $request->addDetector('mobile', array('options' => array('Imagination')));
     $_SERVER['HTTP_USER_AGENT'] = 'Imagination land';
     $this->assertTrue($request->isMobile());
     $_SERVER['HTTP_USER_AGENT'] = 'iPhone 3.0';
     $this->assertTrue($request->isMobile());
     $request->addDetector('callme', array('env' => 'TEST_VAR', 'callback' => array($this, '_detectCallback')));
     $request->addDetector('index', array('param' => 'action', 'value' => 'index'));
     $request->params['action'] = 'index';
     $this->assertTrue($request->isIndex());
     $request->params['action'] = 'add';
     $this->assertFalse($request->isIndex());
     $request->return = true;
     $this->assertTrue($request->isCallMe());
     $request->return = false;
     $this->assertFalse($request->isCallMe());
 }
开发者ID:nabeelio,项目名称:CakePHP-Base,代码行数:34,代码来源:CakeRequestTest.php

示例7: addDetectors

 /**
  * リクエスト検出器を追加する
  *
  * @param CakeRequest $request リクエスト
  * @return void
  */
 public function addDetectors(CakeRequest $request)
 {
     foreach ($this->getDetectorConfigs() as $name => $callback) {
         $request->addDetector($name, $callback);
     }
 }
开发者ID:naow9y,项目名称:basercms,代码行数:12,代码来源:BcRequestFilter.php

示例8: testFlashMessageSupressed

 /**
  * testFlashMessageSupressed
  *
  * The API listener should suppress flash messages
  * if the request is "API"
  *
  * @return void
  */
 public function testFlashMessageSupressed()
 {
     $Request = new CakeRequest();
     $Request->addDetector('api', array('callback' => function () {
         return true;
     }));
     $subject = new CrudSubject(array('request' => $Request));
     $apiListener = new ApiListener($subject);
     $event = new CakeEvent('Crud.setFlash', $subject);
     $apiListener->setFlash($event);
     $stopped = $event->isStopped();
     $this->assertTrue($stopped, 'Set flash event is expected to be stopped');
 }
开发者ID:linking-arts,项目名称:furry-goggles,代码行数:21,代码来源:ApiListenerTest.php

示例9: addDetectorsToRequest

 /**
  * add an array of detectors to the current CakeRequest
  *
  * @param $request CakeRequest
  * @param $detectors Array. Keys are the detector names. Values will be the detector value
  * @return void
  */
 public function addDetectorsToRequest(CakeRequest $request, $detectors = array())
 {
     foreach ($detectors as $detectorName => $detector) {
         $request->addDetector($detectorName, $detector);
     }
 }
开发者ID:simkimsia,项目名称:utility-components,代码行数:13,代码来源:RequestExtrasHandlerComponent.php


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