annotate vendor/symfony/http-foundation/RequestStack.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\HttpFoundation;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Request stack that controls the lifecycle of requests.
Chris@0 16 *
Chris@0 17 * @author Benjamin Eberlei <kontakt@beberlei.de>
Chris@0 18 */
Chris@0 19 class RequestStack
Chris@0 20 {
Chris@0 21 /**
Chris@0 22 * @var Request[]
Chris@0 23 */
Chris@17 24 private $requests = [];
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Pushes a Request on the stack.
Chris@0 28 *
Chris@0 29 * This method should generally not be called directly as the stack
Chris@0 30 * management should be taken care of by the application itself.
Chris@0 31 */
Chris@0 32 public function push(Request $request)
Chris@0 33 {
Chris@0 34 $this->requests[] = $request;
Chris@0 35 }
Chris@0 36
Chris@0 37 /**
Chris@0 38 * Pops the current request from the stack.
Chris@0 39 *
Chris@0 40 * This operation lets the current request go out of scope.
Chris@0 41 *
Chris@0 42 * This method should generally not be called directly as the stack
Chris@0 43 * management should be taken care of by the application itself.
Chris@0 44 *
Chris@0 45 * @return Request|null
Chris@0 46 */
Chris@0 47 public function pop()
Chris@0 48 {
Chris@0 49 if (!$this->requests) {
Chris@0 50 return;
Chris@0 51 }
Chris@0 52
Chris@0 53 return array_pop($this->requests);
Chris@0 54 }
Chris@0 55
Chris@0 56 /**
Chris@0 57 * @return Request|null
Chris@0 58 */
Chris@0 59 public function getCurrentRequest()
Chris@0 60 {
Chris@0 61 return end($this->requests) ?: null;
Chris@0 62 }
Chris@0 63
Chris@0 64 /**
Chris@0 65 * Gets the master Request.
Chris@0 66 *
Chris@0 67 * Be warned that making your code aware of the master request
Chris@0 68 * might make it un-compatible with other features of your framework
Chris@0 69 * like ESI support.
Chris@0 70 *
Chris@0 71 * @return Request|null
Chris@0 72 */
Chris@0 73 public function getMasterRequest()
Chris@0 74 {
Chris@0 75 if (!$this->requests) {
Chris@0 76 return;
Chris@0 77 }
Chris@0 78
Chris@0 79 return $this->requests[0];
Chris@0 80 }
Chris@0 81
Chris@0 82 /**
Chris@0 83 * Returns the parent request of the current.
Chris@0 84 *
Chris@0 85 * Be warned that making your code aware of the parent request
Chris@0 86 * might make it un-compatible with other features of your framework
Chris@0 87 * like ESI support.
Chris@0 88 *
Chris@0 89 * If current Request is the master request, it returns null.
Chris@0 90 *
Chris@0 91 * @return Request|null
Chris@0 92 */
Chris@0 93 public function getParentRequest()
Chris@0 94 {
Chris@17 95 $pos = \count($this->requests) - 2;
Chris@0 96
Chris@0 97 if (!isset($this->requests[$pos])) {
Chris@0 98 return;
Chris@0 99 }
Chris@0 100
Chris@0 101 return $this->requests[$pos];
Chris@0 102 }
Chris@0 103 }