RequestStackContext.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Asset\Context;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. /**
  13. * Uses a RequestStack to populate the context.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class RequestStackContext implements ContextInterface
  18. {
  19. private $requestStack;
  20. public function __construct(RequestStack $requestStack)
  21. {
  22. $this->requestStack = $requestStack;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function getBasePath()
  28. {
  29. if (!$request = $this->requestStack->getMasterRequest()) {
  30. return '';
  31. }
  32. return $request->getBasePath();
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function isSecure()
  38. {
  39. if (!$request = $this->requestStack->getMasterRequest()) {
  40. return false;
  41. }
  42. return $request->isSecure();
  43. }
  44. }