Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpFoundation; Chris@0: Chris@0: /** Chris@0: * Request stack that controls the lifecycle of requests. Chris@0: * Chris@0: * @author Benjamin Eberlei Chris@0: */ Chris@0: class RequestStack Chris@0: { Chris@0: /** Chris@0: * @var Request[] Chris@0: */ Chris@17: private $requests = []; Chris@0: Chris@0: /** Chris@0: * Pushes a Request on the stack. Chris@0: * Chris@0: * This method should generally not be called directly as the stack Chris@0: * management should be taken care of by the application itself. Chris@0: */ Chris@0: public function push(Request $request) Chris@0: { Chris@0: $this->requests[] = $request; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Pops the current request from the stack. Chris@0: * Chris@0: * This operation lets the current request go out of scope. Chris@0: * Chris@0: * This method should generally not be called directly as the stack Chris@0: * management should be taken care of by the application itself. Chris@0: * Chris@0: * @return Request|null Chris@0: */ Chris@0: public function pop() Chris@0: { Chris@0: if (!$this->requests) { Chris@0: return; Chris@0: } Chris@0: Chris@0: return array_pop($this->requests); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return Request|null Chris@0: */ Chris@0: public function getCurrentRequest() Chris@0: { Chris@0: return end($this->requests) ?: null; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the master Request. Chris@0: * Chris@0: * Be warned that making your code aware of the master request Chris@0: * might make it un-compatible with other features of your framework Chris@0: * like ESI support. Chris@0: * Chris@0: * @return Request|null Chris@0: */ Chris@0: public function getMasterRequest() Chris@0: { Chris@0: if (!$this->requests) { Chris@0: return; Chris@0: } Chris@0: Chris@0: return $this->requests[0]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the parent request of the current. Chris@0: * Chris@0: * Be warned that making your code aware of the parent request Chris@0: * might make it un-compatible with other features of your framework Chris@0: * like ESI support. Chris@0: * Chris@0: * If current Request is the master request, it returns null. Chris@0: * Chris@0: * @return Request|null Chris@0: */ Chris@0: public function getParentRequest() Chris@0: { Chris@17: $pos = \count($this->requests) - 2; Chris@0: Chris@0: if (!isset($this->requests[$pos])) { Chris@0: return; Chris@0: } Chris@0: Chris@0: return $this->requests[$pos]; Chris@0: } Chris@0: }