本文整理汇总了PHP中Cake\Event\EventManager::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::instance方法的具体用法?PHP EventManager::instance怎么用?PHP EventManager::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Event\EventManager
的用法示例。
在下文中一共展示了EventManager::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRender
/**
* beforeRender event.
*
* @param Event $event Event.
* @return void
*/
public function beforeRender(Event $event)
{
$this->set('authUser', $this->authUser);
$this->set('title', $this->name);
$event = new Event('CakeAdmin.Controller.beforeRender', $this);
EventManager::instance()->dispatch($event);
}
示例2: instance
/**
* Returns the globally available instance of a UnionEventManager.
*
* @param null $manager
* @return CakeEventManager
*/
public static function instance($manager = null)
{
if (empty(self::$_generalManager)) {
return parent::instance(new EventManager());
}
return parent::instance($manager);
}
示例3: setUp
/**
* startTest
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->ImageStorage = TableRegistry::get('Burzum/FileStorage.ImageStorage');
$listener = new LocalListener();
EventManager::instance()->on($listener);
}
示例4: bake
/**
* {@inheritDoc}
*/
public function bake($name)
{
EventManager::instance()->on('Bake.initialize', function (Event $event) {
$event->subject->loadHelper('Migrations.Migration');
});
return parent::bake($name);
}
示例5: _before
public function _before(TestCase $test)
{
if (method_exists($test, 'getTestClass')) {
$this->testCase = $test->getTestClass();
} else {
$this->testCase = $test;
}
if (!isset($this->testCase->autoFixtures)) {
$this->testCase->autoFixtures = $this->config['autoFixtures'];
}
if (!isset($this->testCase->dropTables)) {
$this->testCase->dropTables = $this->config['dropTables'];
}
if (!isset($this->testCase->cleanUpInsertedRecords)) {
$this->testCase->cleanUpInsertedRecords = $this->config['cleanUpInsertedRecords'];
}
EventManager::instance(new EventManager());
$this->fixtureManager = new FixtureManager();
if ($this->testCase->autoFixtures) {
if (!isset($this->testCase->fixtures)) {
$this->testCase->fixtures = [];
}
$this->loadFixtures($this->testCase->fixtures);
}
$this->snapshotApplication();
}
示例6: authorize
/**
* @return \Cake\Network\Response|void
* @throws \League\OAuth2\Server\Exception\InvalidGrantException
*/
public function authorize()
{
if (!($authParams = $this->OAuth->checkAuthParams('authorization_code'))) {
return;
}
if (!$this->Auth->user()) {
$query = $this->request->query;
$query['redir'] = 'oauth';
return $this->redirect(['plugin' => false, 'controller' => 'Users', 'action' => 'login', '?' => $query]);
}
$event = new Event('OAuthServer.beforeAuthorize', $this);
EventManager::instance()->dispatch($event);
if (is_array($event->result)) {
$this->set($event->result);
}
if ($this->request->is('post') && $this->request->data['authorization'] === 'Approve') {
$ownerModel = isset($this->request->data['owner_model']) ? $this->request->data['owner_model'] : 'Users';
$ownerId = isset($this->request->data['owner_id']) ? $this->request->data['owner_id'] : $this->Auth->user('id');
$redirectUri = $this->OAuth->Server->getGrantType('authorization_code')->newAuthorizeRequest($ownerModel, $ownerId, $authParams);
$event = new Event('OAuthServer.afterAuthorize', $this);
EventManager::instance()->dispatch($event);
return $this->redirect($redirectUri);
} elseif ($this->request->is('post')) {
$event = new Event('OAuthServer.afterDeny', $this);
EventManager::instance()->dispatch($event);
$error = new AccessDeniedException();
$redirectUri = new RedirectUri($authParams['redirect_uri'], ['error' => $error->errorType, 'message' => $error->getMessage()]);
return $this->redirect($redirectUri);
}
$this->set('authParams', $authParams);
$this->set('user', $this->Auth->user());
}
示例7: testProcessVersion
/**
* testProcessVersion
*
* @return void
*/
public function testProcessVersion()
{
$entity = $this->Image->newEntity(['foreign_key' => 'test-1', 'model' => 'Test', 'file' => ['name' => 'titus.jpg', 'size' => 332643, 'tmp_name' => Plugin::path('Burzum/FileStorage') . DS . 'tests' . DS . 'Fixture' . DS . 'File' . DS . 'titus.jpg', 'error' => 0]], ['accessibleFields' => ['*' => true]]);
$this->Image->save($entity);
$result = $this->Image->find()->where(['id' => $entity->id])->first();
$this->assertTrue(!empty($result) && is_a($result, '\\Cake\\ORM\\Entity'));
$this->assertTrue(file_exists($this->testPath . $result['path']));
$path = $this->testPath . $result['path'];
$Folder = new Folder($path);
$folderResult = $Folder->read();
$this->assertEquals(count($folderResult[1]), 3);
Configure::write('FileStorage.imageSizes.Test', array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200))));
StorageUtils::generateHashes();
$Event = new Event('ImageVersion.createVersion', $this->Image, array('record' => $result, 'storage' => StorageManager::adapter('Local'), 'operations' => array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200)))));
EventManager::instance()->dispatch($Event);
$path = $this->testPath . $result['path'];
$Folder = new Folder($path);
$folderResult = $Folder->read();
$this->assertEquals(count($folderResult[1]), 4);
$Event = new Event('ImageVersion.removeVersion', $this->Image, array('record' => $result, 'storage' => StorageManager::adapter('Local'), 'operations' => array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200)))));
EventManager::instance()->dispatch($Event);
$path = $this->testPath . $result['path'];
$Folder = new Folder($path);
$folderResult = $Folder->read();
$this->assertEquals(count($folderResult[1]), 3);
}
示例8: _detachListeners
/**
* Unloads all registered listeners that were attached using the
* "_attachListeners()" method.
*
* @return void
*/
protected function _detachListeners()
{
$EventManager = EventManager::instance();
foreach ($this->_listeners as $listener) {
$EventManager->detach($listener);
}
}
示例9: handleEvents
/**
* Attaches to Event topics and attaches them to the corresponding event handlers
*
* @return void
*/
public function handleEvents()
{
if (defined('PHPUNIT_TESTSUITE') == 1) {
return;
}
$manager = EventManager::instance();
$manager->attach([$this, 'onForgotPassword'], 'Users.forgot_password');
}
示例10: bake
/**
* {@inheritDoc}
*/
public function bake($name)
{
$collection = $this->getCollection($this->connection);
EventManager::instance()->on('Bake.initialize', function (Event $event) use($collection) {
$event->subject->loadHelper('Migrations.Migration', ['collection' => $collection]);
});
return parent::bake($name);
}
示例11: __construct
/**
* Constructor
*
* @param Request|null $request
* @param Response|null $response
* @param EventManager|null $eventManager
* @param array $viewOptions
*/
public function __construct(Request $request = null, Response $response = null, EventManager $eventManager = null, array $viewOptions = [])
{
if ($eventManager === null) {
$eventManager = EventManager::instance();
}
$this->_templatePath = Configure::read('App.paths.templates')[0];
parent::__construct($request, $response, $eventManager, $viewOptions);
}
示例12: setUp
/**
* {@inheritDoc}
*/
public function setUp()
{
$eventManagerInstance = EventManager::instance();
parent::setUp();
EventManager::instance($eventManagerInstance);
$this->session(mockUserSession());
include QUICKAPPS_CORE . '/config/routes_site.php';
}
示例13: findAuth
/**
* Costum Auth finder method
*
* @param array $config Table Configuration.
*
* @return void
*/
public function findAuth(\Cake\ORM\Query $query, array $options)
{
$event = new Event('Lil.authFinder', $this, [$query, $options]);
EventManager::instance()->dispatch($event);
if (!empty($event->result)) {
$query = $event->result;
}
return $query;
}
示例14: getLinkTypes
/**
* Get available link types via an Event trigger
* This fetches avilable Links from all activated Plugins.
*
* @return array
*/
public function getLinkTypes()
{
$event = new Event('Wasabi.Backend.MenuItems.getLinkTypes', $this);
EventManager::instance()->dispatch($event);
$typeExternal = ['type' => 'external'];
$typeCustom = ['type' => 'custom'];
$event->result[__d('wasabi_core', 'General')] = [json_encode($typeExternal) => __d('wasabi_core', 'External Link'), json_encode($typeCustom) => __d('wasabi_core', 'Custom Controller Action')];
return $event->result;
}
示例15: setUp
/**
* [setUp description]
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->resetReflectionCache();
$this->_eventManager = EventManager::instance();
$existing = Configure::read('App.paths.templates');
$existing[] = Plugin::path('Crud') . 'tests/App/Template/';
Configure::write('App.paths.templates', $existing);
}