本文整理汇总了PHP中Cake\Controller\Controller::eventManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::eventManager方法的具体用法?PHP Controller::eventManager怎么用?PHP Controller::eventManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Controller\Controller
的用法示例。
在下文中一共展示了Controller::eventManager方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInnerComponentsAreNotEnabled
/**
* test that component components are not enabled in the collection.
*
* @return void
*/
public function testInnerComponentsAreNotEnabled()
{
$mock = $this->getMock('Cake\\Event\\EventManager');
$controller = new Controller();
$controller->eventManager($mock);
$mock->expects($this->once())->method('on')->with($this->isInstanceOf('TestApp\\Controller\\Component\\AppleComponent'));
$Collection = new ComponentRegistry($controller);
$Apple = $Collection->load('Apple');
$this->assertInstanceOf('TestApp\\Controller\\Component\\OrangeComponent', $Apple->Orange, 'class is wrong');
}
示例2: __construct
/**
* Constructor.
*
* @param \Cake\Controller\Controller $Controller Controller instance.
*/
public function __construct(Controller $Controller = null)
{
if ($Controller) {
$this->_Controller = $Controller;
$this->eventManager($Controller->eventManager());
}
}
示例3: __construct
/**
* Constructor
*
* @param \Cake\Controller\ComponentRegistry $collection Component Registry
* @param array $config Array of configuration settings.
*/
public function __construct(ComponentRegistry $collection, $config = [])
{
$this->_controller = $collection->getController();
$this->_eventManager = $this->_controller->eventManager();
parent::__construct($collection, $config);
$this->_createCrudComponentInstance();
}
示例4: __construct
/**
* Constructor
*
* @param \Cake\Controller\ComponentRegistry $collection A ComponentCollection this component
* can use to lazy load its components.
* @param array $config Array of configuration settings.
*/
public function __construct(ComponentRegistry $collection, $config = [])
{
$config += ['actions' => [], 'listeners' => []];
$config['actions'] = $this->normalizeArray($config['actions']);
$config['listeners'] = $this->normalizeArray($config['listeners']);
$this->_controller = $collection->getController();
$this->_eventManager = $this->_controller->eventManager();
parent::__construct($collection, $config);
}
示例5: controllerSpy
/**
* Add additional event spies to the controller/view event manager.
*
* @param \Cake\Event\Event $event A dispatcher event.
* @return void
*/
public function controllerSpy($event)
{
if (empty($event->data['controller'])) {
return;
}
$this->_controller = $event->data['controller'];
$events = $this->_controller->eventManager();
$events->attach(function ($event, $viewFile) {
$this->_viewName = $viewFile;
}, 'View.beforeRender');
$events->attach(function ($event, $viewFile) {
$this->_layoutName = $viewFile;
}, 'View.beforeLayout');
}
示例6: testRedirectBeforeRedirectListenerReturnFalse
/**
* test that beforeRedirect callback returning false in controller
*
* @return void
*/
public function testRedirectBeforeRedirectListenerReturnFalse()
{
$Response = $this->getMock('Cake\\Network\\Response', ['stop', 'header']);
$Controller = new Controller(null, $Response);
$Controller->eventManager()->attach(function ($event, $url, $response) {
return false;
}, 'Controller.beforeRedirect');
$Controller->response->expects($this->never())->method('stop');
$Controller->response->expects($this->never())->method('header');
$Controller->response->expects($this->never())->method('statusCode');
$result = $Controller->redirect('http://cakephp.org');
$this->assertNull($result);
}
示例7: setController
/**
* Set the controller associated with the collection.
*
* @param \Cake\Controller\Controller $controller Controller instance.
* @return void
*/
public function setController(Controller $controller)
{
$this->_Controller = $controller;
$this->eventManager($controller->eventManager());
}
示例8: testRedirectBeforeRedirectListenerReturnResponse
public function testRedirectBeforeRedirectListenerReturnResponse()
{
$Response = $this->getMockBuilder('Cake\\Network\\Response')->setMethods(['stop', 'header', 'statusCode'])->getMock();
$Controller = new Controller(null, $Response);
$newResponse = new Response();
$Controller->eventManager()->on('Controller.beforeRedirect', function ($event, $url, $response) use($newResponse) {
return $newResponse;
});
$result = $Controller->redirect('http://cakephp.org');
$this->assertSame($newResponse, $result);
}