4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation;
15 * Request stack that controls the lifecycle of requests.
17 * @author Benjamin Eberlei <kontakt@beberlei.de>
24 private $requests = array();
27 * Pushes a Request on the stack.
29 * This method should generally not be called directly as the stack
30 * management should be taken care of by the application itself.
32 public function push(Request $request)
34 $this->requests[] = $request;
38 * Pops the current request from the stack.
40 * This operation lets the current request go out of scope.
42 * This method should generally not be called directly as the stack
43 * management should be taken care of by the application itself.
45 * @return Request|null
49 if (!$this->requests) {
53 return array_pop($this->requests);
57 * @return Request|null
59 public function getCurrentRequest()
61 return end($this->requests) ?: null;
65 * Gets the master Request.
67 * Be warned that making your code aware of the master request
68 * might make it un-compatible with other features of your framework
71 * @return Request|null
73 public function getMasterRequest()
75 if (!$this->requests) {
79 return $this->requests[0];
83 * Returns the parent request of the current.
85 * Be warned that making your code aware of the parent request
86 * might make it un-compatible with other features of your framework
89 * If current Request is the master request, it returns null.
91 * @return Request|null
93 public function getParentRequest()
95 $pos = \count($this->requests) - 2;
97 if (!isset($this->requests[$pos])) {
101 return $this->requests[$pos];