/** * @param string $type * @param string $eventName * @param array $params * * @return mixed */ public function setFlash($type, $eventName, $params = array()) { /** @var FlashBag $flashBag */ $flashBag = $this->session->getBag('flashes'); $flashBag->add($type, $this->generateFlashMessage($eventName, $params)); return $this; }
/** * @param string $type * @param string $message * @param array $parameters */ private function addFlash($type, $message, array $parameters = []) { if (!empty($parameters)) { $message = $this->prepareMessage($message, $parameters); } $this->session->getBag('flashes')->add($type, $message); }
/** * Get the session data */ protected function __construct() { if (PHP_SAPI == 'cli') { $this->session = new SymfonySession(new MockArraySessionStorage()); } else { $this->session = \System::getContainer()->get('session'); } $this->sessionBag = $this->session->getBag($this->getSessionBagKey()); }
/** * @param GetResponseForExceptionEvent $event */ public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if (!$exception instanceof InsufficientStockException) { return; } $this->session->getBag('flashes')->add('notice', $this->translator->trans('sylius.checkout.out_of_stock', ['%quantity%' => $exception->getStockable()->getOnHand(), '%name%' => $exception->getStockable()->getInventoryName()], 'flashes')); $event->setResponse(new RedirectResponse($this->router->generate($this->redirectTo))); }
/** * @param GenericEvent $event * * @throws \InvalidArgumentException */ public function deleteUser(GenericEvent $event) { $user = $event->getSubject(); Assert::isInstanceOf($user, UserInterface::class); $token = $this->tokenStorage->getToken(); if (null !== $token && ($loggedUser = $token->getUser()) && $loggedUser->getId() === $user->getId()) { $event->stopPropagation(); $this->session->getBag('flashes')->add('error', 'Cannot remove currently logged in user.'); } }
/** * @param GenericEvent $event */ public function deleteUser(GenericEvent $event) { $user = $event->getSubject(); if (!$user instanceof UserInterface) { throw new UnexpectedTypeException($user, UserInterface::class); } if (($token = $this->tokenStorage->getToken()) && ($loggedUser = $token->getUser()) && $loggedUser->getId() === $user->getId()) { $event->stopPropagation(); $this->session->getBag('flashes')->add('error', 'Cannot remove currently logged in user.'); } }
/** * @param ResourceEvent $event */ public function deleteUser(ResourceEvent $event) { $user = $event->getSubject(); if (!$user instanceof UserInterface) { throw new UnexpectedTypeException($user, 'Sylius\\Component\\User\\Model\\UserInterface'); } if (($token = $this->securityContext->getToken()) && ($loggedUser = $token->getUser()) && $loggedUser->getId() === $user->getId()) { $event->stopPropagation(); $this->session->getBag('flashes')->add('error', 'Cannot remove currently logged in user.'); } }
/** * Handle coupons added by the user in his cart. * TODO: maybe replace this with a unified FlashSubscriber. * * @param GenericEvent $event */ public function handleCouponPromotion(GenericEvent $event) { if (SyliusPromotionEvents::COUPON_ELIGIBLE === $event->getName()) { $type = 'success'; $message = 'sylius.promotion_coupon.eligible'; } elseif (SyliusPromotionEvents::COUPON_NOT_ELIGIBLE === $event->getName()) { $type = 'error'; $message = 'sylius.promotion_coupon.not_eligible'; } else { $type = 'error'; $message = 'sylius.promotion_coupon.invalid'; } $this->session->getBag('flashes')->add($type, $this->translator->trans($message, [], 'flashes')); }
/** * {@inheritdoc} */ public function getMassActions() { $archiveAction = new MassAction('Archive', function ($ids) { /** @var InvoiceRepository $invoiceRepository */ $invoiceRepository = $this->entityManager->getRepository('CSBillInvoiceBundle:Invoice'); /** @var Invoice[] $invoices */ $invoices = $invoiceRepository->findBy(array('id' => $ids)); /** @var FlashBag $flashBag */ $flashBag = $this->session->getBag('flashes'); $failed = 0; foreach ($invoices as $invoice) { try { $this->invoiceManager->archive($invoice); } catch (InvalidTransitionException $e) { $flashBag->add('warning', $e->getMessage()); ++$failed; } } if ($failed !== count($invoices)) { $flashBag->add('success', 'invoice.archive.success'); } }, true); $archiveAction->setIcon('archive'); $archiveAction->setClass('warning'); return array($archiveAction, new DeleteMassAction()); }
/** * {@inheritdoc} */ public function getMassActions() { $archiveAction = new MassAction('Archive', function ($ids) { /** @var QuoteRepository $quoteRepository */ $quoteRepository = $this->entityManager->getRepository('CSBillQuoteBundle:Quote'); /** @var Quote[] $quotes */ $quotes = $quoteRepository->findBy(array('id' => $ids)); /** @var FlashBag $flashBag */ $flashBag = $this->session->getBag('flashes'); $failed = 0; foreach ($quotes as $quote) { $finite = $this->finite->get($quote, Graph::GRAPH); if ($finite->can(Graph::TRANSITION_ARCHIVE)) { $quote->archive(); $this->entityManager->persist($quote); } else { $flashBag->add('warning', 'quote.transition.exception.archive'); ++$failed; } } if ($failed !== count($quotes)) { $this->entityManager->flush(); $flashBag->add('success', 'quote.archive.success'); } }, true); $archiveAction->setIcon('archive'); $archiveAction->setClass('warning'); return array($archiveAction, new DeleteMassAction()); }
/** * @param PurchaseCompleteEvent $event */ public function addFlash(PurchaseCompleteEvent $event) { switch ($event->getSubject()->getState()) { case PaymentInterface::STATE_COMPLETED: $type = 'success'; $message = 'sylius.checkout.success'; break; case PaymentInterface::STATE_PROCESSING: case PaymentInterface::STATE_PENDING: $type = 'notice'; $message = 'sylius.checkout.processing'; break; case PaymentInterface::STATE_NEW: $type = 'notice'; $message = 'sylius.checkout.new'; break; case PaymentInterface::STATE_VOID: case PaymentInterface::STATE_CANCELLED: $type = 'notice'; $message = 'sylius.checkout.canceled'; break; case PaymentInterface::STATE_FAILED: $type = 'error'; $message = 'sylius.checkout.failed'; break; default: $type = 'error'; $message = 'sylius.checkout.unknown'; break; } $this->session->getBag('flashes')->add($type, $this->translator->trans($message, [], 'flashes')); }
/** * Initializes session access for $_SESSION['FE_DATA'] and $_SESSION['BE_DATA']. */ private function initializeLegacySessionAccess() { if (!$this->session->isStarted()) { return; } $_SESSION['BE_DATA'] = $this->session->getBag('contao_backend'); $_SESSION['FE_DATA'] = $this->session->getBag('contao_frontend'); }
/** * Returns the session bag. * * @return AttributeBagInterface The session bag */ private function getSessionBag() { if ($this->isBackendScope()) { $bag = 'contao_backend'; } else { $bag = 'contao_frontend'; } return $this->session->getBag($bag); }
function it_adds_message_from_event(SessionInterface $session, FlashBagInterface $flashBag, RequestConfiguration $requestConfiguration, ResourceControllerEvent $event) { $event->getMessage()->willReturn('sylius.channel.cannot_be_deleted'); $event->getMessageType()->willReturn(ResourceControllerEvent::TYPE_WARNING); $event->getMessageParameters()->willReturn(['%name%' => 'Germany Sylius Webshop']); $session->getBag('flashes')->willReturn($flashBag); $flashBag->add(ResourceControllerEvent::TYPE_WARNING, ['message' => 'sylius.channel.cannot_be_deleted', 'parameters' => ['%name%' => 'Germany Sylius Webshop']])->shouldBeCalled(); $this->addFlashFromEvent($requestConfiguration, $event); }
/** * @param GenericEvent $event */ public function handleRestrictedZone(GenericEvent $event) { $cart = $event->getSubject(); if (!$cart instanceof CartInterface) { $cart = $this->cartProvider->getCart(); } $removed = false; foreach ($cart->getItems() as $item) { if ($this->restrictedZoneChecker->isRestricted($product = $item->getProduct(), $cart->getShippingAddress())) { $cart->removeItem($item); $removed = true; $this->session->getBag('flashes')->add('error', $this->translator->trans('sylius.cart.restricted_zone_removal', ['%product%' => $product->getName()], 'flashes')); } } if ($removed) { $this->cartManager->persist($cart); $this->cartManager->flush(); } }
function it_adds_flash_from_event(SessionInterface $session, FlashBagInterface $flashBag, TranslatorInterface $translator, RequestConfiguration $requestConfiguration, ResourceControllerEvent $event) { $event->getMessage()->willReturn('sylius.channel.cannot_be_deleted'); $event->getMessageType()->willReturn(ResourceControllerEvent::TYPE_WARNING); $event->getMessageParameters()->willReturn(array('%name%' => 'Germany Sylius Webshop')); $session->getBag('flashes')->willReturn($flashBag); $translator->trans('sylius.channel.cannot_be_deleted', array('%name%' => 'Germany Sylius Webshop'), 'flashes')->willReturn('Channel "Germany Sylius Webshop" cannot be deleted.'); $flashBag->add(ResourceControllerEvent::TYPE_WARNING, 'Channel "Germany Sylius Webshop" cannot be deleted.')->shouldBeCalled(); $this->addFlashFromEvent($requestConfiguration, $event); }
/** * @param GetResponseForExceptionEvent $event */ public function onResourceDelete(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if (!$exception instanceof ForeignKeyConstraintViolationException) { return; } $requestAttributes = $event->getRequest()->attributes; if (null === $requestAttributes->get('_controller')) { return; } $originalRoute = $requestAttributes->get('_route'); $resourceName = $this->getResourceNameFromRoute($originalRoute); $this->session->getBag('flashes')->add('error', $this->translator->trans('sylius.resource.delete_error', ['%resource%' => $resourceName], 'flashes')); $referrer = $event->getRequest()->headers->get('referer'); if ($this->refersFromShow($referrer)) { $event->setResponse($this->createRedirectResponse($originalRoute, ResourceActions::SHOW, ['id' => $requestAttributes->get('id')])); return; } $event->setResponse($this->createRedirectResponse($originalRoute, ResourceActions::INDEX)); }
/** * Returns the session bag. * * @return AttributeBagInterface */ private function getSessionBag() { if ($this->isBackendScope()) { $name = 'contao_backend'; } else { $name = 'contao_frontend'; } /** @var AttributeBagInterface $bag */ $bag = $this->session->getBag($name); return $bag; }
function it_performs_kernel_exception_action_successfully(UrlGeneratorInterface $router, SessionInterface $session, TranslatorInterface $translator, GetResponseForExceptionEvent $event, FlashBagInterface $flashBag, StockableInterface $stockable) { $stockable->getOnHand()->willReturn('30'); $stockable->getInventoryName()->willReturn('Inventory Name'); $event->getException()->willReturn(new InsufficientStockException($stockable->getWrappedObject(), 42)); $event->setResponse(Argument::type(RedirectResponse::class))->shouldBeCalled(); $translator->trans('sylius.checkout.out_of_stock', ['%quantity%' => '30', '%name%' => 'Inventory Name'], 'flashes')->willReturn('message translated'); $flashBag->add('notice', 'message translated')->shouldBeCalled(); $session->getBag('flashes')->willReturn($flashBag); $router->generate('redirect_to_url')->willReturn('url'); $this->onKernelException($event); }
function it_performs_kernel_exception_action_successfully(UrlGeneratorInterface $router, SessionInterface $session, TranslatorInterface $translator, GetResponseForExceptionEvent $event, InsufficientStockException $exception, FlashBagInterface $flashBag, StockableInterface $stockable) { $stockable->getOnHand()->shouldBeCalled()->willReturn('30'); $stockable->getInventoryName()->shouldBeCalled()->willReturn('Inventory Name'); $exception->getStockable()->shouldBeCalledTimes(2)->willReturn($stockable); $event->getException()->shouldBeCalled()->willReturn($exception); $event->setResponse(Argument::type('Symfony\\Component\\HttpFoundation\\RedirectResponse'))->shouldBeCalled(); $translator->trans('sylius.checkout.out_of_stock', array('%quantity%' => '30', '%name%' => 'Inventory Name'), 'flashes')->shouldBeCalled()->willReturn('message translated'); $flashBag->add('notice', 'message translated')->shouldBeCalled(); $session->getBag('flashes')->shouldBeCalled()->willReturn($flashBag); $router->generate('redirect_to_url')->shouldBeCalled()->willReturn('url'); $this->onKernelException($event)->shouldReturn(null); }
/** * @param string $status * @param string $errorMessage */ private function addFlashMessage($status, $errorMessage = null) { switch ($status) { case Status::STATUS_CAPTURED: $type = 'success'; $message = 'payment.flash.status.success'; break; case Status::STATUS_CANCELLED: $type = 'danger'; $message = 'payment.flash.status.cancelled'; break; case Status::STATUS_PENDING: $type = 'warning'; $message = 'payment.flash.status.pending'; break; case Status::STATUS_EXPIRED: $type = 'danger'; $message = 'payment.flash.status.expired'; break; case Status::STATUS_FAILED: $type = 'danger'; $message = 'payment.flash.status.failed'; break; case Status::STATUS_NEW: $type = 'warning'; $message = 'payment.flash.status.new'; break; case Status::STATUS_SUSPENDED: $type = 'danger'; $message = 'payment.flash.status.suspended'; break; case Status::STATUS_AUTHORIZED: $type = 'info'; $message = 'payment.flash.status.authorized'; break; case Status::STATUS_REFUNDED: $type = 'warning'; $message = 'payment.flash.status.refunded'; break; case Status::STATUS_UNKNOWN: default: $type = 'danger'; $message = 'payment.flash.status.unknown'; break; } /** @var FlashBag $flashBag */ $flashBag = $this->session->getBag('flashes'); $parameters = array('%message%' => $errorMessage); $flashBag->add($type, $this->translator->trans($message, $parameters)); }
/** * @param GetResponseForExceptionEvent $event */ public function onResourceDelete(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if (!$exception instanceof ForeignKeyConstraintViolationException) { return; } $requestAttributes = $event->getRequest()->attributes; $originalRoute = $requestAttributes->get('_route'); $resourceName = $this->getResourceNameFromRoute($originalRoute); if (!$this->isHtmlRequest($event->getRequest())) { $event->setResponse($this->viewHandler->handle(View::create(['error' => ['code' => $exception->getSQLState(), 'message' => $this->translator->trans('sylius.resource.delete_error', ['%resource%' => $resourceName], 'flashes')]], 409))); return; } if (null === $requestAttributes->get('_controller')) { return; } $this->session->getBag('flashes')->add('error', $this->translator->trans('sylius.resource.delete_error', ['%resource%' => $resourceName], 'flashes')); $referrer = $event->getRequest()->headers->get('referer'); if (null !== $referrer) { $event->setResponse(new RedirectResponse($referrer)); return; } $event->setResponse($this->createRedirectResponse($originalRoute, ResourceActions::INDEX)); }
/** * {@inheritdoc} */ public function getMassActions() { $archive = new MassAction('Archive', function ($ids) { /** @var ClientRepository $clientRepository */ $clientRepository = $this->objectManager->getRepository('CSBillClientBundle:Client'); /** @var Client[] $clients */ $clients = $clientRepository->findBy(array('id' => $ids)); foreach ($clients as $client) { $client->archive(); $client->setStatus(Status::STATUS_ARCHIVED); $this->objectManager->persist($client); } $this->objectManager->flush(); /** @var FlashBag $flashBag */ $flashBag = $this->session->getBag('flashes'); $flashBag->add('success', 'client.archive.success'); }, true); $archive->setIcon('archive'); $archive->setClass('warning'); $deleteAction = new DeleteMassAction(true); return array($archive, $deleteAction); }
/** * Returns flash bag * * @return \Symfony\Component\HttpFoundation\Session\SessionBagInterface */ private function getFlashBag() { return $this->session->getBag($this->flashesName); }
/** * Get the session data */ protected function __construct() { $this->session = \System::getContainer()->get('session'); $this->sessionBag = $this->session->getBag($this->getSessionBagKey()); }
private function getTrackingBag() { return $this->session->getBag($this->trackingName); }
/** * Get session flows bag. * * @return SessionFlowsBag */ private function getBag() { return $this->session->getBag(SessionFlowsBag::NAME); }
/** * {@inheritdoc} */ public function addFlashFromEvent(RequestConfiguration $requestConfiguration, ResourceControllerEvent $event) { $translatedMessage = $this->translator->trans($event->getMessage(), $event->getMessageParameters(), 'flashes'); $this->session->getBag('flashes')->add($event->getMessageType(), $translatedMessage); }
/** * Returns flash bag * * @return \Symfony\Component\HttpFoundation\Session\Flash\FlashBag */ private function getFlashBag() { return $this->session->getBag(FlashHelperInterface::FLASHES_NAME); }
/** * Constructeur. * * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session Session * @param \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $flashBag FlashBag */ public function __construct(SessionInterface $session, FlashBagInterface $flashBag = null) { $this->sessionFlashBag = $session->getBag($flashBag->getName()); }