本文整理汇总了PHP中CakeEventManager类的典型用法代码示例。如果您正苦于以下问题:PHP CakeEventManager类的具体用法?PHP CakeEventManager怎么用?PHP CakeEventManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CakeEventManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: work
public function work(GearmanJob $job)
{
$workload = $job->workload();
$json = json_decode($workload, true);
if (!json_last_error()) {
$workload = $json;
}
$eventManager = new CakeEventManager();
$eventManager->dispatch(new CakeEvent('Gearman.beforeWork', $this, $workload));
$data = call_user_func($this->_workers[$job->functionName()], $job, $workload);
$eventManager->dispatch(new CakeEvent('Gearman.afterWork', $this, $workload));
return $data;
}
开发者ID:davidsteinsland,项目名称:cakephp-gearman,代码行数:13,代码来源:GearmanShellTask.php
示例2: testProcessVersion
/**
* 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);
}
开发者ID:arourke,项目名称:cakephp-file-storage,代码行数:31,代码来源:ImageStorageTest.php
示例3: changeStatus
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;
}
开发者ID:cvo-technologies,项目名称:croogo-webshop-plugin,代码行数:33,代码来源:StatusBehavior.php
示例4: import
/**
* Import exchange rate for the euro.
*/
public function import()
{
$exchangeRateImporter = new EcbExchangeRateImporter();
$exchangeRateImporter->import();
$event = new CakeEvent('ExchangeRateImport.completed', $this);
CakeEventManager::instance()->dispatch($event);
}
开发者ID:ExpandOnline,项目名称:CakePHPExchangeRates,代码行数:10,代码来源:ExchangeRateImportShell.php
示例5: onProductBought
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;
}
开发者ID:cvo-technologies,项目名称:pltfrm,代码行数:30,代码来源:WebhostingHandler.php
示例6: dispatchEvent
/**
* 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);
}
}
开发者ID:hurad,项目名称:hurad,代码行数:16,代码来源:Hurad.php
示例7: __construct
/**
* 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;
}
开发者ID:alanrodas,项目名称:TwigView,代码行数:16,代码来源:TwigView.php
示例8: initialize
/**
* 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'];
}
开发者ID:mikebirch,项目名称:cakephp-cart-plugin,代码行数:15,代码来源:CartManagerComponent.php
示例9: instance
/**
* Returns the globally available instance of a CakeEventManager
* this is used for dispatching events attached from outside the scope
* other managers were created. Usually for creating hook systems or inter-class
* communication
*
* If called with a first params, it will be set as the globally available instance
*
* @param CakeEventManager $manager
* @return CakeEventManager the global event manager
*/
public static function instance($manager = null)
{
if ($manager instanceof CakeEventManager) {
self::$_generalManager = $manager;
}
if (empty(self::$_generalManager)) {
self::$_generalManager = new CakeEventManager();
}
self::$_generalManager->_isGlobal = true;
return self::$_generalManager;
}
开发者ID:aichelman,项目名称:StudyUp,代码行数:22,代码来源:CakeEventManager.php
示例10: start
/**
* 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();
}
开发者ID:schnauss,项目名称:Ratchet,代码行数:16,代码来源:WebsocketShell.php
示例11: _detachAllListeners
/**
* 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);
}
}
}
}
开发者ID:mikebirch,项目名称:cakephp-cart-plugin,代码行数:18,代码来源:CartTest.php
示例12: testConstruct
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);
}
开发者ID:alanrodas,项目名称:TwigView,代码行数:15,代码来源:TwigViewTest.php
示例13: imageUrl
/**
* 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;
}
}
开发者ID:CodeBlastr,项目名称:FileStorage-CakePHP-Plugin,代码行数:30,代码来源:ImageHelper.php
示例14: _expectedEventCalls
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;
}
开发者ID:schnauss,项目名称:Ratchet,代码行数:21,代码来源:AbstractCakeRatchetTestCase.php
示例15: callback
/**
* Default callback entry point for API callbacks for payment processors
*
* @param null $token
* @throws NotFoundException
* @internal param string $processor
* @return void
*/
public function callback($token = null)
{
$order = $this->Order->find('first', array('contain' => array(), 'conditions' => array('Order.token' => $token)));
if (empty($order)) {
throw new NotFoundException(__d('cart', 'Invalid payment token %s!', $token));
}
try {
$Processor = $this->_loadPaymentProcessor($order['Order']['processor']);
$status = $Processor->notificationCallback($order);
$transactionId = $Processor->getTransactionId();
if (empty($order['Order']['payment_reference']) && !empty($transactionId)) {
$order['Order']['payment_reference'] = $transactionId;
}
$result = $this->Order->save(array('Order' => array('id' => $order['Order']['id'], 'payment_status' => $status, 'payment_reference' => $order['Order']['payment_reference'])), array('validate' => false, 'callbacks' => false));
} catch (Exception $e) {
$this->log($e->getMessage(), 'payment-error');
$this->log($this->request, 'payment-error');
}
$Event = new CakeEvent('Payment.callback', $this->request);
CakeEventManager::dispatch($Event, $this, array($result));
$this->_stop();
}
开发者ID:mikebirch,项目名称:cakephp-cart-plugin,代码行数:30,代码来源:CheckoutController.php
示例16: execute
/**
* {@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']);
}
}
开发者ID:imsamurai,项目名称:cakephp-task-plugin,代码行数:28,代码来源:TaskServerTask.php
示例17: dispatch
/**
* 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;
}
开发者ID:naow9y,项目名称:basercms,代码行数:34,代码来源:BcEventDispatcher.php
示例18: detach
/**
* Removes a listener from the active listeners.
* @see CakeEventManager::detach()
* @return void
*/
public function detach($callable, $eventKey = null)
{
if (is_object($callable)) {
$key = get_class($callable);
unset($this->_listenersMap[$key]);
}
parent::detach($callable, $eventKey);
}
开发者ID:saydulk,项目名称:croogo,代码行数:13,代码来源:CroogoEventManager.php
示例19: getEventManager
/**
* Returns the CakeEventManager manager instance that is handling any callbacks.
* You can use this instance to register any new listeners or callbacks to the
* controller events, or create your own events and trigger them at will.
*
* @return CakeEventManager
*/
public function getEventManager()
{
if (empty($this->_eventManager)) {
$this->_eventManager = new CakeEventManager();
$this->_eventManager->attach($this->Components);
$this->_eventManager->attach($this);
}
return $this->_eventManager;
}
开发者ID:amysupeta,项目名称:Exame1,代码行数:16,代码来源:Controller.php
示例20: array_merge
*/
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;
}
}
/**
* 文字コードの検出順を指定
*/
开发者ID:kenz,项目名称:basercms,代码行数:31,代码来源:bootstrap.php
注:本文中的CakeEventManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论