|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Netgen\InformationCollection\Core\Action; |
|
4
|
|
|
|
|
5
|
|
|
use eZ\Publish\API\Repository\Values\ContentType\ContentType; |
|
6
|
|
|
use eZ\Publish\Core\MVC\ConfigResolverInterface; |
|
7
|
|
|
use Netgen\InformationCollection\API\Action\ActionInterface; |
|
8
|
|
|
use OutOfBoundsException; |
|
9
|
|
|
use function sprintf; |
|
10
|
|
|
use function in_array; |
|
11
|
|
|
|
|
12
|
|
|
final class ConfigurationUtility |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
private $actionsdConfiguration; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
private $singleActionConfiguration; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(ConfigResolverInterface $configResolver) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->actionsdConfiguration = $configResolver->getParameter('actions', 'netgen_information_collection'); |
|
|
|
|
|
|
27
|
|
|
$this->singleActionConfiguration = $configResolver->getParameter('action_config', 'netgen_information_collection'); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function isActionAllowedToRun(ActionInterface $action, array $config): bool |
|
31
|
|
|
{ |
|
32
|
|
|
$identifier = new Identifier($action); |
|
33
|
|
|
|
|
34
|
|
|
if (in_array($identifier->getPrimary(), $config, false)) { |
|
35
|
|
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (in_array($identifier->getSecondary(), $config, false)) { |
|
39
|
|
|
return true; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return false; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getActionConfiguration(ActionInterface $action): array |
|
46
|
|
|
{ |
|
47
|
|
|
$identifier = new Identifier($action); |
|
48
|
|
|
|
|
49
|
|
|
if (in_array($identifier->getPrimary(), $this->singleActionConfiguration, false)) { |
|
50
|
|
|
return $this->singleActionConfiguration[$identifier->getPrimary()]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (in_array($identifier->getSecondary(), $this->singleActionConfiguration, false)) { |
|
54
|
|
|
return $this->singleActionConfiguration[$identifier->getSecondary()]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
throw new OutOfBoundsException(sprintf('There is no configuration available for %s', $identifier->getSecondary())); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns configuration for given content type identifier if exists |
|
62
|
|
|
* or default one. |
|
63
|
|
|
* |
|
64
|
|
|
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getConfigPerContentType(ContentType $contentType): array |
|
69
|
|
|
{ |
|
70
|
|
|
if (!empty($this->actionsdConfiguration['content_types'][$contentType->identifier])) { |
|
71
|
|
|
return $this->actionsdConfiguration['content_types'][$contentType->identifier]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (!empty($this->actionsdConfiguration['default'])) { |
|
75
|
|
|
return $this->actionsdConfiguration['default']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return []; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..