Completed
Push — master ( 0de349...246355 )
by David
13s
created

ExpressionResponseMatcher::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Http\ResponseMatcher;
13
14
use Sensio\Bundle\FrameworkExtraBundle\Security\ExpressionLanguage;
15
use Symfony\Component\HttpFoundation\Response;
16
17
class ExpressionResponseMatcher implements ResponseMatcherInterface
18
{
19
    private $expressionLanguage;
20
    private $expression;
21
22
    public function __construct($expression, ExpressionLanguage $expressionLanguage)
23
    {
24
        $this->expression = $expression;
25
        $this->expressionLanguage = $expressionLanguage;
26
    }
27
28
    public function matches(Response $response)
29
    {
30
        return $this->getExpressionLanguage()->evaluate(
31
            $this->expression,
32
            ['response' => $response]
33
        );
34
    }
35
36
    private function getExpressionLanguage()
37
    {
38
        if (!$this->expressionLanguage) {
39
            $this->expressionLanguage = new ExpressionLanguage();
40
        }
41
42
        return $this->expressionLanguage;
43
    }
44
}
45