1<?php
2
3/**
4 * @see       https://github.com/laminas/laminas-feed for the canonical source repository
5 * @copyright https://github.com/laminas/laminas-feed/blob/master/COPYRIGHT.md
6 * @license   https://github.com/laminas/laminas-feed/blob/master/LICENSE.md New BSD License
7 */
8
9namespace Laminas\Feed\Reader;
10
11/**
12 * Default implementation of ExtensionManagerInterface
13 *
14 * Decorator of ExtensionPluginManager.
15 */
16class ExtensionManager implements ExtensionManagerInterface
17{
18    protected $pluginManager;
19
20    /**
21     * Seeds the extension manager with a plugin manager; if none provided,
22     * creates an instance.
23     */
24    public function __construct(ExtensionPluginManager $pluginManager = null)
25    {
26        if (null === $pluginManager) {
27            $pluginManager = new ExtensionPluginManager();
28        }
29        $this->pluginManager = $pluginManager;
30    }
31
32    /**
33     * Method overloading
34     *
35     * Proxy to composed ExtensionPluginManager instance.
36     *
37     * @param  string $method
38     * @param  array $args
39     * @return mixed
40     * @throws Exception\BadMethodCallException
41     */
42    public function __call($method, $args)
43    {
44        if (! method_exists($this->pluginManager, $method)) {
45            throw new Exception\BadMethodCallException(sprintf(
46                'Method by name of %s does not exist in %s',
47                $method,
48                __CLASS__
49            ));
50        }
51        return call_user_func_array([$this->pluginManager, $method], $args);
52    }
53
54    /**
55     * Get the named extension
56     *
57     * @param  string $name
58     * @return Extension\AbstractEntry|Extension\AbstractFeed
59     */
60    public function get($name)
61    {
62        return $this->pluginManager->get($name);
63    }
64
65    /**
66     * Do we have the named extension?
67     *
68     * @param  string $name
69     * @return bool
70     */
71    public function has($name)
72    {
73        return $this->pluginManager->has($name);
74    }
75}
76