本文整理匯總了PHP中Symfony\Component\EventDispatcher\Event::getSubject方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::getSubject方法的具體用法?PHP Event::getSubject怎麽用?PHP Event::getSubject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\EventDispatcher\Event
的用法示例。
在下文中一共展示了Event::getSubject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handle
/**
* 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;
}
示例2: handle
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;
}
示例3: handle
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;
}
示例4: getData
/**
* @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));
}
示例5: determineQualifiedEvents
/**
* {@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;
}
示例6: getData
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.');
}
}
示例7: getData
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));
}
示例8: fireStepHooks
/**
* 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]);
});
}
示例9: isEventProcessable
public function isEventProcessable(Event $event)
{
$institutionMedicalCenter = $event->getSubject();
return InstitutionMedicalCenterStatus::APPROVED == $institutionMedicalCenter->getStatus();
}
示例10: handle
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;
}
示例11: onEvent
/**
* 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.
}
}
示例12: flushFeatureXML
/**
* 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);
}
示例13: printStepEventInformation
/**
* 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();
}
示例14: handleException
/**
* 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;
}
示例15: printSnippets
/**
* 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();
}
}
}