/** * Handles form based authentication. * * @param Event $event An Event instance */ public function handle(Event $event) { $request = $event->get('request'); if ($this->options['check_path'] !== $request->getPathInfo()) { return; } try { if (null === ($token = $this->attemptAuthentication($request))) { return; } $response = $this->onSuccess($request, $token); } catch (AuthenticationException $failed) { $response = $this->onFailure($event->getSubject(), $request, $failed); } $event->setReturnValue($response); return true; }
public function handle(Event $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) { return false; } $exception = $event->getParameter('exception'); if (null !== $this->logger) { $this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage())); } else { error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine())); } $class = $this->container->getParameter('exception_manager.class'); $logger = $this->container->has('logger.debug') ? $this->container->get('logger.debug') : null; $attributes = array('_controller' => $this->controller, 'manager' => new $class($exception, $event->getParameter('request'), $logger)); $request = $event->getParameter('request')->duplicate(null, null, $attributes); try { $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true); } catch (\Exception $e) { if (null !== $this->logger) { $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage())); } return false; } $event->setReturnValue($response); return true; }
public function handle(Event $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) { return false; } $exception = $event->getParameter('exception'); $request = $event->getParameter('request'); if (null !== $this->logger) { $this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage())); } else { error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine())); } $logger = null !== $this->logger ? $this->logger->getDebugLogger() : null; $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $logger, 'format' => 0 === strncasecmp(PHP_SAPI, 'cli', 3) ? 'txt' : $request->getRequestFormat()); $request = $request->duplicate(null, null, $attributes); try { $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true); } catch (\Exception $e) { if (null !== $this->logger) { $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage())); } // re-throw the exception as this is a catch-all throw new \RuntimeException('Exception thrown when handling an exception.', 0, $e); } $event->setReturnValue($response); return true; }
/** * @see \HealthCareAbroad\MailerBundle\Listener\NotificationsListener::getData() */ public function getData(Event $event) { $institution = $event->getSubject(); $router = $this->container->get('router'); $urlDefaultCenter = $router->generate('institution_medicalCenter_index', array(), true); $urlDefaultCenterGallery = $router->generate('institution_mediaGallery_index', array(), true); $institutionType = $institution->getType(); switch ($institutionType) { case InstitutionTypes::SINGLE_CENTER: $urlTreatmentList = $urlDefaultCenter . '#specializations'; break; case InstitutionTypes::MULTIPLE_CENTER: $urlTreatmentList = $urlDefaultCenter; break; default: $urlTreatmentList = ''; } switch ($institutionType) { case InstitutionTypes::SINGLE_CENTER: $urlFeatureDoctors = $urlDefaultCenter . '#doctors'; break; case InstitutionTypes::MULTIPLE_CENTER: $urlFeatureDoctors = $urlDefaultCenter; break; default: $urlFeatureDoctors = ''; } $urlContactDetails = $urlDefaultCenter . '#contact-details'; $accountOwnerEmail = $this->container->get('services.institution')->getAccountOwner($institution)->getEmail(); return array('institution_name' => $institution->getName(), 'to' => $accountOwnerEmail, 'url' => array('add_centers' => $urlDefaultCenter, 'upload_photos' => $urlDefaultCenterGallery, 'list_treatments' => $urlTreatmentList, 'feature_doctors' => $urlFeatureDoctors, 'contact_info' => $urlContactDetails)); }
/** * {@inheritdoc} */ public static function determineQualifiedEvents(Event $event, $event_name, array &$event_definition) { $events_suffixes = []; if ($event instanceof \Drupal\rules\Event\EntityEvent) { $events_suffixes[] = $event->getSubject()->bundle(); } return $events_suffixes; }
public function getData(Event $event) { $subject = $event->getSubject(); switch ($event->getName()) { case MailerBundleEvents::NOTIFICATIONS_PASSWORD_RESET: return array('to' => $subject['email'], 'email' => array('hca_account' => $subject['email']), 'url' => array('password_reset' => $this->container->get('router')->generate('institution_set_new_password', array('token' => $subject['token']), true)), 'link_expiration' => $subject['expiresIn'] . ' days'); case MailerBundleEvents::NOTIFICATIONS_PASSWORD_CONFIRM: return array('to' => $subject['email']); default: throw new \Exception('Unsupported event.'); } }
public function getData(Event $event) { $inquiry = $event->getSubject(); $institution = $inquiry->getInstitution(); $institutionMedicalCenter = $inquiry->getInstitutionMedicalCenter(); $router = $this->container->get('router'); if ($institutionMedicalCenter) { $facilityName = $institutionMedicalCenter->getName() . ' at ' . $institution->getName(); $urlFacility = $router->generate('frontend_institutionMedicalCenter_profile', array('institutionSlug' => $institution->getSlug(), 'imcSlug' => $institutionMedicalCenter->getSlug()), true); $to = $institutionMedicalCenter->getContactEmail(); } else { $facilityName = $institution->getName(); $routeName = InstitutionService::getInstitutionRouteName($institution); $urlFacility = $router->generate($routeName, array('institutionSlug' => $institution->getSlug()), true); } if (empty($to)) { if (!($to = $institution->getContactEmail())) { $to = $this->container->get('services.institution')->getAccountOwner($institution)->getEmail(); } } return array('inquiry' => array('name' => $inquiry->getInquirerName(), 'email' => $inquiry->getInquirerEmail(), 'message' => $inquiry->getMessage()), 'to' => $to, 'facility_name' => $facilityName, 'url' => array('facility' => $urlFacility)); }
/** * Handle Step Events & Fire Associated Hooks. * * @param Event $event event */ public function fireStepHooks(Event $event) { switch ($event->getName()) { case 'step.run.before': $hookName = 'step.before'; break; case 'step.run.after': $hookName = 'step.after'; break; } $step = $event->getSubject(); $tagsFilter = $this->tagsFilter; $nameFilter = $this->nameFilter; $this->fireHooks($event, $hookName, function ($hook) use($step, $tagsFilter) { return $tagsFilter->isStepMatchFilter($step, $hook[0]); }, function ($hook) use($step, $nameFilter) { return $nameFilter->isStepMatchFilter($step, $hook[0]); }); }
public function isEventProcessable(Event $event) { $institutionMedicalCenter = $event->getSubject(); return InstitutionMedicalCenterStatus::APPROVED == $institutionMedicalCenter->getStatus(); }
public function handle(Event $event) { static $handling; if (true === $handling) { return false; } $handling = true; $exception = $event->get('exception'); $request = $event->get('request'); if (null !== $this->logger) { $this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage())); } else { error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine())); } $logger = null !== $this->logger ? $this->logger->getDebugLogger() : null; $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $logger, 'format' => 0 === strncasecmp(PHP_SAPI, 'cli', 3) ? 'txt' : $request->getRequestFormat()); $request = $request->duplicate(null, null, $attributes); try { $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true); } catch (\Exception $e) { $message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()); if (null !== $this->logger) { $this->logger->err($message); } else { error_log($message); } throw $exception; } $event->setReturnValue($response); $handling = false; return true; }
/** * Handle any event * * If this method does not fit to your need, you are advised to extend this * class and modify this method to suit your own needs * * @param string $resourceType * @param string $action * @param Event $event */ protected function onEvent($resourceType, $action, Event $event) { $idList = null; $data = null; $key = $resourceType . ':' . $action; $sendOnDefaultChan = true; $additionalChanId = []; if ($event instanceof ResourceEvent) { $data = $event->getArguments(); $idList = $event->getResourceIdList(); $additionalChanId = $event->getChanIdList(); $sendOnDefaultChan = $event->shouldKeepDefaultChan(); } else { if ($event instanceof GenericEvent) { $data = $event->getArguments(); // Attempt to do a best guess at the resource identifier if (isset($event['id'])) { $idList = [$event['id']]; } else { $subject = $event->getSubject(); if (is_scalar($subject)) { $idList = [$subject]; } else { if (method_exists($subject, 'getId')) { $idList = [$subject->getId()]; } else { if (property_exists($subject, 'id')) { $idList = [$subject->id]; } } } } } } if (isset($idList)) { // Proceed with pre-configured overrides if ($sendOnDefaultChan && isset($this->chanBlockingOverrides[$key])) { $additionalChanId = array_merge($additionalChanId, $this->chanBlockingOverrides[$key]); // FIXME override should not be blocking default chans // @TODO add a blocking boolean tag attribute (false by default) // $sendOnDefaultChan = false; } if ($additionalChanId) { foreach ($idList as $id) { if ($sendOnDefaultChan) { $additionalChanId[] = $this->service->getChanId($resourceType, $id); } $this->service->notifyChannel($additionalChanId, $resourceType, $id, $action, $data); } } else { if ($sendOnDefaultChan) { foreach ($idList as $id) { $this->service->notify($resourceType, $id, $action, $data); } } } // We might end up sending nothing, as soon as any of the listeners // explicitly forbid to send on the default chan, and we have no // additional chans. } }
/** * Listen to `feature.run.after` event & write feature xml. * * @param Event $event notified event */ public function flushFeatureXML(Event $event) { $feature = $event->getSubject(); $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $xml .= sprintf('<testsuite errors="0" failures="%d" name="%s" tests="%d" time="%f">' . "\n", $this->failuresCount, $feature->getTitle(), $this->testsCount, $this->totalTime); $xml .= $this->xml; $xml .= '</testsuite>'; $event = new Event($this, 'behat.output.write', array('string' => $xml, 'file' => 'TEST-' . basename($feature->getFile(), '.feature') . '.xml', 'newline' => false)); $this->dispatcher->notify($event); }
/** * Print step information (filepath, fileline, exception description). * * @param Event $event step event * @param string $type information type (pending/failed etc.) */ protected function printStepEventInformation(Event $event, $type) { $step = $event->getSubject(); // Print step information $description = $this->colorize(sprintf(" In step `%s %s'.", $step->getType(), $step->getText()), $type); $this->maxDescriptionLength = $this->maxDescriptionLength > mb_strlen($description) ? $this->maxDescriptionLength : mb_strlen($description); $this->write($description, null, false); if (null !== $event->getParameter('definition')) { $this->printLineSourceComment(mb_strlen($description), $event->getParameter('definition')->getFile(), $event->getParameter('definition')->getLine()); } else { $this->write(); } // Print scenario information $item = $step->getParent(); if ($item instanceof BackgroundNode) { $description = $this->colorize(' From scenario background.', $type); } elseif ($item instanceof ScenarioNode) { $description = $this->colorize(sprintf(" From scenario %s.", $item->getTitle() ? sprintf("`%s'", $item->getTitle()) : '***'), $type); } $this->maxDescriptionLength = $this->maxDescriptionLength > mb_strlen($description) ? $this->maxDescriptionLength : mb_strlen($description); $this->write($description, null, false); $this->printLineSourceComment(mb_strlen($description), $item->getFile(), $item->getLine()); $this->write(); }
/** * Handles security related exceptions. * * @param Event $event An Event instance */ public function handleException(Event $event) { $exception = $event->getParameter('exception'); $request = $event->getParameter('request'); if ($exception instanceof AuthenticationException) { if (null !== $this->logger) { $this->logger->info(sprintf('Authentication exception occurred; redirecting to authentication entry point (%s)', $exception->getMessage())); } try { $response = $this->startAuthentication($request, $exception); } catch (\Exception $e) { $event->setParameter('exception', $e); return; } } elseif ($exception instanceof AccessDeniedException) { $token = $this->context->getToken(); if (null === $token || $token instanceof AnonymousToken) { if (null !== $this->logger) { $this->logger->info('Access denied (user is anonymous); redirecting to authentication entry point'); } try { $response = $this->startAuthentication($request, new InsufficientAuthenticationException('Full authentication is required to access this resource.', $token, 0, $exception)); } catch (\Exception $e) { $event->setParameter('exception', $e); return; } } else { if (null !== $this->logger) { $this->logger->info('Access is denied (and user is not anonymous)'); } if (null === $this->errorPage) { return; } $subRequest = Request::create($this->errorPage); $subRequest->attributes->set(SecurityContext::ACCESS_DENIED_ERROR, $exception->getMessage()); try { $response = $event->getSubject()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); } catch (\Exception $e) { if (null !== $this->logger) { $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage())); } $event->setParameter('exception', new \RuntimeException('Exception thrown when handling an exception.', 0, $e)); return; } $response->setStatusCode(403); } } else { return; } $event->setReturnValue($response); return true; }
/** * Listen to some event & print step definition snippets. * * @param Event $event notified event */ public function printSnippets(Event $event) { $statistics = $event->getSubject()->get('behat.statistics_collector'); if (count($statistics->getDefinitionsSnippets())) { $this->write("\n" . $this->getTranslator()->trans("You can implement step definitions for undefined steps with these snippets:") . "\n", 'undefined'); foreach ($statistics->getDefinitionsSnippets() as $key => $snippet) { $this->write($snippet, 'undefined'); $this->write(); } } }
/** * delegates the event to the set connectors * * @param Event $event * @return boolean */ public function process(Event $event) { $message = $event->getSubject(); return $this->doProcess($message); }
/** * Listen to `step.run` and find/call proper step definition. * * @param Event $event step event * * @throws Everzet\Behat\Exception\BehaviorException */ public function runStep(Event $event) { $definition = $this->findDefinition($event->getSubject()); $definition->run($event->getParameter('world')); }
/** * @param \Symfony\Component\EventDispatcher\Event $event */ public function setAuth(Event $event) { $client = $event->getSubject()->getRequestHandler()->getClient(); $client->setDefaultOption('auth', array($this->username, $this->password, 'Basic')); }
/** * On dispatch event listener - called on any event * * @param Event $event * @param string $eventName * @return void */ public function onError(Event $event, $eventName) { $this->logger->error(sprintf("Error (%s)'%s' | %s@%s | %s \n", $event["error"]->getCode(), $event["error"]->getMessage(), $event->getSubject()->getExchangeName(), $event->getSubject()->getRoutingKey(), $event->getSubject()->isRedelivery() ? "redelivery" : "new"), ["message" => $event["error"]->getMessage(), "code" => $event["error"]->getCode(), "class" => get_class($event["error"]), "eventName" => $eventName]); }
/** * Listen to `suite.run.after` event & print generated markup to console or file. * * @param Event $event */ public function flushHTML(Event $event) { $statistics = $event->getSubject()->get('behat.statistics_collector'); $html = '<div class="statistics ' . ($statistics->isPassed() ? 'passed' : 'failed') . '">'; $html .= '<p class="scenarios">'; $html .= $this->translator->transChoice('{0} No scenarios|{1} 1 scenario|]1,Inf] %1% scenarios', $statistics->getScenariosCount(), array('%1%' => $statistics->getScenariosCount())); $statuses = array(); foreach ($statistics->getScenariosStatuses() as $status => $count) { if ($count) { $statuses[] = $this->translator->transChoice("[1,Inf] %1% {$status}", $count, array('%1%' => $count)); } } $html .= count($statuses) ? ' ' . sprintf('(%s)', implode(', ', $statuses)) : ''; $html .= '</p>'; $html .= '<p class="steps">'; $html .= $this->translator->transChoice('{0} No steps|{1} 1 step|]1,Inf] %1% steps', $statistics->getStepsCount(), array('%1%' => $statistics->getStepsCount())); $statuses = array(); foreach ($statistics->getStepsStatuses() as $status => $count) { if ($count) { $statuses[] = $this->translator->transChoice("[1,Inf] %1% {$status}", $count, array('%1%' => $count)); } } $html .= count($statuses) ? ' ' . sprintf('(%s)', implode(', ', $statuses)) : ''; $html .= '</p>'; $html .= '</div>'; $html = strtr($this->getHTMLTemplate(), array('{{ body }}' => $html . $this->html)); $event = new Event($this, 'behat.output.write', array('string' => $html, 'newline' => false)); $this->dispatcher->notify($event); }
public function isEventProcessable(Event $event) { $institutionMedicalCenter = $event->getSubject(); return InstitutionTypes::MULTIPLE_CENTER == $institutionMedicalCenter->getInstitution()->getType(); }
public function preInsert(Event $event) { $subject = $event->getSubject(); $subject->source = 'pre_insert'; $this->events[] = $event; }
protected function addCall(Event $event, $listener, $type) { $listener = $this->listenerToString($listener); if (null !== $this->logger) { $this->logger->debug(sprintf('Notified event "%s" to listener "%s" (%s)', $event->getName(), $listener, $type)); } $this->called[$event->getName() . '.' . $listener] = array('event' => $event->getName(), 'caller' => null !== $event->getSubject() ? get_class($event->getSubject()) : null, 'listener' => $listener); }
/** * Listen to `step.run.after` event & print step run information. * * @param Event $event notified event */ public function printStep(Event $event) { $step = $event->getSubject(); if (!$step->getParent() instanceof BackgroundNode || !$this->backgroundPrinted) { if (!$step->getParent() instanceof OutlineNode || !$this->outlineStepsPrinted) { // Get step description $text = $this->outlineStepsPrinted ? $step->getText() : $step->getCleanText(); $printableText = $text; $description = sprintf(' %s %s', $step->getType(), $text); // Colorize arguments if (null !== $event->getParameter('definition') && StepTester::UNDEFINED !== $event->getParameter('result')) { $argStartCode = $this->colorizeStart($event->getParameter('result') + 10); $argFinishCode = $this->colorizeFinish() . $this->colorizeStart($event->getParameter('result')); $printableText = preg_replace_callback($event->getParameter('definition')->getRegex(), function ($matches) use($argStartCode, $argFinishCode) { $text = array_shift($matches); foreach ($matches as $match) { $text = strtr($text, array('"' . $match . '"' => '"' . $argStartCode . $match . $argFinishCode . '"', '\'' . $match . '\'' => '\'' . $argStartCode . $match . $argFinishCode . '\'', ' ' . $match . ' ' => ' ' . $argStartCode . $match . $argFinishCode . ' ', ' ' . $match => ' ' . $argStartCode . $match . $argFinishCode, $match . ' ' => $argStartCode . $match . $argFinishCode . ' ')); } return $text; }, $printableText); } // Print step description $printableDescription = sprintf(' %s %s', $step->getType(), $printableText); $this->write($printableDescription, $event->getParameter('result'), false); // Print definition path if found one if (null !== $event->getParameter('definition')) { $this->printLineSourceComment(mb_strlen($description), $event->getParameter('definition')->getFile(), $event->getParameter('definition')->getLine()); } else { $this->write(); } // print step arguments if ($step->hasArguments()) { foreach ($step->getArguments() as $argument) { if ($argument instanceof PyStringNode) { $this->write($this->getPyString($argument, 6), $event->getParameter('result')); } elseif ($argument instanceof TableNode) { $this->write($this->getTableString($argument, 6), $event->getParameter('result')); } } } // Print step exception if (null !== $event->getParameter('exception')) { if ($this->verbose) { $error = (string) $event->getParameter('exception'); } else { $error = $event->getParameter('exception')->getMessage(); } $this->write(' ' . strtr($error, array("\n" => "\n ")), $event->getParameter('result')); } } else { if (null !== $event->getParameter('exception')) { $this->outlineSubresultExceptions[] = $event->getParameter('exception'); } } } }
public function receivedEvent(Event $event) { $entity = $this->synchronize($event->getFqn(), $event->getSubject(), array('uniques' => array('id'))); $event->setEntity($entity); }