本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\SessionInterface::getBag方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::getBag方法的具体用法?PHP SessionInterface::getBag怎么用?PHP SessionInterface::getBag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Session\SessionInterface
的用法示例。
在下文中一共展示了SessionInterface::getBag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setFlash
/**
* @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;
}
示例2: addFlash
/**
* @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);
}
示例3: __construct
/**
* 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());
}
示例4: onKernelException
/**
* @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)));
}
示例5: deleteUser
/**
* @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.');
}
}
示例6: deleteUser
/**
* @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.');
}
}
示例7: deleteUser
/**
* @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.');
}
}
示例8: handleCouponPromotion
/**
* 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'));
}
示例9: getMassActions
/**
* {@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());
}
示例10: getMassActions
/**
* {@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());
}
示例11: addFlash
/**
* @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'));
}
示例12: initializeLegacySessionAccess
/**
* 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');
}
示例13: getSessionBag
/**
* 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);
}
示例14:
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);
}
示例15: handleRestrictedZone
/**
* @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();
}
}