Completed
Pull Request — master (#81)
by
unknown
28:56
created

CollectionItemFunctionProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace Kaliop\eZMigrationBundle\Core\ExpressionLanguage;
7
8
use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface;
9
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
10
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
11
12
/**
13
 * Defines the 'collection_item' function.
14
 */
15
class CollectionItemFunctionProvider implements ExpressionFunctionProviderInterface
16
{
17
    /**
18
     * @var ReferenceResolverInterface
19
     */
20
    private $referenceResolver;
21
22
    public function __construct(ReferenceResolverInterface $referenceResolver)
23
    {
24
        $this->referenceResolver = $referenceResolver;
25
    }
26
27
    /**
28
     * @return ExpressionFunction[] An array of Function instances
29
     */
30
    public function getFunctions()
31
    {
32
        return [
33
            new ExpressionFunction(
34
                'collection_item',
35
                function() {
36
                    throw new \Exception('ref function does not support compilation');
37
                },
38
                function($foo, $identifier) {
39
                    return $this->referenceResolver->getReferenceValue('reference:collection_item_' . $identifier);
40
                }
41
            ),
42
        ];
43
    }
44
}
45