Code Duplication    Length = 36-45 lines in 2 locations

eZ/Bundle/EzPublishCoreBundle/Imagine/PlaceholderProviderRegistry.php 1 location

@@ 13-48 (lines=36) @@
10
11
use InvalidArgumentException;
12
13
class PlaceholderProviderRegistry
14
{
15
    /**
16
     * @var \eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProvider
17
     */
18
    private $providers;
19
20
    /**
21
     * PlaceholderProviderRegistry constructor.
22
     *
23
     * @param array $providers
24
     */
25
    public function __construct(array $providers = [])
26
    {
27
        $this->providers = $providers;
28
    }
29
30
    public function addProvider(string $type, PlaceholderProvider $provider)
31
    {
32
        $this->providers[$type] = $provider;
33
    }
34
35
    public function supports(string $type): bool
36
    {
37
        return isset($this->providers[$type]);
38
    }
39
40
    public function getProvider(string $type): PlaceholderProvider
41
    {
42
        if (!$this->supports($type)) {
43
            throw new InvalidArgumentException("Unknown placeholder provider: $type");
44
        }
45
46
        return $this->providers[$type];
47
    }
48
}
49

eZ/Publish/Core/MVC/Symfony/FieldType/View/ParameterProviderRegistry.php 1 location

@@ 13-57 (lines=45) @@
10
11
use InvalidArgumentException;
12
13
class ParameterProviderRegistry implements ParameterProviderRegistryInterface
14
{
15
    protected $providers = array();
16
17
    /**
18
     * Checks if a parameter provider is set for a given field type identifier.
19
     *
20
     * @param string $fieldTypeIdentifier
21
     *
22
     * @return bool
23
     */
24
    public function hasParameterProvider($fieldTypeIdentifier)
25
    {
26
        return isset($this->providers[$fieldTypeIdentifier]);
27
    }
28
29
    /**
30
     * Returns parameter provider for given field type identifier.
31
     *
32
     * @param string $fieldTypeIdentifier
33
     *
34
     * @throws \InvalidArgumentException If no parameter provider is provided for $fieldTypeIdentifier.
35
     *
36
     * @return \eZ\Publish\Core\MVC\Symfony\FieldType\View\ParameterProviderInterface
37
     */
38
    public function getParameterProvider($fieldTypeIdentifier)
39
    {
40
        if (!isset($this->providers[$fieldTypeIdentifier])) {
41
            throw new InvalidArgumentException("No parameter provider found for '$fieldTypeIdentifier' field type.");
42
        }
43
44
        return $this->providers[$fieldTypeIdentifier];
45
    }
46
47
    /**
48
     * Sets a parameter provider for given field type identifier.
49
     *
50
     * @param \eZ\Publish\Core\MVC\Symfony\FieldType\View\ParameterProviderInterface $parameterProvider
51
     * @param string $fieldTypeIdentifier
52
     */
53
    public function setParameterProvider(ParameterProviderInterface $parameterProvider, $fieldTypeIdentifier)
54
    {
55
        $this->providers[$fieldTypeIdentifier] = $parameterProvider;
56
    }
57
}
58