3babc2958357db6d36cb38909b2a86e85c10b921
[yaffs-website] / vendor / zendframework / zend-feed / src / Reader / 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\Reader;
11
12 use Zend\Feed\Reader\Exception\InvalidArgumentException;
13
14 class StandaloneExtensionManager implements ExtensionManagerInterface
15 {
16     private $extensions = [
17         'Atom\Entry'            => Extension\Atom\Entry::class,
18         'Atom\Feed'             => Extension\Atom\Feed::class,
19         'Content\Entry'         => Extension\Content\Entry::class,
20         'CreativeCommons\Entry' => Extension\CreativeCommons\Entry::class,
21         'CreativeCommons\Feed'  => Extension\CreativeCommons\Feed::class,
22         'DublinCore\Entry'      => Extension\DublinCore\Entry::class,
23         'DublinCore\Feed'       => Extension\DublinCore\Feed::class,
24         'GooglePlayPodcast\Entry' => Extension\GooglePlayPodcast\Entry::class,
25         'GooglePlayPodcast\Feed'  => Extension\GooglePlayPodcast\Feed::class,
26         'Podcast\Entry'         => Extension\Podcast\Entry::class,
27         'Podcast\Feed'          => Extension\Podcast\Feed::class,
28         'Slash\Entry'           => Extension\Slash\Entry::class,
29         'Syndication\Feed'      => Extension\Syndication\Feed::class,
30         'Thread\Entry'          => Extension\Thread\Entry::class,
31         'WellFormedWeb\Entry'   => Extension\WellFormedWeb\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 Extension\AbstractEntry|Extension\AbstractFeed
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\AbstractEntry::class, true)
68                 || is_a($class, Extension\AbstractFeed::class, true)
69             )
70         ) {
71             $this->extensions[$name] = $class;
72             return;
73         }
74
75         throw new InvalidArgumentException(sprintf(
76             'Plugin of type %s is invalid; must implement %2$s\Extension\AbstractFeed '
77             . 'or %2$s\Extension\AbstractEntry',
78             $class,
79             __NAMESPACE__
80         ));
81     }
82
83     /**
84      * Remove an extension.
85      *
86      * @param string $name
87      */
88     public function remove($name)
89     {
90         unset($this->extensions[$name]);
91     }
92 }