vendor/friendsofsymfony/http-cache-bundle/src/Http/RuleMatcher.php line 42

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;
  11. use FOS\HttpCacheBundle\Http\ResponseMatcher\ResponseMatcherInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\RequestMatcherInterface;
  14. use Symfony\Component\HttpFoundation\Response;
  15. /**
  16. * Combines a RequestMatcherInterface and a ResponseMatcherInterface.
  17. *
  18. * Both must match for the RuleMatcher to match.
  19. *
  20. * @author David Buchmann <mail@davidbu.ch>
  21. */
  22. class RuleMatcher implements RuleMatcherInterface
  23. {
  24. /**
  25. * @var RequestMatcherInterface
  26. */
  27. private $requestMatcher;
  28. /**
  29. * @var ResponseMatcherInterface
  30. */
  31. private $responseMatcher;
  32. /**
  33. * @param RequestMatcherInterface $requestMatcher|null Request matcher
  34. * @param ResponseMatcherInterface $responseMatcher|null Response matcher
  35. */
  36. public function __construct(
  37. RequestMatcherInterface $requestMatcher = null,
  38. ResponseMatcherInterface $responseMatcher = null
  39. ) {
  40. $this->requestMatcher = $requestMatcher;
  41. $this->responseMatcher = $responseMatcher;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function matches(Request $request, Response $response)
  47. {
  48. if ($this->requestMatcher && !$this->requestMatcher->matches($request)) {
  49. return false;
  50. }
  51. if ($this->responseMatcher && !$this->responseMatcher->matches($response)) {
  52. return false;
  53. }
  54. return true;
  55. }
  56. }