本文整理汇总了PHP中Zend\Mvc\MvcEvent::getParam方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::getParam方法的具体用法?PHP MvcEvent::getParam怎么用?PHP MvcEvent::getParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::getParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: injectIntoView
/**
* Sets some Meta-Data into the view.
*
* @param MvcEvent $event
*/
public function injectIntoView(MvcEvent $event)
{
$serviceLocator = $event->getApplication()->getServiceManager();
$nodeOptions = $serviceLocator->get('NodeOptions');
/* @var $nodeOptions \Node\Options\NodeOptions */
$viewHelperManager = $serviceLocator->get('viewhelpermanager');
$serverurl = $viewHelperManager->get('serverurl');
if (null != $event->getParam('matchedNode')) {
$node = $event->getParam('matchedNode');
/* @var $node \Node\Entity\NodeInterface */
// HeadTitle
$headtitle = $viewHelperManager->get('headtitle');
$headtitle->set($node->getNodeName());
// Canonical
$headlink = $viewHelperManager->get('headlink');
$headlink(['rel' => 'canonical', 'href' => $serverurl() . $node->getNodeRoute()]);
// Meta?
if (true == $nodeOptions->getEnableMetaTags()) {
$headmeta = $viewHelperManager->get('headmeta');
if (null != $node->getNodeMetaRobots()) {
$headmeta->appendName('robots', $node->getNodeMetaRobots());
}
if (null != $node->getNodeMetaDescription()) {
$headmeta->appendName('description', $node->getNodeMetaDescription());
}
if (null != $node->getNodeMetaKeywords()) {
$headmeta->appendName('keywords', $node->getNodeMetaKeywords());
}
}
}
}
示例2: testNoRolesAllowed
public function testNoRolesAllowed()
{
$this->routeMatch->setParam('action', 'noRoles');
$listener = new Authorized();
$listener->onDispach($this->event);
$this->assertNull($this->event->getParam('exception'));
}
示例3: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// Add translation
$translator = $e->getApplication()->getServiceManager()->get('translator');
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$setLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
} else {
$setLang = '';
}
$translator->setLocale(\Locale::acceptFromHttp($setLang))->setFallbackLocale('en_US');
// Add ACL information to the Navigation view helper
$sm = $e->getApplication()->getServiceManager();
$authorize = $sm->get('BjyAuthorize\\Service\\Authorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
\Zend\View\Helper\Navigation::setDefaultAcl($acl);
\Zend\View\Helper\Navigation::setDefaultRole($role);
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Application', 'dispatch.error', function ($e) use($sm) {
if ($e->getParam('exception')) {
$sm->get('Zend\\Log\\Logger')->crit($e->getParam('exception'));
}
});
}
示例4: dispatchError
public function dispatchError(MvcEvent $e)
{
$sharedManager = $e->getApplication()->getEventManager()->getSharedManager();
$sharedManager->attach('Zend\\Mvc\\Application', 'dispatch.error', function ($e) {
if ($e->getParam('exception')) {
ob_clean();
//Limpar a tela de erros do php
header('HTTP/1.1 400 Bad Request');
$exception = $e->getParam('exception');
$sm = $e->getApplication()->getServiceManager();
$config = $sm->get('Config');
$e->getApplication()->getServiceManager()->get('Controller\\Plugin\\Manager')->get('jsLog')->log($exception, 2);
$viewModel = new \Zend\View\Model\ViewModel(['exception' => $exception]);
if ($e->getRequest()->isXmlHttpRequest()) {
$viewModel->setTemplate($config['js_library']['error_ajax_exception']);
$e->getApplication()->getServiceManager()->get('ViewRenderer')->render($viewModel);
} else {
$viewModel->setTemplate($config['js_library']['error_exception']);
echo $e->getApplication()->getServiceManager()->get('ViewRenderer')->render($viewModel);
}
/*
* Com erros handler o codigo continua a ser executado,
* entao o exit para e so mostra os erros
*/
exit;
}
});
}
示例5: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$events = $e->getApplication()->getEventManager()->getSharedManager();
$config = $e->getApplication()->getServiceManager()->get('config');
// configure session
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$events->attach('ZfcUser\\Service\\User', 'register.post', function ($e) {
$user = $e->getParam('user');
// User account object
$form = $e->getParam('form');
// Form object
// Perform your custom action here
/* @var $sm ServiceLocatorInterface */
$sm = $e->getTarget()->getServiceManager();
/* @var $em \Doctrine\ORM\EntityManager */
$em = $sm->get('doctrine.entitymanager.orm_default');
$userRole = $em->find(__NAMESPACE__ . '\\Entity\\UserRole', DEFAULT_ROLE);
if (NULL !== $userRole) {
$user->addRole($userRole);
$em->persist($user);
$em->flush();
}
});
}
示例6: onError
/**
* Listener callback
*/
public function onError()
{
$this->verifyIsError();
/** @var \Exception $exception */
$exception = $this->mvcEvent->getParam('exception');
$logger = $this->getLogger();
$logger->err($exception);
}
示例7: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$doctrineAdapter = $serviceManager = $e->getParam('application')->getServiceManager()->get('oauth2.doctrineadapter.default');
$listenerAggregate = new \ZFTest\OAuth2\Doctrine\Listener\TestEvents($doctrineAdapter);
/** @var ServiceManager $serviceManager */
$serviceManager = $e->getParam('application')->getServiceManager();
/** @var EventManager $eventManager */
$eventManager = $serviceManager->get('oauth2.doctrineadapter.default')->getEventManager();
$listenerAggregate->attach($eventManager);
}
示例8: loadDocument
protected function loadDocument(MvcEvent $event, $documentManager, $metadata, $field)
{
if (!($document = $event->getParam('document'))) {
// document not set, so load it
$document = $documentManager->createQueryBuilder()->find($metadata->name)->field($event->getTarget()->getOptions()->getProperty())->equals($event->getParam('id'))->select($field)->getQuery()->getSingleResult();
if (!$document) {
throw new Exception\DocumentNotFoundException();
}
}
return $document;
}
示例9: handleError
/**
*
*/
public function handleError(MvcEvent $event)
{
$controller = $event->getController();
$error = $event->getParam('error');
$exception = $event->getParam('exception');
$message = sprintf('Error dispatching controller "%s". Error was: "%s"', $controller, $error);
if ($exception instanceof \Exception) {
$message .= ', Exception(' . $exception->getMessage() . '): ' . $exception->getTraceAsString();
}
error_log($message);
}
示例10: onBootstrap
/**
* Bootstrap.
*
* @var MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
$em = $e->getApplication()->getEventManager();
// this event listener will turn the request into '403 Forbidden' when
// there is a NotAllowedException
$em->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) {
if ($e->getError() == 'error-exception' && $e->getParam('exception', null) != null && $e->getParam('exception') instanceof NotAllowedException) {
$e->getResult()->setTemplate('error/403');
$e->getResponse()->setStatusCode(403);
}
}, -100);
}
示例11: latch
public function latch(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$em = $eventManager->getSharedManager();
$zfcServiceEvents = $e->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager();
$zfcServiceEvents->attach('register', function ($e) {
$form = $e->getParam('form');
/* @var $user \FzyAuth\Entity\Base\UserInterface */
$user = $e->getParam('user');
$user->setRole(UserInterface::ROLE_USER);
});
}
示例12: _addRegistrationFields
private function _addRegistrationFields(MvcEvent $e)
{
$zfcServiceEvents = $e->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager();
// Store the field
$zfcServiceEvents->attach('register', function ($e) {
$form = $e->getParam('form');
$user = $e->getParam('user');
/* @var $user \FooUser\Entity\User */
$displayName = $form->get('firstName')->getValue() . ' ' . $form->get('lastName')->getValue();
$user->setDisplayName($displayName);
});
}
示例13: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$application = $e->getApplication();
$serviceLocator = $application->getServiceManager();
$application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (Event $e) use($serviceLocator) {
$exception = $e->getParam('exception');
$serviceLocator->get('Zend\\Log\\Logger')->crit($exception);
});
$application->getEventManager()->attach(MvcEvent::EVENT_RENDER_ERROR, function (Event $e) use($serviceLocator) {
$exception = $e->getParam('exception');
$serviceLocator->get('Zend\\Log\\Logger')->crit($exception);
});
}
示例14: unserializeSingle
public function unserializeSingle(MvcEvent $event, $mode)
{
if (count($event->getParam('deeperResource')) > 0 || ($result = $event->getResult())) {
return $event->getResult();
}
$data = $event->getParam('data');
$id = $event->getParam('id');
$options = $event->getTarget()->getOptions();
if ($property = $options->getProperty()) {
$data[$property] = $id;
}
$result = new Result($event->getTarget()->getOptions()->getManifest()->getServiceManager()->get('unserializer')->fromArray($data, $event->getTarget()->getOptions()->getClass(), $event->getParam('document'), $mode));
$event->setResult($result);
return $result;
}
示例15: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$events = StaticEventManager::getInstance();
$serviceManager = $e->getApplication()->getServiceManager();
$appConfig = $serviceManager->get('Config');
$logger = new Logger();
if (!isset($appConfig['operation_logger'])) {
throw new \RuntimeException("Logger not properly configured");
}
if (!isset($appConfig['operation_logger']['priority_filter'])) {
throw new \RuntimeException("You must specify a 'priority_filter' config param");
}
$logFilter = new PriorityFilter($appConfig['operation_logger']['priority_filter']);
if (!is_null($appConfig['operation_logger']['db_adapter'])) {
if (empty($appConfig['operation_logger']['logger_table'])) {
throw new \RuntimeException("You must specify a 'logger_table' config param");
}
$dbAdapter = $serviceManager->get($appConfig['operation_logger']['db_adapter']);
if (!$dbAdapter instanceof \Zend\Db\Adapter\Adapter) {
throw new \RuntimeException("Failed to load database adapter for logger");
}
$tableMapping = array('timestamp' => 'event_date', 'priorityName' => 'priority', 'message' => 'event', 'extra' => array('id_operation_log' => 'id_operation_log', 'note' => 'note', 'table' => 'table_name', 'id_user' => 'id_user', 'username' => 'username', 'id_row' => 'id_row', 'field' => 'field', 'value_old' => 'value_old', 'value_new' => 'value_new', 'source' => 'source', 'uri' => 'uri', 'ip' => 'ip', 'session_id' => 'session_id'));
$logWriter = new DbWriter($dbAdapter, $appConfig['operation_logger']['logger_table'], $tableMapping);
$logWriter->addFilter($logFilter);
$logger->addWriter($logWriter);
}
// nel caso si volgia fare un file LOG
if (isset($appConfig['operation_logger']['log_file']) && !is_null($appConfig['operation_logger']['log_file'])) {
$streamWriter = new StreamWriter($appConfig['operation_logger']['log_file']);
$streamWriter->addFilter($logFilter);
$logger->addWriter($streamWriter);
}
$request = $e->getApplication()->getRequest();
$remoteAddress = new RemoteAddress();
Logger::registerErrorHandler($logger, true);
Logger::registerExceptionHandler($logger);
// Attacco evento per trigger LOG! (evento: operation-log)
$events->attach("*", 'operation-log', function (\Zend\EventManager\Event $e) use($logger, $request, $remoteAddress, $serviceManager) {
$targetClass = get_class($e->getTarget());
$message = $e->getParam('message');
$priority = $e->getParam('priority', Logger::INFO);
$zfcAuthEvents = $serviceManager->get('zfcuser_auth_service');
$idUser = $zfcAuthEvents->hasIdentity() ? $zfcAuthEvents->getIdentity()->getId() : (array_key_exists('id_user', $message) ? $message['id_user'] : 'guest');
$displayName = $zfcAuthEvents->hasIdentity() ? $zfcAuthEvents->getIdentity()->getDisplayName() : (array_key_exists('username', $message) ? $message['username'] : 'guest');
$extras = array('id_operation_log' => null, 'note' => array_key_exists('note', $message) ? $message['note'] : null, 'table_name' => array_key_exists('table', $message) ? $message['table'] : null, 'operation' => array_key_exists('operation', $message) ? $message['operation'] : null, 'id_user' => $idUser, 'username' => $displayName, 'id_row' => array_key_exists('id_row', $message) ? $message['id_row'] : null, 'field' => array_key_exists('field', $message) ? $message['field'] : null, 'value_old' => array_key_exists('value_old', $message) ? $message['value_old'] : null, 'value_new' => array_key_exists('value_new', $message) ? $message['value_new'] : null, 'source' => $targetClass, 'uri' => $request->getUriString(), 'ip' => $remoteAddress->getIpAddress(), 'session_id' => session_id());
$logger->log($priority, $message['message'], $extras);
});
}