Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / StandaloneExtensionManager.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
5  * @link      http://github.com/zendframework/zf2 for the canonical source repository
6  * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7  * @license   http://framework.zend.com/license/new-bsd New BSD License
8  */
9
10 namespace Zend\Feed\Writer;
11
12 use Zend\Feed\Writer\Exception\InvalidArgumentException;
13
14 class StandaloneExtensionManager implements ExtensionManagerInterface
15 {
16     private $extensions = [
17         'Atom\Renderer\Feed'           => Extension\Atom\Renderer\Feed::class,
18         'Content\Renderer\Entry'       => Extension\Content\Renderer\Entry::class,
19         'DublinCore\Renderer\Entry'    => Extension\DublinCore\Renderer\Entry::class,
20         'DublinCore\Renderer\Feed'     => Extension\DublinCore\Renderer\Feed::class,
21         'GooglePlayPodcast\Entry'          => Extension\GooglePlayPodcast\Entry::class,
22         'GooglePlayPodcast\Feed'           => Extension\GooglePlayPodcast\Feed::class,
23         'GooglePlayPodcast\Renderer\Entry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
24         'GooglePlayPodcast\Renderer\Feed'  => Extension\GooglePlayPodcast\Renderer\Feed::class,
25         'ITunes\Entry'                 => Extension\ITunes\Entry::class,
26         'ITunes\Feed'                  => Extension\ITunes\Feed::class,
27         'ITunes\Renderer\Entry'        => Extension\ITunes\Renderer\Entry::class,
28         'ITunes\Renderer\Feed'         => Extension\ITunes\Renderer\Feed::class,
29         'Slash\Renderer\Entry'         => Extension\Slash\Renderer\Entry::class,
30         'Threading\Renderer\Entry'     => Extension\Threading\Renderer\Entry::class,
31         'WellFormedWeb\Renderer\Entry' => Extension\WellFormedWeb\Renderer\Entry::class,
32     ];
33
34     /**
35      * Do we have the extension?
36      *
37      * @param  string $extension
38      * @return bool
39      */
40     public function has($extension)
41     {
42         return array_key_exists($extension, $this->extensions);
43     }
44
45     /**
46      * Retrieve the extension
47      *
48      * @param  string $extension
49      * @return mixed
50      */
51     public function get($extension)
52     {
53         $class = $this->extensions[$extension];
54         return new $class();
55     }
56
57     /**
58      * Add an extension.
59      *
60      * @param string $name
61      * @param string $class
62      */
63     public function add($name, $class)
64     {
65         if (is_string($class)
66             && ((
67                 is_a($class, Extension\AbstractRenderer::class, true)
68                 || 'Feed' === substr($class, -4)
69                 || 'Entry' === substr($class, -5)
70             ))
71         ) {
72             $this->extensions[$name] = $class;
73
74             return;
75         }
76
77         throw new InvalidArgumentException(sprintf(
78             'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
79             . 'or the classname must end in "Feed" or "Entry"',
80             $class,
81             __NAMESPACE__
82         ));
83     }
84
85     /**
86      * Remove an extension.
87      *
88      * @param string $name
89      */
90     public function remove($name)
91     {
92         unset($this->extensions[$name]);
93     }
94 }