instance() 공개 정적인 메소드

If called with the first parameter, it will be set as the globally available instance
public static instance ( CakeEventManager $manager = null ) : CakeEventManager
$manager CakeEventManager
리턴 CakeEventManager the global event manager
 public function changeStatus(Model $Model, $status, $id = null, $force = false)
 {
     if ($id === null) {
         $id = $Model->getID();
     }
     if ($id === false) {
         return false;
     }
     $force = true;
     $Model->id = $id;
     if (!$Model->exists()) {
         throw new NotFoundException();
     }
     if ($force !== true) {
         $modelData = $Model->read();
         if ($modelData[$Model->alias]['status'] === $status) {
             CakeLog::write(LOG_WARNING, __d('webshop', 'The status of %1$s with id %2$d is already set to %3$s. Not making a change', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
             return false;
         }
     } else {
         CakeLog::write(LOG_WARNING, __d('webshop', 'Status change of %1$s with id %2$d is being forced to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
     }
     $Model->saveField('status', $status);
     CakeLog::write(LOG_INFO, __d('webshop', 'Changed status of %1$s with id %2$d to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
     $eventData = array();
     $eventData[Inflector::underscore($Model->name)]['id'] = $id;
     $eventData[Inflector::underscore($Model->name)]['status'] = $status;
     $overallEvent = new CakeEvent($Model->name . '.statusChanged', $this, $eventData);
     $specificEvent = new CakeEvent($Model->name . '.statusChangedTo' . Inflector::camelize($status), $this, $eventData);
     CakeEventManager::instance()->dispatch($overallEvent);
     CakeEventManager::instance()->dispatch($specificEvent);
     return true;
 }
예제 #2
0
 public function onProductBought($event)
 {
     $this->Product->id = $event->data['product']['id'];
     $this->Product->recursive = 2;
     $product = $this->Product->read();
     if ($product[$this->Product->WebhostingProduct->alias]['id'] === null) {
         return;
     }
     $this->Product->WebhostingProduct->HostGroup->id = $product['HostGroup']['id'];
     $this->Product->WebhostingProduct->HostGroup->recursive = 2;
     $hostGroup = $this->Product->WebhostingProduct->HostGroup->read();
     $WebhostingProvider = BasicWebhostingProvider::get($hostGroup['Host'][0]['Provider']['class']);
     $webhostingPackage = $this->WebhostingPackage->createFromWebhostingProduct($product['WebhostingProduct'], $event->data['customer']['id'], $hostGroup['Host'][0]['id']);
     $webhostingDetails = $WebhostingProvider->createPackage($webhostingPackage['WebhostingPackage']['id']);
     if ($webhostingDetails === false) {
         CakeLog::write(LOG_ERROR, __d('pltfrm', 'Webhosting provider %1$s could not create webhosting package with id %2$d owned by %3$s', $hostGroup['Host'][0]['Provider']['class'], $webhostingPackage['WebhostingPackage']['id'], $webhostingPackage['Customer']['name']), array('webhosting', 'pltfrm'));
         return false;
     }
     $eventData = array();
     $eventData['webhosting']['id'] = $webhostingPackage['WebhostingPackage']['id'];
     $eventData['details'] = $webhostingDetails;
     $eventData['metadata'] = array();
     $webhostingCreatedEvent = new CakeEvent('Webhosting.created', $this, $eventData);
     CakeEventManager::instance()->dispatch($webhostingCreatedEvent);
     CakeLog::write(LOG_INFO, __d('pltfrm', 'Webhosting provider %1$s created webhosting package with id %2$d', $hostGroup['Host'][0]['Provider']['class'], $webhostingPackage['WebhostingPackage']['id']), array('webhosting', 'pltfrm'));
     if (isset($event->data['order'])) {
         $this->OrderProduct->changeStatus('delivered', $event->data['order']['product_id']);
     }
     return true;
 }
 /**
  * Import exchange rate for the euro.
  */
 public function import()
 {
     $exchangeRateImporter = new EcbExchangeRateImporter();
     $exchangeRateImporter->import();
     $event = new CakeEvent('ExchangeRateImport.completed', $this);
     CakeEventManager::instance()->dispatch($event);
 }
 /**
  * testProcessVersion
  *
  * @return void
  */
 public function testProcessVersion()
 {
     $this->Image->create();
     $result = $this->Image->save(array('foreign_key' => 'test-1', 'model' => 'Test', 'file' => array('name' => 'titus.jpg', 'size' => 332643, 'tmp_name' => CakePlugin::path('FileStorage') . DS . 'Test' . DS . 'Fixture' . DS . 'File' . DS . 'titus.jpg', 'error' => 0)));
     $result = $this->Image->find('first', array('conditions' => array('id' => $this->Image->getLastInsertId())));
     $this->assertTrue(!empty($result) && is_array($result));
     $this->assertTrue(file_exists($this->testPath . $result['ImageStorage']['path']));
     $path = $this->testPath . $result['ImageStorage']['path'];
     $Folder = new Folder($path);
     $folderResult = $Folder->read();
     $this->assertEqual(count($folderResult[1]), 3);
     Configure::write('Media.imageSizes.Test', array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200))));
     ClassRegistry::init('FileStorage.ImageStorage')->generateHashes();
     $Event = new CakeEvent('ImageVersion.createVersion', $this->Image, array('record' => $result, 'storage' => StorageManager::adapter('Local'), 'operations' => array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200)))));
     CakeEventManager::instance()->dispatch($Event);
     $path = $this->testPath . $result['ImageStorage']['path'];
     $Folder = new Folder($path);
     $folderResult = $Folder->read();
     $this->assertEqual(count($folderResult[1]), 4);
     $Event = new CakeEvent('ImageVersion.removeVersion', $this->Image, array('record' => $result, 'storage' => StorageManager::adapter('Local'), 'operations' => array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200)))));
     CakeEventManager::instance()->dispatch($Event);
     $path = $this->testPath . $result['ImageStorage']['path'];
     $Folder = new Folder($path);
     $folderResult = $Folder->read();
     $this->assertEqual(count($folderResult[1]), 3);
 }
예제 #5
0
 /**
  * Returns the globally available instance of a CroogoEventManager
  * @return CroogoEventManager the global event manager
  */
 public static function instance($manager = null)
 {
     if (empty(self::$_generalManager)) {
         return parent::instance(new CroogoEventManager());
     }
     return parent::instance($manager);
 }
예제 #6
0
파일: Hurad.php 프로젝트: hurad/hurad
 /**
  * Dispatch event
  *
  * @param string $name    Name of the event
  * @param object $subject the object that this event applies to (usually the object that is generating the event)
  * @param mixed  $data    any value you wish to be transported with this event to it can be read by listeners
  */
 public static function dispatchEvent($name, $subject = null, $data = [])
 {
     $event = new CakeEvent($name, $subject, $data);
     if (!$subject) {
         CakeEventManager::instance()->dispatch($event);
     } else {
         $subject->getEventManager()->dispatch($event);
     }
 }
예제 #7
0
 /**
  * Constructor
  * Overridden to provide Twig loading
  *
  * @param Controller $Controller Controller
  */
 public function __construct(Controller $Controller = null)
 {
     $this->Twig = new Twig_Environment(new Twig_Loader_Cakephp(array()), array('cache' => Configure::read('TwigView.Cache'), 'charset' => strtolower(Configure::read('App.encoding')), 'auto_reload' => Configure::read('debug') > 0, 'autoescape' => false, 'debug' => Configure::read('debug') > 0));
     CakeEventManager::instance()->dispatch(new CakeEvent('Twig.TwigView.construct', $this, array('TwigEnvironment' => $this->Twig)));
     parent::__construct($Controller);
     if (isset($Controller->theme)) {
         $this->theme = $Controller->theme;
     }
     $this->ext = self::EXT;
 }
 /**
  * Default settings
  *
  * @var array
  */
 public function initialize(Controller $Controller)
 {
     $this->settings = array_merge($this->_defaultSettings, $this->settings);
     $this->Controller = $Controller;
     $this->_EventManager = CakeEventManager::instance();
     if (empty($this->settings['model'])) {
         $this->settings['model'] = $this->Controller->modelClass;
     }
     $this->sessionKey = $this->settings['sessionKey'];
 }
예제 #9
0
 /**
  * Starts the websocket server
  *
  * @return void
  */
 public function start()
 {
     $this->__loop = LoopFactory::create();
     if ($this->__loop instanceof \React\EventLoop\StreamSelectLoop) {
         $this->out('<warning>Your configuration doesn\'t seem to support \'ext-libevent\'. It is highly reccomended that you install and configure it as it provides significant performance gains over stream select!</warning>');
     }
     $socket = new Reactor($this->__loop);
     $socket->listen(Configure::read('Ratchet.Connection.websocket.port'), Configure::read('Ratchet.Connection.websocket.address'));
     $this->__ioServer = new IoServer(new HttpServer(new WsServer(new SessionProvider(new WampServer(new CakeWampAppServer($this, $this->__loop, CakeEventManager::instance(), $this->params['verbose'])), new CakeWampSessionHandler(), [], new PhpSerializeHandler()))), $socket, $this->__loop);
     $this->__loop->run();
 }
예제 #10
0
 /**
  * Detaches all listeners from the Cart events to avoid application level events changing the tests
  *
  * @return void
  */
 protected function _detachAllListeners()
 {
     $EventManager = CakeEventManager::instance();
     $events = array('Cart.beforeCalculateCart', 'Cart.applyTaxRules', 'Cart.applyDiscounts', 'Cart.afterCalculateCart');
     foreach ($events as $event) {
         $listeners = $EventManager->listeners($event);
         foreach ($listeners as $listener) {
             foreach ($listener['callable'] as $callable) {
                 $EventManager->detach($callable);
             }
         }
     }
 }
예제 #11
0
 public function testConstruct()
 {
     $this->_hibernateListeners('Twig.TwigView.construct');
     $callbackFired = false;
     $that = $this;
     $eventCallback = function ($event) use($that, &$callbackFired) {
         $that->assertInstanceof('Twig_Environment', $event->data['TwigEnvironment']);
         $callbackFired = true;
     };
     CakeEventManager::instance()->attach($eventCallback, 'Twig.TwigView.construct');
     $TwigView = new TwigView();
     CakeEventManager::instance()->detach($eventCallback, 'Twig.TwigView.construct');
     $this->_wakeupListeners('Twig.TwigView.construct');
     $this->assertTrue($callbackFired);
 }
 /**
  * URL
  *
  * @param array $image FileStorage array record or whatever else table that matches this helpers needs without the model, we just want the record fields
  * @param string $version Image version string
  * @param array $options HtmlHelper::image(), 2nd arg options array
  * @throws InvalidArgumentException
  * @return string
  */
 public function imageUrl($image, $version = null, $options = array())
 {
     if (empty($image) || empty($image['id'])) {
         return false;
     }
     if (!empty($version)) {
         $hash = Configure::read('Media.imageHashes.' . $image['model'] . '.' . $version);
         if (empty($hash)) {
             throw new \InvalidArgumentException(__d('file_storage', 'No valid version key (%s %s) passed!', @$image['model'], $version));
         }
     } else {
         $hash = null;
     }
     $Event = new CakeEvent('FileStorage.ImageHelper.imagePath', $this, array('hash' => $hash, 'image' => $image, 'version' => $version, 'options' => $options));
     CakeEventManager::instance()->dispatch($Event);
     if ($Event->isStopped()) {
         return $this->normalizePath($Event->data['path']);
     } else {
         return false;
     }
 }
 protected function _expectedEventCalls(&$asserts, $events)
 {
     $cbi = [];
     foreach ($events as $eventName => $event) {
         $this->__preservedEventListeners[$eventName] = CakeEventManager::instance()->listeners($eventName);
         foreach ($this->__preservedEventListeners[$eventName] as $eventListener) {
             $this->eventManager->detach($eventListener['callable'], $eventName);
         }
         $count = count($events[$eventName]['callback']);
         for ($i = 0; $i < $count; $i++) {
             $asserts[$eventName . '_' . $i] = false;
         }
         $cbi[$eventName] = 0;
         $this->eventManager->attach(function ($event) use(&$events, $eventName, &$asserts, &$cbi) {
             $asserts[$eventName . '_' . $cbi[$eventName]] = true;
             call_user_func($events[$eventName]['callback'][$cbi[$eventName]], $event);
             $cbi[$eventName]++;
         }, $eventName);
     }
     return $asserts;
 }
 /**
  * {@inheritdoc}
  *
  * @return void
  */
 public function execute()
 {
     $tasks = array();
     $this->TaskServer->killZombies();
     while ($this->TaskServer->freeSlots() > 0 && ($task = $this->TaskServer->getPending())) {
         $tasks[] = $task;
     }
     if (empty($tasks)) {
         return;
     }
     $events = (array) Configure::read('Task.processEvents');
     $models = array();
     foreach ($events as $event) {
         $models[$event['model']] = ClassRegistry::init($event['model']);
         CakeEventManager::instance()->attach($models[$event['model']], $event['key'], $event['options']);
     }
     foreach ($tasks as $task) {
         $this->_run($task);
     }
     foreach ($events as $event) {
         CakeEventManager::instance()->detach($models[$event['model']], $event['key'], $event['options']);
     }
 }
예제 #15
0
 /**
  * dispatch
  * 
  * 命名規則に従ったイベント名で、イベントをディスパッチする
  * 
  * @param string $name
  * @param Object $subject
  * @param array $params
  * @param array $options
  * @return boolean|\CakeEvent
  */
 public static function dispatch($name, $subject, $params = array(), $options = array())
 {
     $options = array_merge(array('modParams' => 0, 'layer' => '', 'plugin' => $subject->plugin, 'class' => $subject->name), $options);
     extract($options);
     if ($layer && !preg_match('/^' . $layer . './', $name)) {
         $evnetName = $layer;
         if ($plugin) {
             $evnetName .= '.' . $plugin;
         }
         if ($class) {
             $evnetName .= '.' . $class;
         }
         $evnetName .= '.' . $name;
     }
     $EventManager = CakeEventManager::instance();
     if (!$EventManager->listeners($evnetName)) {
         return false;
     }
     $event = new CakeEvent($evnetName, $subject, $params);
     $event->modParams = $modParams;
     $EventManager->dispatch($event);
     return $event;
 }
예제 #16
0
<?php

App::uses('FileStorageUtils', 'FileStorage.Lib/Utility');
App::uses('StorageManager', 'FileStorage.Lib');
App::uses('LocalImageProcessingListener', 'FileStorage.Event');
//App::uses('LocalFileStorageListener', 'FileStorage.Event');
App::uses('CakeEventManager', 'Event');
spl_autoload_register(__NAMESPACE__ . '\\FileStorageUtils::gaufretteLoader');
$listener = new LocalImageProcessingListener();
CakeEventManager::instance()->attach($listener);
예제 #17
0
 *
 */
/**
 * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
 * Uncomment one of the lines below, as you need. make sure you read the documentation on CakePlugin to use more
 * advanced ways of loading plugins
 *
 * CakePlugin::loadAll(); // Loads all plugins at once
 * CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit
 *
 */
//CakePlugin::load('Crud');
if (php_sapi_name() !== 'cli' && Configure::read('debug') && in_array('DebugKit', App::objects('plugin'))) {
    CakePlugin::load('DebugKit');
    App::uses('CakeEventManager', 'Event');
    CakeEventManager::instance()->attach(function ($event) {
        $controller = $event->subject();
        if (!isset($controller->Crud)) {
            return;
        }
        $controller->Toolbar = $controller->Components->load('DebugKit.Toolbar', ['panels' => ['Crud.Crud']]);
        $controller->Crud->addListener('DebugKit', 'Crud.DebugKit');
    }, 'Controller.initialize');
}
/**
 * You can attach event listeners to the request lifecycle as Dispatcher Filter . By Default CakePHP bundles two filters:
 *
 * - AssetDispatcher filter will serve your asset files (css, images, js, etc) from your themes and plugins
 * - CacheDispatcher filter will read the Cache.check configure variable and try to serve cached content generated from controllers
 *
 * Feel free to remove or add filters as you see fit for your application. A few examples:
예제 #18
0
 /**
  * Tests that the global event manager gets the event too from any other manager
  *
  * @return void
  */
 public function testDispatchWithGlobal()
 {
     $generalManager = $this->getMock('CakeEventManager', array('dispatch'));
     $manager = new CakeEventManager();
     $event = new CakeEvent('fake.event');
     CakeEventManager::instance($generalManager);
     $generalManager->expects($this->once())->method('dispatch')->with($event);
     $manager->dispatch($event);
 }
예제 #19
0
 /**
  * Test that events are dispatched properly when there are global and local
  * listeners at the same priority.
  *
  * @return void
  */
 public function testDispatchWithGlobalAndLocalEvents()
 {
     $listener = new CustomTestEventListener();
     CakeEventManager::instance()->attach($listener);
     $listener2 = new CakeEventTestListener();
     $manager = new CakeEventManager();
     $manager->attach(array($listener2, 'listenerFunction'), 'fake.event');
     $manager->dispatch(new CakeEvent('fake.event', $this));
     $this->assertEquals(array('listenerFunction'), $listener->callStack);
     $this->assertEquals(array('listenerFunction'), $listener2->callStack);
 }
 /**
  * Tets helper. Makes task runner mock
  * 
  * @param array $processEvents
  * @return object
  */
 protected function _makeRunner(array $processEvents)
 {
     return function () use($processEvents) {
         $Runner = $this->getMockBuilder('TaskRunner')->setMethods(array('start'))->disableOriginalConstructor()->getMock();
         $Runner->expects($this->once())->method('start')->willReturnCallback(function () use($processEvents) {
             foreach ($processEvents as $processEvent) {
                 CakeEventManager::instance()->dispatch(new CakeEvent($processEvent['key'], $this, array()));
             }
         });
         return $Runner;
     };
 }
예제 #21
0
파일: basics.php 프로젝트: hanhunhun/hanlog
/**
 * プラグインを読み込む
 * 
 * @param string $plugin
 * @return type
 */
function loadPlugin($plugin, $priority)
{
    if (CakePlugin::loaded($plugin)) {
        return true;
    }
    try {
        CakePlugin::load($plugin);
    } catch (Exception $e) {
        return false;
    }
    $pluginPath = CakePlugin::path($plugin);
    $config = array('bootstrap' => file_exists($pluginPath . 'Config' . DS . 'bootstrap.php'), 'routes' => file_exists($pluginPath . 'Config' . DS . 'routes.php'));
    CakePlugin::load($plugin, $config);
    if (file_exists($pluginPath . 'Config' . DS . 'setting.php')) {
        // DBに接続できない場合、CakePHPのエラーメッセージが表示されてしまう為、 try を利用
        // ※ プラグインの setting.php で、DBへの接続処理が書かれている可能性がある為
        try {
            Configure::load($plugin . '.setting');
        } catch (Exception $ex) {
        }
    }
    // プラグインイベント登録
    $eventTargets = array('Controller', 'Model', 'View', 'Helper');
    foreach ($eventTargets as $eventTarget) {
        $eventClass = $plugin . $eventTarget . 'EventListener';
        if (file_exists($pluginPath . 'Event' . DS . $eventClass . '.php')) {
            App::uses($eventClass, $plugin . '.Event');
            $CakeEvent = CakeEventManager::instance();
            $CakeEvent->attach(new $eventClass(), null, array('priority' => $priority));
        }
    }
    return true;
}
 /**
  * Get the Event Manager
  *
  * If none exist, it uses the default CakeEventManager instance
  *
  * @return CakeEventManager
  */
 public function getEventManager()
 {
     if (is_null($this->_eventManager)) {
         $this->setEventManager(CakeEventManager::instance());
     }
     return $this->_eventManager;
 }
예제 #23
0
<?php

/**
 * User: lukas Strassel
 * Date: 06.11.13
 * Time: 11:55
 */
App::uses('CakeEventManager', 'Event');
App::uses('UserListener', 'User.Lib/Event');
CakeEventManager::instance()->attach(new UserListener());
예제 #24
0
<?php

/**
 * This file is part of Ratchet for CakePHP.
 *
 ** (c) 2012 - 2013 Cees-Jan Kiewiet
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * Configuration
 */
Configure::write('Ratchet', ['Client' => ['retryDelay' => 5000, 'maxRetries' => 25], 'Connection' => ['websocket' => ['address' => '0.0.0.0', 'port' => 11001], 'external' => ['hostname' => 'localhost', 'port' => 80, 'path' => 'websocket', 'secure' => false], 'keepaliveInterval' => 23]]);
App::uses('CakeEventManager', 'Event');
/**
 * Client services listener
 */
App::uses('RatchetKeepAliveListener', 'Ratchet.Event');
CakeEventManager::instance()->attach(new RatchetKeepAliveListener());
/**
 * PCNTL listener
 */
App::uses('PcntlListener', 'Ratchet.Event');
CakeEventManager::instance()->attach(new PcntlListener());
예제 #25
0
 /**
  * Gets a list of image versions for a given record.
  *
  * Use this method to get a list of ALL versions when needed or to cache all the
  * versions somewhere. This method will return all configured versions for an
  * image. For example you could store them serialized along with the file data
  * by adding a "versions" field to the DB table and extend this model.
  *
  * Just in case you're wondering about the event name in the method code: It's
  * called FileStorage.ImageHelper.imagePath there because the event is the same
  * as in the helper. No need to introduce yet another event, the existing event
  * already fulfills the purpose. I might rename this event in the 3.0 version of
  * the plugin to a more generic one.
  *
  * @param array $record An ImageStorage database record
  * @param array $options. Options for the version.
  * @return array A list of versions for this image file. Key is the version, value is the path or URL to that image.
  */
 public function getImageVersions($record, $options = array())
 {
     if (isset($record[$this->alias])) {
         $record = $record[$this->alias];
     }
     $versions = array();
     $versionData = (array) Configure::read('Media.imageSizes.' . $record['model']);
     $versionData['original'] = isset($options['originalVersion']) ? $options['originalVersion'] : 'original';
     foreach ($versionData as $version => $data) {
         $hash = Configure::read('Media.imageHashes.' . $record['model'] . '.' . $version);
         $Event = new CakeEvent('FileStorage.ImageHelper.imagePath', $this, array('hash' => $hash, 'image' => $record, 'version' => $version, 'options' => array()));
         CakeEventManager::instance()->dispatch($Event);
         if ($Event->isStopped()) {
             $versions[$version] = str_replace('\\', '/', $Event->data['path']);
         }
     }
     return $versions;
 }
예제 #26
0
 /**
  * Auto-load plugin event listeners.
  *
  * @param CommonEventManager $manager Optional. Instance to use. Defaults to the global instance.
  * @param string $scope Optional. The scope of events to load.
  * @return CakeEventManager
  */
 public static function loadListeners($manager = null, $scope = null)
 {
     if (!$manager instanceof CakeEventManager) {
         $manager = CakeEventManager::instance();
     }
     empty($manager::$loadedListeners['Common']) && ($manager::$loadedListeners['Common'] = new CommonEventListener());
     (empty($manager::$loadedScopes['Common']) || !in_array($scope, (array) $manager::$loadedScopes['Common'])) && ($manager::$loadedScopes['Common'][] = $scope && CommonEventManager::attachByScope($manager::$loadedListeners['Common'], $manager, $scope));
     $manager::$implementedEvents['Common'] = array_keys($manager::$loadedListeners['Common']->implementedEvents());
     foreach (CakePlugin::loaded() as $plugin) {
         if (isset($manager::$loadedListeners[$plugin])) {
             if ($manager::$loadedListeners[$plugin] && !empty($scope) && !in_array($scope, (array) $manager::$loadedScopes[$plugin])) {
                 self::$loadedScopes[$plugin][] = $scope;
                 CommonEventManager::attachByScope($manager::$loadedListeners[$plugin], $manager, $scope);
             }
             continue;
         }
         $class = $plugin . 'EventListener';
         if (ClassRegistry::isKeySet($class)) {
             $manager::$loadedListeners[$plugin] = ClassRegistry::getObject($class);
         } else {
             if (file_exists(CakePlugin::path($plugin) . 'Event' . DS . $class . '.php')) {
                 App::uses($class, $plugin . '.Event');
                 $manager::$loadedListeners[$plugin] = new $class();
             } else {
                 $manager::$loadedListeners[$plugin] = false;
                 continue;
             }
         }
         $manager::$loadedScopes[$plugin] = array();
         $manager::$implementedEvents[$plugin] = array_keys($manager::$loadedListeners[$plugin]->implementedEvents());
         if (empty($scope)) {
             $manager->attach($manager::$loadedListeners[$plugin]);
         } else {
             if (!in_array($scope, $manager::$loadedScopes[$plugin])) {
                 $manager::$loadedScopes[$plugin][] = $scope;
                 CommonEventManager::attachByScope($manager::$loadedListeners[$plugin], $manager, $scope);
             }
         }
     }
     if (!Reveal::is('Page.test') && !isset($manager::$loadedListeners['App'])) {
         if (file_exists(APP . 'Event' . DS . 'AppEventListener.php')) {
             App::uses('AppEventListener', 'Event');
             $manager::$loadedListeners['App'] = new AppEventListener();
             $manager::$loadedScopes['App'] = array();
             $manager::$implementedEvents['App'] = array_keys($manager::$loadedListeners['App']->implementedEvents());
             if (empty($scope)) {
                 $manager->attach($manager::$loadedListeners['App']);
             } else {
                 if (!in_array($scope, $manager::$loadedScopes['App'])) {
                     self::$loadedScopes['App'][] = $scope;
                     CommonEventManager::attachByScope($manager::$loadedListeners['App'], $manager, $scope);
                 }
             }
         }
     } else {
         if (isset($manager::$loadedListeners['App']) && $manager::$loadedListeners['App'] && !empty($scope) && !in_array($scope, $manager::$loadedScopes['App'])) {
             $manager::$loadedScopes['App'][] = $scope;
             CommonEventManager::attachByScope($manager::$loadedListeners['App'], $manager, $scope);
         }
     }
     return $manager;
 }
예제 #27
0
파일: bootstrap.php 프로젝트: kenz/basercms
 */
if (BC_INSTALLED && !$isUpdater && !$isMaintenance) {
    App::build(array('Plugin' => array_merge(array(BASER_THEMES . $bcSite['theme'] . DS . 'Plugin' . DS), App::path('Plugin'))));
    $plugins = getEnablePlugins();
    foreach ($plugins as $plugin) {
        loadPlugin($plugin['Plugin']['name'], $plugin['Plugin']['priority']);
    }
    $plugins = Hash::extract($plugins, '{n}.Plugin.name');
    Configure::write('BcStatus.enablePlugins', $plugins);
    /**
     * イベント登録
     */
    App::uses('BcControllerEventDispatcher', 'Event');
    App::uses('BcModelEventDispatcher', 'Event');
    App::uses('BcViewEventDispatcher', 'Event');
    $CakeEvent = CakeEventManager::instance();
    $CakeEvent->attach(new BcControllerEventDispatcher());
    $CakeEvent->attach(new BcModelEventDispatcher());
    $CakeEvent->attach(new BcViewEventDispatcher());
    /**
     * テーマの bootstrap を実行する
     */
    $themePath = WWW_ROOT . 'theme' . DS . Configure::read('BcSite.theme') . DS;
    $themeBootstrap = $themePath . 'Config' . DS . 'bootstrap.php';
    if (file_exists($themeBootstrap)) {
        include $themeBootstrap;
    }
}
/**
 * 文字コードの検出順を指定
 */
예제 #28
0
파일: NodeTest.php 프로젝트: saydulk/croogo
 /**
  * testSaveNodeEvents
  */
 public function testSaveNodeEvents()
 {
     $this->Node->type = null;
     $oldNodeCount = $this->Node->find('count');
     $data = array('Node' => array('title' => 'Test Content', 'slug' => 'test-content', 'type' => 'blog', 'token_key' => 1, 'body' => ''), 'Role' => array('Role' => array('3')), 'TaxonomyData' => array(1 => array(1)));
     $manager = CakeEventManager::instance();
     $manager->attach(array($this, 'onBeforeSaveNode'), 'Model.Node.beforeSaveNode');
     $manager->attach(array($this, 'onAfterSaveNode'), 'Model.Node.afterSaveNode');
     $result = $this->Node->saveNode($data, Node::DEFAULT_TYPE);
     $this->Node->type = null;
     $node = $this->Node->find('first', array('fields' => array('id', 'title', 'slug', 'body'), 'recursive' => -1, 'conditions' => array('Node.id' => $this->Node->id)));
     $this->assertTrue($result);
     $this->assertEquals('Test Content', $node['Node']['title']);
     $this->assertEquals($this->testBody, $node['Node']['body']);
     $manager->detach(array($this, 'onBeforeSaveNode'));
     $manager->detach(array($this, 'onAfterSaveNode'));
 }
예제 #29
0
<?php

Configure::write('TwigView', array('Cache' => CakePlugin::path('TwigView') . 'tmp' . DS . 'views'));
App::uses('CakeEventManager', 'Event');
App::uses('TwigRegisterTwigExtentionsListener', 'TwigView.Event');
CakeEventManager::instance()->attach(new TwigRegisterTwigExtentionsListener());
 /**
  * @param $mediaPlatformId
  * @param $mediaPlatformUserId
  */
 protected function _newUserEvent($mediaPlatformId, $mediaPlatformUserId)
 {
     $event = new CakeEvent('AuthManager.MediaPlatformUser.new', $this, array('media_platform_id' => $mediaPlatformId, 'media_platform_user_id' => $mediaPlatformUserId));
     CakeEventManager::instance()->dispatch($event);
 }