/**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
 /**
  * @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);
 }
 public function handleOneToOneAnnotation(EventInterface $event)
 {
     $annotation = $event->getParam('annotation');
     if (!$annotation instanceof OneToOne) {
         return;
     }
     $spec = $event->getParam('spec');
     $spec['oneToOne'] = $annotation->getName();
 }
 public function handleManyToManyAnnotation(EventInterface $event)
 {
     $annotation = $event->getParam('annotation');
     if (!$annotation instanceof Annotation\ManyToMany) {
         return;
     }
     $spec = $event->getParam('spec');
     $spec['manyToMany'] = $annotation->getName();
 }
Example #6
0
 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);
     });
 }
Example #7
0
 /**
  * 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
 }
 /**
  * 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);
 }
Example #9
0
 /**
  * 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);
 }
Example #10
0
 /**
  * {@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);
 }
Example #11
0
 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);
 }
Example #12
0
 /**
  * @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);
 }
Example #13
0
 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);
 }
 /**
  * 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;
 }
Example #15
0
 /**
  * {@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');
     }
 }
Example #16
0
 /**
  * Listen to the bootstrap event
  *
  * @param EventInterface $e
  *
  * @return array
  */
 public function onBootstrap(EventInterface $e)
 {
     $app = $e->getParam('application');
     $em = $app->getEventManager();
     $em->attach(MvcEvent::EVENT_DISPATCH, function ($event) {
         $event->getApplication()->getServiceManager()->get(AffiliationNavigationService::class)->update();
     });
 }
Example #17
0
 /**
  * Inject Table defined by type to PizzaService when triggered
  *
  * @param EventInterface
  */
 public function onTableSet(EventInterface $e)
 {
     $type = $e->getParam('type', 'rentals');
     $tableName = StaticFilter::execute($type, 'wordunderscoretocamelcase');
     $service = $this->serviceLocator->get('Rentals\\Service\\Rentals');
     $form = $this->serviceLocator->get('Rentals\\Table\\' . $tableName);
     $service->setTable($form, $type);
 }
Example #18
0
 /**
  * Listen to the bootstrap event
  *
  * @param EventInterface $e
  *
  * @return array
  */
 public function onBootstrap(EventInterface $e)
 {
     $app = $e->getParam('application');
     $em = $app->getEventManager();
     $em->attach(MvcEvent::EVENT_DISPATCH, function ($event) {
         $event->getApplication()->getServiceManager()->get('program_nda_navigation_service')->update();
     });
 }
 /**
  * Discover the fallback name via reflection
  *
  * @param  \Zend\EventManager\EventInterface $e
  * @return string
  */
 public function discoverFallbackName($e)
 {
     $reflection = $e->getParam('reflection');
     if ($reflection instanceof ReflectionClass) {
         return $reflection->getShortName();
     }
     return $reflection->getName();
 }
Example #20
0
 /**
  * @param \Zend\EventManager\EventInterface $e
  */
 public function handleAllowEmpty($e)
 {
     $formSpec = $e->getParam('formSpec');
     if (!(isset($formSpec['object']) && $this->objectManager->getMetadataFactory()->hasMetadataFor($formSpec['object']))) {
         return;
     }
     $metadata = $this->objectManager->getClassMetadata($formSpec['object']);
     $fieldName = $e->getParam('elementSpec')['spec']['name'];
     if (!$metadata->hasField($fieldName)) {
         return;
     }
     $fieldMapping = $metadata->getFieldMapping($fieldName);
     $inputSpec = $e->getParam('inputSpec');
     if (!isset($inputSpec['allow_empty'])) {
         $inputSpec['allow_empty'] = $fieldMapping['nullable'];
         $e->setParam('inputSpec', $inputSpec);
     }
 }
Example #21
0
 /**
  * @param EventInterface $e
  * @return void
  */
 public function handleTitleAnnotation(EventInterface $e)
 {
     $annotation = $e->getParam('annotation');
     if (!$annotation instanceof Title) {
         return;
     }
     $datagridSpec = $e->getParam('datagridSpec');
     $datagridSpec['title'] = array('singular' => $annotation->singular, 'plural' => $annotation->plural);
 }
Example #22
0
 public function __invoke(EventInterface $e)
 {
     $page = $e->getParam('page');
     $container = $this->helper->getContainer();
     $navPage = $container->findOneBy('route', $page->getId());
     if ($navPage instanceof Page) {
         $navPage->setActive(true);
     }
 }
Example #23
0
 /**
  * @{inheritdoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     $app = $e->getParam('application');
     $em = $app->getEventManager();
     $eventManager = $e->getApplication()->getEventManager();
     //$result=$eventManager->attach('route', array($this, 'loadConfigurations'), 2);
     $em->attach(MvcEvent::EVENT_DISPATCH, array($this, 'selectLayoutBasedOnRoute'));
     $em->attach(MvcEvent::EVENT_DISPATCH, array($this, 'selectLayoutBasedOnRoute1'));
 }
Example #24
0
 public function onReceivedNodeReceipt(EventInterface $e)
 {
     /** @var NodeInterface $node */
     $node = $e->getParam('node');
     /** @var Client $client */
     $client = $e->getTarget();
     $params = ['id' => $node->getAttribute('id'), 'node' => $node];
     $client->getEventManager()->trigger('onReceiptClient', $client, $params);
 }
 /**
  * On user registration
  *
  * @param EventInterface $e
  */
 public function onUserRegistration(EventInterface $e)
 {
     $user = $e->getParam('user');
     if ($this->getOptions()->getSendVerificationEmail() && $this->getZfcUserOptions()->getEnableRegistration()) {
         $this->sendVerificationEmail($user);
     } elseif ($this->getOptions()->getSendPasswordRequestEmail() && !$this->getZfcUserOptions()->getEnableRegistration()) {
         $this->sendPasswordRequestEmail($user);
     }
 }
 /**
  * Listen to onCreateAnnotation, and attempt to return an annotation object
  * instance.
  *
  * If the annotation class or alias is not registered, immediately returns
  * false. Otherwise, resolves the class, clones it, and, if any content is
  * present, calls {@link AnnotationInterface::initialize()} with the
  * content.
  *
  * @param  EventInterface $e
  * @return false|AnnotationInterface
  */
 public function onCreateAnnotation(EventInterface $e)
 {
     $class = $e->getParam('class', false);
     if (!$class || !$this->hasAnnotation($class)) {
         return false;
     }
     $content = $e->getParam('content', '');
     $content = trim($content, '()');
     if ($this->hasAlias($class)) {
         $class = $this->resolveAlias($class);
     }
     $index = array_search($class, $this->annotationNames);
     $annotation = $this->annotations[$index];
     $newAnnotation = clone $annotation;
     if ($content) {
         $newAnnotation->initialize($content);
     }
     return $newAnnotation;
 }
 /**
  * @param EventInterface $event
  * @return bool
  */
 public function accept(EventInterface $event)
 {
     // This is the default behavior (allow access, if not otherwise specified)
     $accept = true;
     $page = $event->getParam('page');
     if ($page instanceof AbstractPage && $page->getPermission() !== null) {
         $accept = $this->authorizationService->isAllowed($page->getPermission(), $page);
     }
     return $accept;
 }
 /**
  * @param EventInterface $e
  */
 public function handleMappingAnnotation(EventInterface $e)
 {
     $annotation = $e->getParam('annotation');
     if (!$annotation instanceof OneToOne && !$annotation instanceof OneToMany && !$annotation instanceof ManyToOne && !$annotation instanceof ManyToMany) {
         return;
     }
     $elementSpec = $e->getParam('elementSpec');
     $options = array('target_class' => $annotation->targetEntity);
     if (isset($elementSpec['spec']['options'])) {
         if (is_array($elementSpec['spec']['options'])) {
             $elementSpec['spec']['options'] = array_merge($elementSpec['spec']['options'], $options);
         }
         if ($elementSpec['spec']['options'] instanceof ArrayObject) {
             $elementSpec['spec']['options'] = array_merge($elementSpec['spec']['options']->getArrayCopy(), $options);
         }
     } else {
         $elementSpec['spec']['options'] = $options;
     }
 }
Example #29
0
 /**
  * @internal
  */
 public function onBootstrap(\Zend\EventManager\EventInterface $e)
 {
     $eventManager = $e->getParam('application')->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'forceLogin'));
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'setStrictVars'));
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'setMenu'));
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'setLayoutTitle'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'onError'));
     $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'onError'));
 }
Example #30
0
 /**
  * @param EventInterface $e
  */
 public function onReceivedNode(EventInterface $e)
 {
     /** @var NodeInterface $node */
     $node = $e->getParam('node');
     /** @var Client $client */
     $client = $e->getTarget();
     // triggering public event
     $client->getEventManager()->trigger('onLoginFailed', $client, ['node' => $node]);
     throw new \RuntimeException("Login failed");
 }