本文整理汇总了PHP中Zend\EventManager\Event类的典型用法代码示例。如果您正苦于以下问题:PHP Event类的具体用法?PHP Event怎么用?PHP Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Determines if we're dealing with the required Resource
* before dispatching to actions
*
* @param Event $e
* @return mixed|void
*/
public function dispatch(Event $e)
{
switch ($e->getName()) {
case 'create.post':
case 'update.post':
case 'patch.post':
/**
* Redirect client to newly created resource
*/
$controller = $e->getTarget();
if ($controller instanceof ResourceController) {
$resource = $controller->getResource();
if ($resource instanceof Resource) {
$model = $e->getParam('resource');
if ($model instanceof ResourceJsonModel) {
$object = $model->getPayload();
if ($object instanceof BackendResourceInterface) {
$e->stopPropagation(true);
$response = $controller->redirect()->toRoute('api/default', array('resource' => $resource->getIdentifier(), 'id' => $object->getId()));
return $response;
//@TODO remove until fixed CORS redirect
}
}
}
}
break;
}
}
示例2: onBootstrap
public function onBootstrap(Event $e)
{
$app = $e->getApplication();
Utility::setSM($app->getServiceManager());
TransactionUtility::setSM($app->getServiceManager());
UnitCalcUtility::setSM($app->getServiceManager());
}
示例3: onUpdate
public function onUpdate(Event $e)
{
/* @var $term TaxonomyTermInterface */
$term = $e->getParam('term');
$instance = $term->getInstance();
$this->logEvent('taxonomy/term/update', $instance, $term);
}
示例4: initListener
/**
* Initialize event listener
* @param \Zend\EventManager\Event $e
* @return void
*/
public function initListener(Event $e)
{
$app = $e->getParam('application');
$eventListener = new Listener();
$eventListener->setServiceManager($app->getServiceManager());
$app->getEventManager()->attachAggregate($eventListener);
}
示例5: __invoke
/**
* @param array|null $resource
* @param Request $request
* @param Response $response
*/
public function __invoke(Event $event)
{
$resource = $event->getParam('resource');
$response = $event->getParam('response');
$body = $this->renderView($resource, $response);
$response->setBody($body);
}
示例6: onDispatch
public function onDispatch(Event $event)
{
$controller = $event->getTarget();
if (!$controller instanceof AbstractController) {
return;
}
$entity = $controller->getEntity();
if (!$entity) {
return;
}
$terms = $entity->getTaxonomyTerms();
if ($terms->isEmpty()) {
foreach ($entity->getParents('link') as $parent) {
$terms = $parent->getTaxonomyTerms();
if (!$terms->isEmpty()) {
break;
}
}
}
$term = $this->strategy->findBranch($terms);
if ($term) {
/* @var $navigationFactory DefaultNavigationFactory */
$navigationFactory = $controller->getServiceLocator()->get('Navigation\\Factory\\DefaultNavigationFactory');
$params = ['term' => $term->getId(), 'controller' => 'Taxonomy\\Controller\\GetController', 'action' => 'index'];
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName('taxonomy/term/get');
$navigationFactory->setRouteMatch($routeMatch);
}
}
示例7: preSend
/**
* Add Client Id and Client Secret to Request Parameters
*
* @throws Exception\InvalidArgumentException
*/
public function preSend(Event $e)
{
$this->request = $e->getTarget();
$headers = $this->request->getHeaders();
$params = array('Authorization' => 'OAuth ' . $this->getOauthString());
$headers->addHeaders($params);
}
示例8: onCreate
public function onCreate(Event $e)
{
$entity = $e->getParam('entity');
$user = $this->getUserManager()->getUserFromAuthenticator();
$instance = $this->getInstanceManager()->getInstanceFromRequest();
$this->logEvent('entity/create', $instance, $entity);
}
示例9: onBootstrap
public function onBootstrap(Event $e)
{
$sm = $e->getApplication()->getServiceManager();
$em = $sm->get('doctrine.entitymanager.orm_default');
$vcard = $sm->get('vcard');
$vcard->setEm($em);
}
示例10: clearCache
public function clearCache($id)
{
$event = new Event();
$event->setParam('id', $id);
$result = $this->getEventManager()->trigger('clear', $event);
return $result->last();
}
示例11: onTrash
public function onTrash(Event $e)
{
$object = $e->getParam('object');
$user = $this->getUserManager()->getUserFromAuthenticator();
$instance = $this->getInstanceManager()->getInstanceFromRequest();
$this->logEvent('uuid/trash', $instance, $object);
}
示例12: onCancelSingle
public function onCancelSingle(Event $event)
{
$booking = $event->getTarget();
$reservations = $this->reservationManager->getBy(['bid' => $booking->need('bid')], 'date ASC', 1);
$reservation = current($reservations);
$square = $this->squareManager->get($booking->need('sid'));
$user = $this->userManager->get($booking->need('uid'));
$dateRangerHelper = $this->dateRangeHelper;
$reservationTimeStart = explode(':', $reservation->need('time_start'));
$reservationTimeEnd = explode(':', $reservation->need('time_end'));
$reservationStart = new \DateTime($reservation->need('date'));
$reservationStart->setTime($reservationTimeStart[0], $reservationTimeStart[1]);
$reservationEnd = new \DateTime($reservation->need('date'));
$reservationEnd->setTime($reservationTimeEnd[0], $reservationTimeEnd[1]);
$subject = sprintf($this->t('Your %s-booking has been cancelled'), $this->optionManager->get('subject.square.type'));
$message = sprintf($this->t('we have just cancelled %s %s, %s for you.'), $this->optionManager->get('subject.square.type'), $square->need('name'), $dateRangerHelper($reservationStart, $reservationEnd));
if ($user->getMeta('notification.bookings', 'true') == 'true') {
$this->userMailService->send($user, $subject, $message);
}
if ($this->optionManager->get('client.contact.email.user-notifications')) {
$backendSubject = sprintf($this->t('%s\'s %s-booking has been cancelled'), $user->need('alias'), $this->optionManager->get('subject.square.type'));
$addendum = sprintf($this->t('Originally sent to %s (%s).'), $user->need('alias'), $user->need('email'));
$this->backendMailService->send($backendSubject, $message, array(), $addendum);
}
}
示例13: testTriggerSetsTarget
public function testTriggerSetsTarget()
{
$event = new Event();
$this->assertNull($event->getTarget());
Reflection::invoke($this->sut, 'trigger', array($event));
$this->assertSame($this->sut, $event->getTarget());
}
示例14: updateSchema
/**
* {@inheritDoc}
*/
public function updateSchema(Event $e)
{
$moduleVersion = $e->getParam('version');
// Set extra model
$extraModel = Pi::model('extra', $this->module);
$extraTable = $extraModel->getTable();
$extraAdapter = $extraModel->getAdapter();
// Set news story model
$newsStoryModel = Pi::model('story', 'news');
$newsStoryTable = $newsStoryModel->getTable();
$newsStoryAdapter = $newsStoryModel->getAdapter();
// Update to version 0.1.5
if (version_compare($moduleVersion, '0.1.5', '<')) {
// Update value
$select = $extraModel->select();
$rowSet = $extraModel->selectWith($select);
foreach ($rowSet as $row) {
// Set time
$time = $row->time_end ? $row->time_end : $row->time_start;
// Update time_publish
$newsStoryModel->update(array('time_publish' => $time), array('id' => $row->id));
}
}
// Update to version 0.4.1
if (version_compare($moduleVersion, '0.4.1', '<')) {
// Alter table field `register_discount`
$sql = sprintf("ALTER TABLE %s ADD `register_discount` TEXT", $extraTable);
try {
$extraAdapter->query($sql, 'execute');
} catch (\Exception $exception) {
$this->setResult('db', array('status' => false, 'message' => 'Table alter query failed: ' . $exception->getMessage()));
return false;
}
}
}
示例15: checkModules
/**
* Check other modules and register comments if available
*
* @param Event $e
* @return void
*/
public function checkModules(Event $e)
{
$module = $e->getParam('module');
$modules = Pi::registry('module')->read();
if (isset($modules['comment'])) {
unset($modules['comment']);
}
$moduleList = array_keys($modules);
foreach ($moduleList as $mod) {
$options = Pi::service('module')->loadMeta($mod, 'comment', true);
if (empty($options)) {
continue;
}
/*
if (is_string($options)) {
$optionsFile = sprintf(
'%s/%s/config/%s',
Pi::path('module'),
Pi::service('module')->directory($mod),
$options
);
$options = include $optionsFile;
if (empty($options) || !is_array($options)) {
continue;
}
}
*/
$resourceHandler = new CommentResource($options);
$e->setParam('module', $mod);
$resourceHandler->setEvent($e);
$resourceHandler->installAction();
}
$e->setParam('module', $module);
}