本文整理汇总了PHP中Symfony\Component\HttpFoundation\RequestStack类的典型用法代码示例。如果您正苦于以下问题:PHP RequestStack类的具体用法?PHP RequestStack怎么用?PHP RequestStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(TranslatorInterface $translator, Router $router, LocaleManager $localeManager, RequestStack $requestStack)
{
$this->translator = $translator;
$this->router = $router;
$this->localeManager = $localeManager;
$this->request = $requestStack->getCurrentRequest();
}
示例2: createMainMenu
public function createMainMenu(RequestStack $requestStack)
{
$menu = $this->_factory->createItem('root');
$items = $this->_manager->getRepository('MenuBundle:Menu')->findAll();
$currentRoute = $requestStack->getMasterRequest()->attributes->get('_route');
$westItems = array_slice($items, 0, 2);
$eastItems = array_slice($items, 2, 2);
foreach ($westItems as $item) {
$menu->addChild($item->getTitle(), ['route' => $item->getRoute()])->setAttribute('class', 'touch-hover');
if ($item->getRoute() === str_replace("_default", "", $currentRoute)) {
$menu[$item->getTitle()]->setCurrent(TRUE);
}
}
// $menu
// ->addChild(NULL, [
// 'route' => 'index', 'routeParameters' => [
// '_locale' => $requestStack->getMasterRequest()->attributes->get('_locale')
// ]
// ])
// ->setAttribute('class', 'logo-holder')
// ->setLinkAttribute('class', 'logo')
// ;
foreach ($eastItems as $item) {
$menu->addChild($item->getTitle(), ['route' => $item->getRoute()])->setAttribute('class', 'touch-hover');
if ($item->getRoute() === str_replace("_default", "", $currentRoute)) {
$menu[$item->getTitle()]->setCurrent(TRUE);
}
}
return $menu;
}
示例3: __construct
/**
* @param RequestStack $requestStack
* @param EntityManager $entityManager
* @param $securityContext
* @param $acl
*/
public function __construct(RequestStack $requestStack, EntityManager $entityManager, SecurityContext $securityContext, $acl)
{
$this->securityContext = $securityContext;
$this->request = $requestStack->getCurrentRequest();
$this->em = $entityManager;
$this->acl = $acl;
}
示例4: __construct
/**
* @DI\InjectParams({
* "container" = @DI\Inject("service_container"),
* "httpKernel" = @DI\Inject("http_kernel"),
* "requestStack" = @DI\Inject("request_stack"),
* "resourceManager" = @DI\Inject("claroline.manager.resource_manager")
* })
*/
public function __construct(ContainerInterface $container, HttpKernelInterface $httpKernel, RequestStack $requestStack, ResourceManager $resourceManager)
{
$this->container = $container;
$this->httpKernel = $httpKernel;
$this->request = $requestStack->getCurrentRequest();
$this->resourceManager = $resourceManager;
}
示例5: __construct
/**
* @param IntegrationHelper $integrationHelper
* @param UserPasswordEncoderInterface $encoder
* @param EventDispatcherInterface $dispatcher
* @param RequestStack $requestStack
*/
public function __construct(IntegrationHelper $integrationHelper, UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher, RequestStack $requestStack)
{
$this->encoder = $encoder;
$this->dispatcher = $dispatcher;
$this->integrationHelper = $integrationHelper;
$this->request = $requestStack->getCurrentRequest();
}
示例6: __construct
/**
* Constructs a PageRedirect object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger factory service.
* @param \Drupal\Core\Path\CurrentPathStack $current_path_stack
* The current path stack service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, CurrentPathStack $current_path_stack, RequestStack $request_stack)
{
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $logger_factory->get('rules');
$this->currentPathStack = $current_path_stack;
$this->request = $request_stack->getCurrentRequest();
}
示例7:
function it_throws_a_channel_not_found_exception_if_channel_with_given_code_was_not_found(FakeChannelCodeProviderInterface $fakeChannelCodeProvider, ChannelRepositoryInterface $channelRepository, RequestStack $requestStack, Request $request)
{
$requestStack->getMasterRequest()->willReturn($request);
$fakeChannelCodeProvider->getCode($request)->willReturn('CHANNEL_CODE');
$channelRepository->findOneByCode('CHANNEL_CODE')->willReturn(null);
$this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
}
示例8: setUp
protected function setUp()
{
/**
* Add the test type to the factory and
* the form to the container
*/
$factory = new FormFactoryBuilder();
$factory->addExtension(new CoreExtension());
$factory->addType(new TestType());
/**
* Construct the container
*/
$container = new Container();
$container->set("thelia.form_factory_builder", $factory);
$container->set("thelia.translator", new Translator($container));
$container->setParameter("thelia.parser.forms", $definition = array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm"));
$request = new Request();
$requestStack = new RequestStack();
$requestStack->push($request);
$request->setSession(new Session(new MockArraySessionStorage()));
$container->set("request", $request);
$container->set("request_stack", $requestStack);
$container->set("thelia.forms.validator_builder", new ValidatorBuilder());
$container->set("event_dispatcher", new EventDispatcher());
$this->factory = new TheliaFormFactory($requestStack, $container, $definition);
}
示例9: let
public function let(RequestStack $requestStack, Request $request, Session $session, ParameterBag $cookies)
{
$requestStack->getCurrentRequest()->willReturn($request);
$request->getSession()->willReturn($session);
$request->cookies = $cookies;
$this->beConstructedWith($requestStack);
}
示例10: testOnPageContext
/**
* @covers ::onPageContext
*/
public function testOnPageContext()
{
$collection = new RouteCollection();
$route_provider = $this->prophesize(RouteProviderInterface::class);
$route_provider->getRoutesByPattern('/test_route')->willReturn($collection);
$request = new Request();
$request_stack = new RequestStack();
$request_stack->push($request);
$data_definition = new DataDefinition(['type' => 'entity:user']);
$typed_data = $this->prophesize(TypedDataInterface::class);
$this->typedDataManager->getDefaultConstraints($data_definition)->willReturn([]);
$this->typedDataManager->create($data_definition, 'banana')->willReturn($typed_data->reveal());
$this->typedDataManager->createDataDefinition('bar')->will(function () use($data_definition) {
return $data_definition;
});
$page = $this->prophesize(PageInterface::class);
$this->executable->expects($this->once())->method('getPage')->will($this->returnValue($page->reveal()));
$page->getPath()->willReturn('/test_route');
$this->executable->expects($this->at(1))->method('addContext')->with('foo', $this->isInstanceOf(Context::class));
$this->executable->expects($this->at(2))->method('addContext')->with('baz', $this->isInstanceOf(Context::class));
$collection->add('test_route', new Route('/test_route', [], [], ['parameters' => ['foo' => ['type' => 'bar'], 'baz' => ['type' => 'bop'], 'page' => ['type' => 'entity:page']]]));
// Set up a request with one of the expected parameters as an attribute.
$request->attributes->add(['foo' => 'banana']);
$route_param_context = new RouteParamContext($route_provider->reveal(), $request_stack);
$route_param_context->onPageContext($this->event);
}
示例11: __construct
/**
* @param DisplayMediaManager $displayMediaManager
* @param MediaRepositoryInterface $mediaRepository
* @param RequestStack $requestStack
* @param MediaWithFormatExtractorInterface $mediaWithFormatExtractor
*/
public function __construct(DisplayMediaManager $displayMediaManager, MediaRepositoryInterface $mediaRepository, RequestStack $requestStack, MediaWithFormatExtractorInterface $mediaWithFormatExtractor)
{
$this->displayMediaManager = $displayMediaManager;
$this->mediaRepository = $mediaRepository;
$this->request = $requestStack->getMasterRequest();
$this->mediaWithFormatExtractor = $mediaWithFormatExtractor;
}
示例12: handleRequestStack
/**
* Handle the request stack
*/
protected function handleRequestStack()
{
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest) {
$this->add('request.locale', $currentRequest->getLocale());
}
}
示例13: __construct
/**
* @DI\InjectParams({
* "httpKernel" = @DI\Inject("http_kernel"),
* "requestStack" = @DI\Inject("request_stack"),
* "router" = @DI\Inject("router"),
* "translator" = @DI\Inject("translator")
* })
*/
public function __construct(HttpKernelInterface $httpKernel, RequestStack $requestStack, UrlGeneratorInterface $router, TranslatorInterface $translator)
{
$this->httpKernel = $httpKernel;
$this->request = $requestStack->getCurrentRequest();
$this->router = $router;
$this->translator = $translator;
}
示例14: __construct
/**
* @param EntityManagerInterface $em
* @param EngineInterface $twigEngine
* @param TranslatorInterface $translator
* @param RequestStack $requestStack
*/
public function __construct(EntityManagerInterface $em, EngineInterface $twigEngine, TranslatorInterface $translator, RequestStack $requestStack)
{
$this->em = $em;
$this->translator = $translator;
$this->render = $twigEngine;
$this->request = $requestStack->getCurrentRequest();
}
示例15: createRequestStack
/**
* @return RequestStack
*/
private function createRequestStack()
{
$request = Request::create('/');
$requestStack = new RequestStack();
$requestStack->push($request);
return $requestStack;
}