/** * Executes the configured command. * * @param Event $event * @param string $eventName * @param EventDispatcherInterface $eventDispatcher * * @throws TaskRuntimeException when execution of the command has failed. */ public function onEvent(Event $event, $eventName, EventDispatcherInterface $eventDispatcher) { if (in_array($eventName, $this->events)) { if ($event instanceof ReleaseEvent) { $release = $event->getRelease(); $host = $release->getWorkspace()->getHost(); $path = $release->getPath(); } else { $host = $event->getWorkspace()->getHost(); $path = $host->getPath(); } $connection = $this->ensureConnection($host); $currentWorkingDirectory = $connection->getWorkingDirectory(); $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Executing command "{command}".', $eventName, $this, array('command' => $this->command, 'event.task.action' => TaskInterface::ACTION_IN_PROGRESS))); $connection->changeWorkingDirectory($path); $result = $connection->executeCommand($this->command, $this->arguments); $connection->changeWorkingDirectory($currentWorkingDirectory); if ($result->isSuccessful()) { $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Executed command "{command}".', $eventName, $this, array('command' => $this->command, 'event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true))); $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, "{separator} Command output:{separator}\n{command.result}{separator}", $eventName, $this, array('command.result' => $result->getOutput(), 'separator' => "\n=================\n"))); } else { throw new TaskCommandExecutionException(sprintf('Failed executing command "%s".', $this->command), $result, $this); } } }
public function getController(Event $event, $controller) { if (HttpKernelInterface::MASTER_REQUEST === $event->get('request_type')) { $this->extension->setController($controller); } return $controller; }
/** * @param Event $event */ public function onTestEvent(Event $event) { if (!$event instanceof TestEvent) { throw new \RuntimeException("invalid event"); } $event->setNick("jowy"); }
public function getData(Event $event) { $institutionUser = $event->getInstitutionUser(); $router = $this->container->get('router'); $urlProfile = $router->generate('institution_account_profile', array(), true); $urlDefaultCenter = $router->generate('institution_medicalCenter_index', array(), true); $urlDefaultCenterGallery = $router->generate('institution_mediaGallery_index', array(), true); $institutionType = $institutionUser->getInstitution()->getType(); switch ($institutionType) { case InstitutionTypes::SINGLE_CENTER: $urlTreatmentList = $urlProfile . '#specializations'; break; case InstitutionTypes::MULTIPLE_CENTER: $urlTreatmentList = $urlDefaultCenter; break; default: $urlTreatmentList = ''; } switch ($institutionType) { case InstitutionTypes::SINGLE_CENTER: $urlFeatureDoctors = $urlProfile . '#doctors'; break; case InstitutionTypes::MULTIPLE_CENTER: $urlFeatureDoctors = $urlDefaultCenter; break; default: $urlFeatureDoctors = ''; } $urlContactDetails = $urlProfile . '#contact-details'; return array('to' => $institutionUser->getEmail(), 'email' => array('user_login' => $institutionUser->getEmail()), 'url' => array('complete_profile' => $urlProfile, 'add_centers' => $urlDefaultCenter, 'upload_photos' => $urlDefaultCenterGallery, 'list_treatments' => $urlTreatmentList, 'feature_doctors' => $urlFeatureDoctors, 'contact_info' => $urlContactDetails)); }
/** * Handles security. * * @param Event $event An Event instance */ public function handle(Event $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { return; } $request = $event->get('request'); $this->dispatcher->disconnect('core.security'); list($listeners, $exception) = $this->map->getListeners($request); if (null !== $exception) { $exception->register($this->dispatcher); } foreach ($listeners as $listener) { $listener->register($this->dispatcher); } $e = $this->dispatcher->notifyUntil(new Event($request, 'core.security', array('request' => $request))); if ($e->isProcessed()) { $event->setReturnValue($e->getReturnValue()); return true; } return; }
public function handle(Event $event) { $request = $event->get('request'); $master = HttpKernelInterface::MASTER_REQUEST === $event->get('request_type'); $this->initializeSession($request, $master); $this->initializeRequestAttributes($request, $master); }
/** * * * @param Event $event An Event instance */ public function filter(Event $event, $controller) { $request = $event->get('request'); if ($configuration = $request->attributes->get('_converters')) { $this->manager->apply($request, $configuration); } if (is_array($controller)) { $r = new \ReflectionMethod($controller[0], $controller[1]); } else { $r = new \ReflectionFunction($controller); } // automatically apply conversion for non-configured objects foreach ($r->getParameters() as $param) { if ($param->getClass() && !$request->attributes->get($param->getName())) { $configuration = new ParamConverter(); $configuration->setName($param->getName()); $configuration->setClass($param->getClass()->getName()); $configuration->setOptional($param->isOptional()); $this->manager->apply($request, $configuration); } } return $controller; }
/** * Handles channel management. * * @param Event $event An Event instance */ public function handle(Event $event) { $request = $event->get('request'); list($attributes, $channel) = $this->map->getPatterns($request); if ('https' === $channel && !$request->isSecure()) { if (null !== $this->logger) { $this->logger->debug('Redirecting to HTTPS'); } $event->setReturnValue($this->authenticationEntryPoint->start($request)); return true; } if ('http' === $channel && $request->isSecure()) { if (null !== $this->logger) { $this->logger->debug('Redirecting to HTTP'); } $event->setReturnValue($this->authenticationEntryPoint->start($request)); return true; } }
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); } // re-throw the exception as this is a catch-all throw $exception; } $event->setReturnValue($response); $handling = false; return true; }
/** * Handles digest authentication. * * @param Event $event An Event instance */ public function handle(Event $event) { $request = $event->get('request'); if (!$request->get($this->usernameParameter)) { return; } if ('_exit' === $request->get($this->usernameParameter)) { $this->securityContext->setToken($this->attemptExitUser($request)); } else { try { $this->securityContext->setToken($this->attemptSwitchUser($request)); } catch (AuthenticationException $e) { if (null !== $this->logger) { $this->logger->debug(sprintf('Switch User failed: "%s"', $e->getMessage())); } } } $response = new Response(); $request->server->set('QUERY_STRING', ''); $response->setRedirect($request->getUri(), 302); $event->setReturnValue($response); return true; }
/** * Captures outline into the ivar on outline BEFORE event. * * @param Event $event */ public function captureOutlineOnBeforeOutlineEvent(Event $event) { if (!$event instanceof BeforeOutlineTested) { return; } $this->outline = $event->getOutline(); }
/** * Handles basic authentication. * * @param Event $event An Event instance */ public function handle(Event $event) { $request = $event->getParameter('request'); if (false === ($username = $request->server->get('PHP_AUTH_USER', false))) { return; } if (null !== ($token = $this->securityContext->getToken())) { if ($token->isImmutable()) { return; } if ($token instanceof UsernamePasswordToken && $token->isAuthenticated() && (string) $token === $username) { return; } } if (null !== $this->logger) { $this->logger->debug(sprintf('Basic Authentication Authorization header found for user "%s"', $username)); } try { $token = $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $request->server->get('PHP_AUTH_PW'))); $this->securityContext->setToken($token); } catch (AuthenticationException $failed) { $this->securityContext->setToken(null); if (null !== $this->logger) { $this->logger->debug(sprintf('Authentication request failed: %s', $failed->getMessage())); } if ($this->ignoreFailure) { return; } $event->setReturnValue($this->authenticationEntryPoint->start($request, $failed)); return true; } }
/** * Handles security. * * @param Event $event An Event instance */ public function handle(Event $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) { return; } $request = $event->get('request'); // disconnect all listeners from core.security to avoid the overhead // of most listeners having to do this manually $this->dispatcher->disconnect('core.security'); // ensure that listeners disconnect from wherever they have connected to foreach ($this->currentListeners as $listener) { $listener->unregister($this->dispatcher); } // register listeners for this firewall list($listeners, $exception) = $this->map->getListeners($request); if (null !== $exception) { $exception->register($this->dispatcher); } foreach ($listeners as $listener) { $listener->register($this->dispatcher); } // save current listener instances $this->currentListeners = $listeners; $this->currentListeners[] = $exception; // initiate the listener chain $e = $this->dispatcher->notifyUntil(new Event($request, 'core.security', array('request' => $request))); if ($e->isProcessed()) { $event->setReturnValue($e->getReturnValue()); return true; } return; }
/** * Handles X509 authentication. * * @param Event $event An Event instance */ public function handle(Event $event) { $request = $event->get('request'); if (null !== $this->logger) { $this->logger->debug(sprintf('Checking secure context token: %s', $this->securityContext->getToken())); } list($user, $credentials) = $this->getPreAuthenticatedData($request); if (null !== ($token = $this->securityContext->getToken())) { if ($token->isImmutable()) { return; } if ($token instanceof PreAuthenticatedToken && $token->isAuthenticated() && (string) $token === $user) { return; } } if (null !== $this->logger) { $this->logger->debug(sprintf('Trying to pre-authenticate user "%s"', $user)); } try { $token = $this->authenticationManager->authenticate(new PreAuthenticatedToken($user, $credentials)); if (null !== $this->logger) { $this->logger->debug(sprintf('Authentication success: %s', $token)); } $this->securityContext->setToken($token); } catch (AuthenticationException $failed) { $this->securityContext->setToken(null); if (null !== $this->logger) { $this->logger->debug(sprintf("Cleared security context due to exception: %s", $failed->getMessage())); } } }
public function addSuccessFlash(Event $event) { if (!isset(self::$successMessages[$event->getName()])) { throw new \InvalidArgumentException('This event does not correspond to a known flash message'); } $this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$event->getName()])); }
/** * On dispatch event listener - called on any event * AMQP_MANDATORY: When publishing a message, the message must be routed to a valid queue. If it is not, an error will be returned. * if the client publishes a message with the "mandatory" flag set to an exchange of "direct" type which is not bound to a queue. * AMQP_IMMEDIATE: When publishing a message, mark this message for immediate processing by the broker. * REMOVED from rabbitmq > 3-0 http://www.rabbitmq.com/blog/2012/11/19/breaking-things-with-rabbitmq-3-0 * @param Event $event * @param string $eventName * @return void */ public function onPublish(Event $event, $eventName) { if ($event instanceof Amqp\PublishEvent && $event->getExchangeName() !== null) { $exchange = $this->broker->exchange(null, $event->getExchangeName()); return $this->publish($event, $eventName, $exchange); } }
public function onlineProductFromYahoo(Event $event) { $product = $event->getAuction()->getProduct(); if (!is_null($product->getYahooId())) { $this->getClient()->online($product); } }
/** * @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)); }
/** * @param Formatter $formatter * @param Event $event */ private function printFooterOnAfterSuiteTestedEvent(Formatter $formatter, Event $event) { if (!$event instanceof AfterSuiteTested) { return; } $this->suitePrinter->printFooter($formatter, $event->getSuite()); }
/** * * * @param Event $event An Event instance */ public function filter(Event $event, Response $response) { if (!$configuration = $event->get('request')->attributes->get('_cache')) { return $response; } if (!$response->isSuccessful()) { return $response; } if (null !== $configuration->getSMaxAge()) { $response->setSharedMaxAge($configuration->getSMaxAge()); } if (null !== $configuration->getMaxAge()) { $response->setMaxAge($configuration->getMaxAge()); } if (null !== $configuration->getExpires()) { $date = \DateTime::create(\DateTime::createFromFormat('U', $configuration->getExpires(), new \DateTimeZone('UTC'))); $response->setLastModified($date); } return $response; }
public function dispatch($eventName, Event $event = null) { if ($event instanceof LoggableEventInterface) { $this->getContainer()->get('logger')->addInfo($eventName, $event->getLogContext()); } return parent::dispatch($eventName, $event); }
/** * @group legacy */ public function testAddSuccessFlashLegacy() { if (!method_exists($this->event, 'setDispatcher')) { $this->markTestSkipped('Legacy test which requires Symfony <3.0.'); } $this->event->setName(FOSUserEvents::CHANGE_PASSWORD_COMPLETED); $this->listener->addSuccessFlash($this->event); }
/** * Executes the given callback, returns the callback's return value. * * @param \Philip\IRC\Event $event The Philip IRC event * * @return mixed */ public function testAndExecute(Event $event) { if ($this->shouldExecuteCallback($event->getRequest()->getMessage())) { $event->setMatches($this->getMatches()); return call_user_func($this->callback, $event); } return false; }
public function listenToInteractiveLogin(Event $event) { $user = $event->get('token')->getUser(); if ($user instanceof User) { $user->setLastLogin(new DateTime()); $this->userManager->updateUser($user); } }
/** * {@inheritdoc} */ public function collect(Event $event, $eventName) { if ($event instanceof LogEvent) { ++$this->logLevelCount[$event->getLevel()]; } elseif ($event instanceof FailedEvent) { ++$this->failedEventCount; } }
/** * {@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 handle(Event $event, Response $response) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) { return $response; } $this->profiler->collect($response); return $response; }
/** * Prints feature footer on AFTER event. * * @param Formatter $formatter * @param Event $event */ private function printFooterOnAfterEvent(Formatter $formatter, Event $event) { if (!$event instanceof AfterFeatureTested) { return; } $this->setupPrinter->printTeardown($formatter, $event->getTeardown()); $this->featurePrinter->printFooter($formatter, $event->getTestResult()); }
public function parseRequest(Event $event) { $request = $event->get('request'); $matcher = new UrlMatcher($this->routes, array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'is_secure' => $request->isSecure())); if (false === ($attributes = $matcher->match($request->getPathInfo()))) { return false; } $request->attributes->add($attributes); }
/** * {@inheritdoc} */ public function listenEvent(Formatter $formatter, Event $event, $eventName) { if ($event instanceof AfterSuiteSetup) { $this->setupPrinter->printSetup($formatter, $event->getSetup()); } if ($event instanceof AfterSuiteTested) { $this->setupPrinter->printTeardown($formatter, $event->getTeardown()); } }