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

ExpressionResponseMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 28
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 7 1
A getExpressionLanguage() 0 8 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