|
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\ReferenceResolver; |
|
7
|
|
|
|
|
8
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
|
9
|
|
|
use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
11
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunction; |
|
12
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
|
13
|
|
|
use eZ\Publish\Core\FieldType; |
|
14
|
|
|
|
|
15
|
|
|
class ContainerParameterResolver extends AbstractResolver |
|
16
|
|
|
{ |
|
17
|
|
|
protected $referencePrefixes = ['%']; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var ContainerInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $container; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(ContainerInterface $container) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct(); |
|
27
|
|
|
$this->container = $container; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $stringIdentifier |
|
32
|
|
|
* @return mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getReferenceValue($stringIdentifier) |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->container->getParameter(trim($stringIdentifier, '%')); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
View Code Duplication |
private function getExpressionLanguage() |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
{ |
|
42
|
|
|
$language = new ExpressionLanguage(); |
|
43
|
|
|
$language->addFunction( |
|
44
|
|
|
new ExpressionFunction( |
|
45
|
|
|
'relatedContentIds', |
|
46
|
|
|
function() { |
|
47
|
|
|
throw new \Exception('ref function does not support compilation'); |
|
48
|
|
|
}, |
|
49
|
|
|
function($foo, Content $content, $fieldDefinitionIdentifier) { |
|
50
|
|
|
$fieldValue = $content->getFieldValue($fieldDefinitionIdentifier); |
|
51
|
|
|
if ($fieldValue instanceof FieldType\Relation\Value) { |
|
52
|
|
|
return [$fieldValue->destinationContentId]; |
|
53
|
|
|
} elseif ($fieldValue instanceof FieldType\RelationList\Value) { |
|
54
|
|
|
return $fieldValue->destinationContentIds; |
|
55
|
|
|
} else { |
|
56
|
|
|
throw new \Exception("Expected a Relation or RelationList field value"); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
) |
|
60
|
|
|
); |
|
61
|
|
|
$language->addFunction( |
|
62
|
|
|
new ExpressionFunction( |
|
63
|
|
|
'collection_item', |
|
64
|
|
|
function() { |
|
65
|
|
|
throw new \Exception('ref function does not support compilation'); |
|
66
|
|
|
}, |
|
67
|
|
|
function($foo, $identifier) { |
|
68
|
|
|
return $this->referenceResolver->getReferenceValue('reference:collection_item_' . $identifier); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
return $language; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|