作者:deborahvanderveg
项目:accompl
/**
* 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);
}
}
}
作者:richsag
项目:symfony-standar
public function getController(Event $event, $controller)
{
if (HttpKernelInterface::MASTER_REQUEST === $event->get('request_type')) {
$this->extension->setController($controller);
}
return $controller;
}
作者:digideski
项目:sing
/**
* @param Event $event
*/
public function onTestEvent(Event $event)
{
if (!$event instanceof TestEvent) {
throw new \RuntimeException("invalid event");
}
$event->setNick("jowy");
}
作者:TMBaa
项目:MEDTrip---Healthcareabroa
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));
}
作者:pmjone
项目:php-framework-benchmark
/**
* 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;
}
作者:notbrai
项目:symfon
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);
}
作者:ruud
项目:FrameworkExtraBundl
/**
*
*
* @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;
}
作者:pmjone
项目:php-framework-benchmark
/**
* 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;
}
}
作者:rosstuc
项目:Po
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;
}
作者:pmjone
项目:php-framework-benchmark
/**
* 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;
}
作者:aaa200
项目:behat-vcr-extensio
/**
* 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();
}
作者:rsk
项目:symfon
/**
* 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;
}
}
作者:hirocaste
项目:symfony-sandbo
/**
* 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;
}
作者:rosstuc
项目:Po
/**
* 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()));
}
}
}
作者:makranelhoucin
项目:pfa_ensaobo
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()]));
}
作者:galln
项目:amqp-even
/**
* 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);
}
}
作者:jocoonop
项目:avenu
public function onlineProductFromYahoo(Event $event)
{
$product = $event->getAuction()->getProduct();
if (!is_null($product->getYahooId())) {
$this->getClient()->online($product);
}
}
作者:TMBaa
项目:MEDTrip---Healthcareabroa
/**
* @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));
}
作者:OverByTher
项目:Beha
/**
* @param Formatter $formatter
* @param Event $event
*/
private function printFooterOnAfterSuiteTestedEvent(Formatter $formatter, Event $event)
{
if (!$event instanceof AfterSuiteTested) {
return;
}
$this->suitePrinter->printFooter($formatter, $event->getSuite());
}
作者:ruud
项目:FrameworkExtraBundl
/**
*
*
* @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;
}