本文整理汇总了PHP中Zend\EventManager\EventInterface::getTarget方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::getTarget方法的具体用法?PHP EventInterface::getTarget怎么用?PHP EventInterface::getTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventInterface
的用法示例。
在下文中一共展示了EventInterface::getTarget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModulosCarregados
public function getModulosCarregados(Event $e)
{
echo $e->getName() . "<br>";
echo get_class($e->getTarget());
$moduleManager = $e->getTarget();
print_r($moduleManager->getLoadedModules());
}
示例2: onBootstrap
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
/* @var $app \Zend\Mvc\ApplicationInterface */
$app = $e->getTarget();
$events = $app->getEventManager()->getSharedManager();
// Attach to helper set event and load the entity manager helper.
$events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
/* @var $cli \Symfony\Component\Console\Application */
$cli = $e->getTarget();
ConsoleRunner::addCommands($cli);
$cli->addCommands(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
/* @var $sm ServiceLocatorInterface */
$sm = $e->getParam('ServiceManager');
/* @var $em \Doctrine\ORM\EntityManager */
$em = $sm->get('doctrine.entitymanager.orm_default');
$helperSet = $cli->getHelperSet();
$helperSet->set(new DialogHelper(), 'dialog');
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
});
$config = $app->getServiceManager()->get('Config');
$app->getServiceManager()->get('doctrine.entity_resolver.orm_default');
if (isset($config['zenddevelopertools']['profiler']['enabled']) && $config['zenddevelopertools']['profiler']['enabled']) {
$app->getServiceManager()->get('doctrine.sql_logger_collector.orm_default');
}
}
示例3: onBootstrap
public function onBootstrap(EventInterface $e)
{
$application = $e->getTarget();
$eventManager = $application->getEventManager();
$services = $application->getServiceManager();
$services->get('Server');
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractController', 'dispatch', function ($e) {
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
$config = $e->getApplication()->getServiceManager()->get('config');
if (isset($config['module_layouts'][$moduleNamespace])) {
$controller->layout($config['module_layouts'][$moduleNamespace]);
}
}, 100);
$eventManager->attach('route', function ($event) {
$sm = $event->getApplication()->getServiceManager();
$config = $event->getApplication()->getServiceManager()->get('Config');
$localesConfig = $config['locales'];
$locales = $localesConfig['list'];
$locale = $event->getRouteMatch()->getParam('locale', null);
if (empty($locale)) {
$locale = isset($_COOKIE['locale']) ? $_COOKIE['locale'] : $localesConfig['default']['code'];
}
if (in_array($locale, array_keys($locales))) {
$locale = $locales[$locale]['code'];
} else {
$locale = $localesConfig['default']['code'];
}
$translator = $sm->get('translator');
$translator->setLocale($locale);
$httpServer = "";
if (isset($_SERVER['HTTP_HOST'])) {
$httpServer = $_SERVER['HTTP_HOST'];
}
setcookie('locale', $locale, time() + 3600, '/', $httpServer);
}, -10);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach('dispatch.error', function ($event) use($services) {
$event->getResult()->setTerminal(TRUE);
$exception = $event->getResult()->exception;
$error = $event->getError();
if (!$exception && !$error) {
return;
}
$service = $services->get('Likerow\\ErrorHandler');
if ($exception) {
$service->logException($exception, $services->get('Mail'));
}
if ($error) {
$service->logError('Dispatch ERROR: ' . $error, $services->get('Mail'));
}
});
}
示例4: onBootstrap
public function onBootstrap(EventInterface $e)
{
$t = $e->getTarget();
$t->getEventManager()->attach($t->getServiceManager()->get('ZfcRbac\\View\\Strategy\\UnauthorizedStrategy'));
$events = $e->getApplication()->getEventManager()->getSharedManager();
$events->attach('ZfcUser\\Form\\Login', 'init', function ($e) {
$form = $e->getTarget();
$form->get('identity')->setLabel("Nom d'utilisateur");
$form->get('credential')->setLabel("Mot de passe");
$form->get('submit')->setLabel("Se connecter");
});
}
示例5: onBootstrap
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
$config = $e->getTarget()->getServiceManager()->get('Config');
$config = isset($config['view_manager']) ? $config['view_manager'] : array();
if ($e->getRequest() instanceof ConsoleRequest || empty($config['display_exceptions'])) {
return;
}
$this->run = new Run();
$this->run->register();
// set up whoops config
$prettyPageHandler = new PrettyPageHandler();
if (isset($config['editor'])) {
if ($config['editor'] == 'phpStorm') {
$localPath = null;
if (isset($config['local_path'])) {
$localPath = $config['local_path'];
}
$prettyPageHandler->setEditor(function ($file, $line) use($localPath) {
if ($localPath) {
// if your development server is not local it's good to map remote files to local
$translations = array('^' . __DIR__ => $config['editor_path']);
// change to your path
foreach ($translations as $from => $to) {
$file = preg_replace('#' . $from . '#', $to, $file, 1);
}
}
return "pstorm://{$file}:{$line}";
});
} else {
$prettyPageHandler->setEditor($config['editor']);
}
}
if (!empty($config['json_exceptions']['display'])) {
$jsonHandler = new JsonResponseHandler();
if (!empty($config['json_exceptions']['show_trace'])) {
$jsonHandler->addTraceToOutput(true);
}
if (!empty($config['json_exceptions']['ajax_only'])) {
$jsonHandler->onlyForAjaxRequests(true);
}
$this->run->pushHandler($jsonHandler);
}
if (!empty($config['whoops_no_catch'])) {
$this->noCatchExceptions = $config['whoops_no_catch'];
}
$this->run->pushHandler($prettyPageHandler);
$eventManager = $e->getTarget()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareException'));
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareException'));
}
示例6: onBootstrap
public function onBootstrap(EventInterface $e)
{
/* @var $application \Zend\Mvc\Application */
$application = $e->getTarget();
$eventManager = $application->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
//todo Delete this hack (avoid unit tests) after update BjyAuthorize module to 2.0
if (\Zend\Console\Console::isConsole()) {
return;
}
$sm = $e->getApplication()->getServiceManager();
// Add ACL information to the Navigation view helper
$authorize = $sm->get('BjyAuthorizeServiceAuthorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
ZendViewHelperNavigation::setDefaultAcl($acl);
ZendViewHelperNavigation::setDefaultRole($role);
$services = $application->getServiceManager();
$zfcServiceEvents = $services->get('zfcuser_user_service')->getEventManager();
$zfcServiceEvents->attach('register', function ($e) use($services) {
$zfcUser = $e->getParam('user');
$em = $services->get('doctrine.entitymanager.orm_default');
$configAuth = $services->get('BjyAuthorize\\Config');
$providerConfig = $configAuth['role_providers']['BjyAuthorize\\Provider\\Role\\ObjectRepositoryProvider'];
$criteria = array('roleId' => $configAuth['authenticated_role']);
$defaultUserRole = $em->getRepository($providerConfig['role_entity_class'])->findOneBy($criteria);
if ($defaultUserRole !== null) {
$zfcUser->addRole($defaultUserRole);
}
});
$application->getEventManager()->getSharedManager()->attach('ZfcUserAdmin\\Form\\EditUser', 'init', function ($e) {
// $form is a ZfcUser\Form\Register
$form = $e->getTarget();
$sm = $form->getServiceManager();
$om = $sm->get('Doctrine\\ORM\\EntityManager');
//$form->setHydrator(new \DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity($om, 'OpsWay\TocatUser\Entity\User'));
$form->add(array('name' => 'roles', 'type' => 'DoctrineModule\\Form\\Element\\ObjectMultiCheckbox', 'options' => array('label' => 'Assign Roles', 'object_manager' => $om, 'target_class' => Entity\Role::class, 'property' => 'roleId')));
$form->add(array('name' => 'groups', 'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'options' => array('label' => 'Assign Groups', 'object_manager' => $om, 'target_class' => Entity\Group::class, 'property' => 'name'), 'attributes' => array('multiple' => true)));
});
$application->getEventManager()->getSharedManager()->attach('ZfcUserAdmin\\Service\\User', 'edit', function ($e) {
$zfcUser = $e->getParam('user');
$post = $e->getParam('data');
$em = $e->getParam('form')->getServiceManager()->get('doctrine.entitymanager.orm_default');
$listRoles = $em->getRepository(Entity\Role::class)->findBy(array('id' => $post['roles']));
$zfcUser->updateRoles($listRoles);
$listGroup = $em->getRepository(Entity\Group::class)->findBy(array('id' => $post['groups']));
$zfcUser->updateGroups($listGroup);
});
}
示例7: onBootstrap
public function onBootstrap(EventInterface $e)
{
$this->serviceLocator = $e->getTarget()->getServiceManager();
$config = $e->getTarget()->getServiceManager()->get('Config');
$this->whoopsConfig = $config['arilas']['whoops'];
if ($this->whoopsConfig['disabled']) {
return;
}
$this->run = new Run();
$this->run->register();
$this->run->pushHandler($this->getHandler());
$eventManager = $e->getTarget()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareException'));
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareException'));
}
示例8: onBootstrap
/**
* {@inheritdoc}
*/
public function onBootstrap(EventInterface $e)
{
/** @var ApplicationInterface $app */
$app = $e->getTarget();
$serviceManager = $app->getServiceManager();
/** @var Options $options */
$options = $serviceManager->get('BuggymanOptions');
if ($options->getEnabled() && $options->getToken()) {
Buggyman::setToken($options->getToken());
Buggyman::setErrorLevel($options->getErrorLevel());
Buggyman::setRoot(getcwd());
Buggyman::init();
$app->getEventManager()->attach([MvcEvent::EVENT_DISPATCH_ERROR, MvcEvent::EVENT_RENDER_ERROR], function (MvcEvent $event) use($serviceManager) {
if ($event->getParam('exception') instanceof Exception) {
Buggyman::reportException($event->getParam('exception'));
}
});
if ($options->getPublicToken() && !isset($_SERVER['HTTPS'])) {
/** @var HelperPluginManager $pluginManager */
$pluginManager = $serviceManager->get('ViewHelperManager');
/** @var InlineScript $inline */
$inline = $pluginManager->get('InlineScript');
$inline($inline::FILE, 'http://cdn.buggyman.io/v1/js/' . $options->getPublicToken() . '/collector.js');
}
}
}
示例9: onBootstrap
public function onBootstrap(EventInterface $e)
{
// Récupération des erreurs en ajoutant un callback qui affiche l'erreur coté serveur
$application = $e->getTarget();
$event = $application->getEventManager();
$event->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $e) {
error_log('DISPATCH_ERROR : ' . $e->getError());
error_log($e->getControllerClass() . ' ' . $e->getController());
});
$event->attach(MvcEvent::EVENT_RENDER_ERROR, function (MvcEvent $e) {
error_log('RENDER_ERROR : ' . $e->getError());
});
$event->attach(MvcEvent::EVENT_RENDER, function (MvcEvent $e) {
$services = $e->getApplication()->getServiceManager();
$session = $services->get('session');
$rightViewModel = new ViewModel();
if (!isset($session->user)) {
$form = $services->get('MiniModule\\Form\\Authentification');
$formUser = $services->get('MiniModule\\Form\\NewUser');
$rightViewModel->setVariables(array('form' => $form, 'newUserForm' => $formUser));
$rightViewModel->setTemplate('layout/form-auth');
} else {
$rightViewModel->setVariables(array('user' => $session->user));
$rightViewModel->setTemplate('layout/info-auth');
}
$view = $e->getViewModel();
// c'est le viewModel qui contient le layout (top viewModel)
$view->addChild($rightViewModel, 'formulaireAuth');
});
}
示例10: onBootstrap
public function onBootstrap(EventInterface $e)
{
/** @var \Zend\Mvc\Application $app */
$app = $e->getTarget();
$config = $app->getConfig();
$sessionConfig = new SessionConfig();
if (isset($config['session']['options'])) {
$options = $config['session']['options'];
if (isset($options['cookie_domain']) && strpos($_SERVER['SERVER_NAME'], $options['cookie_domain']) === false) {
$options['cookie_domain'] = $_SERVER['SERVER_NAME'];
}
$sessionConfig->setOptions($options);
}
$serviceManager = $app->getServiceManager();
$storage = null;
$saveHandler = null;
if ($serviceManager->has('Session\\Service\\Storage', false)) {
/** @var \Zend\Session\Storage\StorageInterface $storage */
$storage = $serviceManager->get('Session\\Service\\Storage');
}
if ($serviceManager->has('Session\\Service\\SaveHandler', false)) {
/** @var \Zend\Session\SaveHandler\SaveHandlerInterface $saveHandler */
$saveHandler = $serviceManager->get('Session\\Service\\SaveHandler');
}
Container::setDefaultManager(new SessionManager($sessionConfig, $storage, $saveHandler));
}
示例11: onBootstrap
/**
* On bootstrap.
*
* @param MvcEvent $e
* @return void
*/
public function onBootstrap(EventInterface $e)
{
$application = $e->getTarget();
$events = $application->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($events);
}
示例12: onBootstrap
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $event)
{
/**
* @var ModuleOptions $moduleOptions
*/
$moduleOptions = $event->getTarget()->getServiceManager()->get('LemoTracy\\Options\\ModuleOptions');
if (true === $moduleOptions->getEnabled()) {
if (null !== $moduleOptions->getMode()) {
Debugger::enable($moduleOptions->getMode());
}
if (null !== $moduleOptions->getLogDirectory()) {
Debugger::$logDirectory = $moduleOptions->getLogDirectory();
}
if (null !== $moduleOptions->getLogSeverity()) {
Debugger::$logSeverity = $moduleOptions->getLogSeverity();
}
if (null !== $moduleOptions->getMaxDepth()) {
Debugger::$maxDepth = $moduleOptions->getMaxDepth();
}
if (null !== $moduleOptions->getMaxLen()) {
Debugger::$maxLen = $moduleOptions->getMaxLen();
}
if (null !== $moduleOptions->getShowBar()) {
Debugger::$showBar = $moduleOptions->getShowBar();
}
if (null !== $moduleOptions->getStrict()) {
Debugger::$strictMode = $moduleOptions->getStrict();
}
}
}
示例13: onBootstrap
public function onBootstrap(EventInterface $event)
{
/*$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);*/
$application = $event->getTarget();
$serviceManager = $application->getServiceManager();
$translator = $serviceManager->get('translator');
$translator->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']))->setFallbackLocale('en_US');
$application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) use($serviceManager) {
$request = $event->getRequest();
$response = $event->getResponse();
if (!($request instanceof HttpRequest && $response instanceof HttpResponse)) {
return;
// CLI application maybe?
}
$authAdapter = $serviceManager->get('AuthenticationAdapter');
$authAdapter->setRequest($request);
$authAdapter->setResponse($response);
$result = $authAdapter->authenticate();
if ($result->isValid()) {
return;
// OK
}
$response->setContent('Access denied');
$response->setStatusCode(HttpResponse::STATUS_CODE_401);
$event->setResult($response);
// to end
return false;
// event propagation stop
});
}
示例14: onBootstrap
public function onBootstrap(EventInterface $e)
{
/* @var \Zend\Mvc\Application $application */
$application = $e->getTarget();
$serviceManager = $application->getServiceManager();
$eventManager = $application->getEventManager();
}
示例15: onSearchPre
/**
* Set up spelling parameters.
*
* @param EventInterface $event Event
*
* @return EventInterface
*/
public function onSearchPre(EventInterface $event)
{
$backend = $event->getTarget();
if ($backend === $this->backend) {
$params = $event->getParam('params');
if ($params) {
// Set spelling parameters unless explicitly disabled:
$sc = $params->get('swissbibspellcheck');
if (!empty($sc) && $sc[0] != 'false') {
//remove the homegrown parameter only needed to activate
// the spellchecker in case of zero hits
$params->remove("swissbibspellcheck");
$this->active = true;
if (empty($this->dictionaries)) {
throw new \Exception('Spellcheck requested but no dictionary configured');
}
// Set relevant Solr parameters:
reset($this->dictionaries);
$params->set('spellcheck', 'true');
$params->set('spellcheck.dictionary', current($this->dictionaries));
// Turn on spellcheck.q generation in query builder:
$this->backend->getQueryBuilder()->setCreateSpellingQuery(true);
}
}
}
return $event;
}