本文整理汇总了PHP中Zend\EventManager\EventInterface::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::getName方法的具体用法?PHP EventInterface::getName怎么用?PHP EventInterface::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventInterface
的用法示例。
在下文中一共展示了EventInterface::getName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onAfterSimpleMailerSend
public function onAfterSimpleMailerSend(EventInterface $event)
{
/** @var \Detail\Mail\Service\MailerInterface $mailer */
$mailer = $event->getTarget();
$message = $event->getParam('message');
if ($message === null) {
throw new RuntimeException(sprintf('Event "%s" is missing param "message"', $event->getName()));
} elseif (!$message instanceof MessageInterface) {
throw new RuntimeException(sprintf('Event "%s" has invalid value for param "message"; ' . 'expected Detail\\Mail\\Message\\MessageInterface object but got ' . is_object($message) ? get_class($message) : gettype($message), $event->getName()));
}
$headersText = preg_replace('/\\s+/', ' ', str_replace(PHP_EOL, ' ', var_export($message->getHeaders(), true)));
if ($mailer instanceof SimpleMailer) {
/** @var \Detail\Mail\Service\SimpleMailer $mailer */
$driverClass = get_class($mailer->getDriver());
switch ($driverClass) {
case 'Detail\\Mail\\Driver\\Bernard\\BernardDriver':
$text = 'Queued email message "%s" of type "%s" (headers: "%s", driver: %s)';
break;
default:
$text = 'Sent email message "%s" of type "%s" (headers: "%s", driver: %s)';
break;
}
$text = sprintf($text, $message->getId(), $message->getName(), $headersText, $driverClass);
} else {
$text = sprintf('Sent email message "%s" of type "%s" (headers: "%s")', $message->getId(), $message->getName(), $headersText);
}
$this->log($text);
}
示例2: getModulosCarregados
public function getModulosCarregados(Event $e)
{
echo $e->getName() . "<br>";
echo get_class($e->getTarget());
$moduleManager = $e->getTarget();
print_r($moduleManager->getLoadedModules());
}
示例3: handle
public function handle(EventInterface $event)
{
$user = $event->getTarget();
$extractor = new PlainExtractor($this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'), '.');
$data = $event->getParam('data');
if (!is_array($data)) {
$data = $extractor->extract($data);
}
$data = $data + $extractor->extract($user, 'user') + $extractor->extract($user->getUserInfo(), 'userinfo');
/**
* @var \Mailer\Model\NotificationModel $notifyModel
*/
$notifyModel = $this->getServiceLocator()->get('Mailer/Model/Notification');
$notificationTpl = $notifyModel->findBySlug($this->convertNameToSlug($event->getName()));
if (null == $notificationTpl) {
$this->getLog()->crit('Notification template "' . $this->convertNameToSlug($event->getName()) . '" not found', array('template_vars' => implode(',', array_keys($data))));
throw new \Mailer\Model\Exception\NotificationTemplateNotFound('Notification template "' . $this->convertNameToSlug($event->getName()) . '" not found');
}
$translation = $notifyModel->getNotificationTranslation($notificationTpl);
$messageOptions = $this->getMailSettings();
$mail = new \Mailer\Mail\Message();
$mail->setEncoding($messageOptions['encoding']);
if (null != $notificationTpl->getEmailFrom()) {
$mail->setFrom($notificationTpl->getEmailFrom(), $translation->getNameFrom());
$mail->setSender($notificationTpl->getEmailFrom(), $translation->getNameFrom());
} else {
$mail->setFrom($messageOptions['defaultFrom'], $messageOptions['defaultFromName']);
$mail->setSender($messageOptions['defaultFrom'], $messageOptions['defaultFromName']);
}
$mail->setTo($user->getEmail(), $user->getUserInfo()->getFullName());
$mail->setSubject($translation->compileSubject($data));
$body = new \Zend\Mime\Message();
if (null != $translation->getNotificationHtml()) {
$part = new \Zend\Mime\Part($translation->compileNotificationHtml($data));
$part->type = "text/html";
$part->charset = $messageOptions['encoding'];
$part->language = $translation->getLanguageId();
$body->addPart($part);
}
if (null != $translation->getNotificationText()) {
$part = new \Zend\Mime\Part($translation->compileNotificationText($data));
$part->type = "text/plain";
$part->charset = $messageOptions['encoding'];
$part->language = $translation->getLanguageId();
$body->addPart($part);
}
$mail->setBody($body);
$this->getTransport()->send($mail);
}
示例4: log
/**
* Actually do the logging.
*
* @param EventInterface $event
*/
public function log(EventInterface $event)
{
$params = $event->getParams();
$method = isset($params[0]) ? $params[0] : '';
$this->logger->debug(get_class($event->getTarget()) . "::{$method} - {$event->getName()}");
}
示例5: triggerListeners
/**
* Trigger listeners
*
* Actual functionality for triggering listeners, to which trigger() delegate.
*
* @param EventInterface $event
* @param null|callable $callback
* @return ResponseCollection
*/
protected function triggerListeners(EventInterface $event, callable $callback = null)
{
$name = $event->getName();
if (empty($name)) {
throw new Exception\RuntimeException('Event is missing a name; cannot trigger!');
}
// Initial value of stop propagation flag should be false
$event->stopPropagation(false);
$responses = new ResponseCollection();
foreach ($this->getListenersByEventName($name) as $listener) {
$response = $listener($event);
$responses->push($response);
// If the event was asked to stop propagating, do so
if ($event->propagationIsStopped()) {
$responses->setStopped(true);
break;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && $callback($response)) {
$responses->setStopped(true);
break;
}
}
return $responses;
}
示例6: onBootstrap
/**
* @param EventInterface $e
*/
public function onBootstrap(EventInterface $e)
{
/* @var $application Application */
$application = $e->getApplication();
$serviceManager = $application->getServiceManager();
$config = $serviceManager->get('config');
$request = $application->getRequest();
$debugbarConfig = $config['php-debug-bar'];
if ($debugbarConfig['enabled'] !== true || !$request instanceof Request) {
return;
}
$applicationEventManager = $application->getEventManager();
$viewEventManager = $serviceManager->get('View')->getEventManager();
$viewRenderer = $serviceManager->get('ViewRenderer');
$debugbar = $serviceManager->get('debugbar');
$timeCollector = $debugbar['time'];
$exceptionCollector = $debugbar['exceptions'];
self::$messageCollector = $debugbar['messages'];
$lastMeasure = null;
$applicationEventManager->attach(MvcEvent::EVENT_FINISH, function (MvcEvent $event) use($debugbar) {
$response = $event->getResponse();
if (!$response instanceof Response) {
return;
}
$contentTypeHeader = $response->getHeaders()->get('Content-type');
if ($contentTypeHeader && $contentTypeHeader->getFieldValue() !== 'text/html') {
return;
}
$renderer = $debugbar->getJavascriptRenderer();
$renderer->renderOnShutdown(false);
});
// Enable messages function
require __DIR__ . '/Functions.php';
// Auto enable assets
if ($debugbarConfig['auto-append-assets']) {
$viewRenderer->plugin('DebugBar')->appendAssets();
}
// Timeline
$measureListener = function (EventInterface $e) use($timeCollector, &$lastMeasure) {
if ($lastMeasure !== null && $timeCollector->hasStartedMeasure($lastMeasure)) {
$timeCollector->stopMeasure($lastMeasure);
}
$lastMeasure = $e->getName();
if ($e instanceof ViewEvent) {
$model = $e->getParam('model');
if ($model instanceof ModelInterface) {
$lastMeasure .= ' (' . $model->getTemplate() . ')';
}
}
$timeCollector->startMeasure($lastMeasure, $lastMeasure);
};
$applicationEventManager->attach('*', $measureListener);
$viewEventManager->attach('*', $measureListener);
// Exceptions
$exceptionListener = function (EventInterface $event) use($exceptionCollector) {
$exception = $event->getParam('exception');
if ($exception instanceof \Exception) {
$exceptionCollector->addException($exception);
}
};
$applicationEventManager->attach('*', $exceptionListener);
$viewEventManager->attach('*', $exceptionListener);
// Route
$applicationEventManager->attach(MvcEvent::EVENT_ROUTE, function (EventInterface $e) use($debugbar) {
$route = $e->getRouteMatch();
$data = array('route_name' => $route->getMatchedRouteName(), 'params' => $route->getParams());
$debugbar->addCollector(new ConfigCollector($data, 'Route'));
});
}