vendor/friendsofsymfony/http-cache-bundle/src/Http/ResponseMatcher/ExpressionResponseMatcher.php line 30

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the FOSHttpCacheBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\HttpCacheBundle\Http\ResponseMatcher;
  11. use Sensio\Bundle\FrameworkExtraBundle\Security\ExpressionLanguage as SecurityExpressionLanguage;
  12. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  13. use Symfony\Component\HttpFoundation\Response;
  14. class ExpressionResponseMatcher implements ResponseMatcherInterface
  15. {
  16. /**
  17. * @var ExpressionLanguage
  18. */
  19. private $expressionLanguage;
  20. /**
  21. * @var string
  22. */
  23. private $expression;
  24. public function __construct($expression, ExpressionLanguage $expressionLanguage = null)
  25. {
  26. $this->expression = $expression;
  27. $this->expressionLanguage = $expressionLanguage;
  28. }
  29. public function matches(Response $response)
  30. {
  31. return $this->getExpressionLanguage()->evaluate(
  32. $this->expression,
  33. ['response' => $response]
  34. );
  35. }
  36. private function getExpressionLanguage()
  37. {
  38. if (!$this->expressionLanguage) {
  39. $this->expressionLanguage = class_exists(SecurityExpressionLanguage::class)
  40. ? new SecurityExpressionLanguage()
  41. : new ExpressionLanguage()
  42. ;
  43. }
  44. return $this->expressionLanguage;
  45. }
  46. }