本文整理汇总了PHP中Symfony\Component\HttpFoundation\RequestStack::getMasterRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestStack::getMasterRequest方法的具体用法?PHP RequestStack::getMasterRequest怎么用?PHP RequestStack::getMasterRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\RequestStack
的用法示例。
在下文中一共展示了RequestStack::getMasterRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbnailInfo
/**
* @param $path
* @param $alias
* @param bool|false $isAbsolute
* @return array
* @throws \Exception
*/
public function getThumbnailInfo($path, $alias, $isAbsolute = false)
{
$filter = isset($this->settings['filters'][$alias]) ? $this->settings['filters'][$alias] : null;
if (!$filter) {
throw new \Exception(sprintf('Unknown thumbnail filter "%s"', $alias));
}
if (!$path) {
$default = null;
if (isset($filter['default'])) {
$defaultAlias = explode('.', $filter['default']);
$default = $this->settings['defaults'];
foreach ($defaultAlias as $defaultAliasName) {
$default = $default[$defaultAliasName];
}
}
$src = $default;
} else {
$src = sprintf('/%s/%s', $this->settings['url_prefix'], $alias) . $path;
}
if ($isAbsolute || $this->settings['absolute']) {
$host = $this->request->getMasterRequest()->getSchemeAndHttpHost();
$port = $this->request->getMasterRequest()->getPort();
if ($port != 80) {
$host .= ':' . $port;
}
$src = $host . $src;
}
$width = $filter['width'];
$height = $filter['height'];
return ['src' => $src, 'width' => $width, 'height' => $height];
}
示例2: vote
/**
* If you have failed to login too many times, a log of this will be present
* in your session and the databse (incase session is dropped the record remains).
*
* @access public
* @return int
*/
public function vote()
{
$request = $this->requestStack->getMasterRequest();
if (($this->forceAccountRecovery['enabled'] || $this->blockPages['enabled']) && $request) {
$route = $request->get('_route');
$ipAddress = $request->getClientIp();
$this->blockPages['routes'][] = $this->routeLogin['name'];
if ($this->blockPages['enabled'] && in_array($route, $this->blockPages['routes'])) {
// Get number of failed login attempts.
$attempts = $this->loginFailureTracker->getAttempts($ipAddress, $this->blockPages['duration_in_minutes']);
if (count($attempts) >= $this->blockPages['after_attempts']) {
// You have too many failed login attempts, login access is temporarily blocked.
return self::ACCESS_DENIED_BLOCK;
}
}
$this->forceAccountRecovery['routes'][] = $this->routeLogin['name'];
if ($this->forceAccountRecovery['enabled'] && in_array($route, $this->forceAccountRecovery['routes'])) {
// Get number of failed login attempts.
$attempts = $this->loginFailureTracker->getAttempts($ipAddress, $this->forceAccountRecovery['duration_in_minutes']);
if (count($attempts) >= $this->forceAccountRecovery['after_attempts']) {
// You have too many failed login attempts, login access is temporarily blocked, go recover your account.
return self::ACCESS_DENIED_DEFER;
}
}
}
return self::ACCESS_ALLOWED;
}
示例3: createAndHandle
public function createAndHandle($name, $type, IEntity $entity)
{
$request = $this->request_stack->getMasterRequest();
$form = $this->form_factory->createNamed($name, $type, $entity, ['method' => 'POST']);
$form->handleRequest($request);
return $form;
}
示例4: getCurrentRequest
/**
* {@inheritdoc}
*/
public function getCurrentRequest()
{
if (null === $this->request) {
$this->request = $this->requestStack->getMasterRequest();
}
return $this->request;
}
示例5: render
/**
* {@inheritdoc}
*/
public function render(GridViewInterface $grid, ColumnInterface $column, $sorting)
{
$definition = $grid->getDefinition();
$name = $column->getName();
if (!$definition->hasSort($name)) {
return;
}
$sort = $sorting === SorterInterface::ASC ? $name : '-' . $name;
$routeParameters = [];
if (($request = $this->requestStack->getMasterRequest()) !== null) {
$routeParameters = array_merge($request->attributes->get('_route_params', []), $request->query->all());
}
if (!isset($routeParameters['grid']['reset']) && isset($routeParameters['grid']['sorting']) && $routeParameters['grid']['sorting'] === $sort) {
return;
}
if ($definition->hasOption('persistent') && $definition->getOption('persistent')) {
$filters = $this->filterManager->get($definition);
if (isset($filters['sorting']) && $filters['sorting'] === $sort) {
return;
}
}
$routeParameters['grid']['sorting'] = $sort;
unset($routeParameters['grid']['reset']);
return $this->urlGenerator->generate($definition->getOption('grid_route'), $routeParameters);
}
示例6: execute
/**
* {@inheritDoc}
*
* @param ObtainCreditCard $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);
$httpRequest = null;
if ($this->httpRequest instanceof Request) {
$httpRequest = $this->httpRequest;
} else {
if ($this->httpRequestStack instanceof RequestStack) {
$httpRequest = $this->httpRequestStack->getMasterRequest();
}
}
if (false == $httpRequest) {
throw new LogicException('The action can be run only when http request is set.');
}
$form = $this->createCreditCardForm();
$form->handleRequest($httpRequest);
if ($form->isSubmitted()) {
/** @var CreditCardInterface $card */
$card = $form->getData();
$card->secure();
if ($form->isValid()) {
$request->set($card);
return;
}
}
$renderTemplate = new RenderTemplate($this->templateName, array('model' => $request->getModel(), 'firstModel' => $request->getFirstModel(), 'form' => $form->createView(), 'actionUrl' => $request->getToken() ? $request->getToken()->getTargetUrl() : null));
$this->gateway->execute($renderTemplate);
throw new HttpResponse(new Response($renderTemplate->getResult(), 200, array('Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', 'X-Status-Code' => 200, 'Pragma' => 'no-cache')));
}
示例7: initializeTree
public function initializeTree(TreeInitializedEvent $event)
{
if ($masterRequest = $this->requestStack->getMasterRequest()) {
if ($node = $event->getTree()->find($masterRequest->attributes->all())) {
$node->setActive();
}
}
}
示例8: getMasterRequest
/**
* @return Request
*/
private function getMasterRequest()
{
$masterRequest = $this->requestStack->getMasterRequest();
if (null === $masterRequest) {
throw new \UnexpectedValueException('There are not any requests on request stack');
}
return $masterRequest;
}
示例9: getLocale
/**
* Get user's locale
*
* @return string
*/
protected function getLocale()
{
$request = $this->requestStack->getMasterRequest();
if (null === $request) {
return 'en';
}
return $request->getLocale();
}
示例10: mergeDefaultParameters
/**
* {@inheritdoc}
*/
protected function mergeDefaultParameters(array $parameters)
{
$parameters = parent::mergeDefaultParameters($parameters);
$language = $this->requestStack->getMasterRequest()->headers->get('Accept-Language');
$parameters['headers'] = isset($parameters['headers']) ? $parameters['headers'] : [];
$parameters['headers'] = array_merge($parameters['headers'], ['Accept-Language' => $language]);
return $parameters;
}
示例11: getRequest
/**
* @return Request
*/
public function getRequest()
{
if (null === $this->request) {
return $this->requestStack->getMasterRequest();
} else {
return $this->request;
}
}
示例12: getMasterRequest
/**
* @return Request
*/
private function getMasterRequest()
{
$masterRequest = $this->requestStack->getMasterRequest();
if (null === $masterRequest) {
throw new ChannelNotFoundException();
}
return $masterRequest;
}
示例13: addCurrent
public function addCurrent(ItemInterface $menu)
{
$currentRoute = $this->stack->getMasterRequest()->get('_route');
$route = $this->menu[$menu->getName()]['route'];
if ($currentRoute == $route) {
$menu->setCurrent(true);
}
}
示例14: getCurrentScopeId
/**
* {@inheritdoc}
*/
public function getCurrentScopeId()
{
if (null === $this->requestStack->getMasterRequest()) {
return null;
}
$sessionBag = $this->requestStack->getMasterRequest()->getSession();
$scope = $sessionBag->get($this->getSessionBagNamespace());
return isset($scope['id']) ? $scope['id'] : null;
}
示例15: getCurrentItem
/**
* @return null|Structure
*/
public function getCurrentItem()
{
$request = $this->requestStack->getMasterRequest();
if (empty($this->currentItem) && $request && $request->attributes->has(Structure::ROUTING_ID_NAME)) {
$structureId = $request->attributes->get(Structure::ROUTING_ID_NAME);
$this->currentItem = $this->entityManger->getRepository('OctavaStructureBundle:Structure')->getById($structureId);
}
return $this->currentItem;
}