本文整理汇总了PHP中Zend\EventManager\EventInterface::getParam方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::getParam方法的具体用法?PHP EventInterface::getParam怎么用?PHP EventInterface::getParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventInterface
的用法示例。
在下文中一共展示了EventInterface::getParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onCreateAnnotation
/**
* Handle annotation creation
*
* @param EventInterface $e
* @return false|\stdClass
*/
public function onCreateAnnotation(EventInterface $e)
{
$annotationClass = $e->getParam('class', false);
if (!$annotationClass) {
return false;
}
if (!isset($this->allowedAnnotations[$annotationClass])) {
return false;
}
$annotationString = $e->getParam('raw', false);
if (!$annotationString) {
return false;
}
// Annotation classes provided by the AnnotationScanner are already
// resolved to fully-qualified class names. Adding the global namespace
// prefix allows the Doctrine annotation parser to locate the annotation
// class correctly.
$annotationString = preg_replace('/^(@)/', '$1\\', $annotationString);
$parser = $this->getDocParser();
$annotations = $parser->parse($annotationString);
if (empty($annotations)) {
return false;
}
$annotation = array_shift($annotations);
if (!is_object($annotation)) {
return false;
}
return $annotation;
}
示例2: onSearchPre
/**
* Handle event. Add config values
*
* @param EventInterface $event
* @return EventInterface
*/
public function onSearchPre(EventInterface $event)
{
$backend = $event->getTarget();
if ($backend === $this->backend) {
$params = $event->getParam('params');
if ($params) {
// Set highlighting parameters unless explicitly disabled:
$hl = $params->get('hl');
if (!isset($hl[0]) || $hl[0] != 'false') {
// Add hl.q for non query events
if (!$event->getParam('query', false)) {
$lastSearch = $this->memory->retrieve();
if ($lastSearch) {
$urlParams = parse_url($lastSearch);
parse_str($urlParams['query'], $queryParams);
if (isset($queryParams['lookfor'])) {
$params->set('hl.q', '*:"' . addslashes($queryParams['lookfor']) . '"');
}
}
}
// All all highlight config fields
foreach ($this->config as $key => $value) {
$params->set('hl.' . $key, $value);
}
}
}
}
return $event;
}
示例3: __invoke
/**
* @param array|null $resource
* @param Request $request
* @param Response $response
*/
public function __invoke(EventInterface $event)
{
$resource = $event->getParam('resource');
$request = $event->getParam('request');
$formattedResource = $this->formatter->format($resource, $request->params());
$event->setParam('resource', $formattedResource);
}
示例4: handleOneToOneAnnotation
public function handleOneToOneAnnotation(EventInterface $event)
{
$annotation = $event->getParam('annotation');
if (!$annotation instanceof OneToOne) {
return;
}
$spec = $event->getParam('spec');
$spec['oneToOne'] = $annotation->getName();
}
示例5: handleManyToManyAnnotation
public function handleManyToManyAnnotation(EventInterface $event)
{
$annotation = $event->getParam('annotation');
if (!$annotation instanceof Annotation\ManyToMany) {
return;
}
$spec = $event->getParam('spec');
$spec['manyToMany'] = $annotation->getName();
}
示例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: onMissingTranslation
/**
* Event handler for missing translations
*
* @param \Zend\EventManager\EventInterface $e
*/
public function onMissingTranslation(\Zend\EventManager\EventInterface $e)
{
// Issue warning about missing translation for the 'default' text
// domain. This warning will indicate either a message string missing in
// the translation file, or accidental translator invokation when a
// string should not actually be translated.
// If a fallback locale is involved, suppress the warning for the
// standard locale.
$fallbackLocale = $e->getTarget()->getFallbackLocale();
if ((!$fallbackLocale or $e->getParam('locale') == $fallbackLocale) and $e->getParam('text_domain') == 'default') {
trigger_error('Missing translation: ' . $e->getParam('message'), E_USER_NOTICE);
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
}
示例8: onUpdate
/**
* Add current `DateTime` value for field `last_updated_at`
*
* @param EventInterface $event
*/
public function onUpdate(EventInterface $event)
{
$values = $event->getParam('values');
$now = new DateTime();
$values['last_updated_at'] = $now->format('Y-m-d h:i:s');
$event->setParam('values', $values);
}
示例9: onFormSet
/**
* Inject Form defined by type to BlogService when triggered
*
* @param EventInterface
*/
public function onFormSet(EventInterface $e)
{
$type = $e->getParam('type', 'create');
$service = $this->serviceLocator->get('Blog\\Service\\Blog');
$form = $this->serviceLocator->get('Blog\\Form\\' . ucfirst($type));
$service->setForm($form, $type);
}
示例10: onBootstrap
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
/** @var $application \Zend\Mvc\Application */
$application = $e->getParam('application');
$listener = $application->getServiceManager()->get('StrokerCache\\Listener\\CacheListener');
$application->getEventManager()->attach($listener);
}
示例11: onRenderEntity
public function onRenderEntity(EventInterface $event)
{
$halEntity = $event->getParam('entity');
$link = new \ZF\Hal\Link\Link('search');
$link->setUrl('http://www.google.com/?q=thing' . $halEntity->entity->getId());
$halEntity->getLinks()->add($link);
}
示例12: __invoke
/**
* @param EventInterface $event
*/
public function __invoke(EventInterface $event)
{
/** @var Message $message */
$message = $event->getParam('message');
/** @var Template $template */
$template = $event->getParam('template');
/** @var \Zend\Mail\AddressList $toAddress */
$toAddress = $message->getTo();
$toAddress->rewind();
$fromAddress = $message->getFrom();
$fromAddress->rewind();
/** @var \Zend\Mime\Message $body */
$body = $message->getBody();
$entry = new MailLogEntry(['mailFrom' => $fromAddress->current()->getEmail(), 'mailTo' => $toAddress->current()->getEmail(), 'subject' => $message->getSubject(), 'layoutId' => $template->getLayoutId(), 'templateId' => $template->getId(), 'body' => $body->getPartContent(0), 'calculatedVars' => json_encode($event->getParam('data'))]);
$this->logRepository->add($entry);
}
示例13: 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);
}
示例14: 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;
}
示例15: 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');
}
}