7b8c61c04163c4bd6fff4f98901a58d9ec0cec12
[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         'Podcast\Entry'         => Extension\Podcast\Entry::class,
25         'Podcast\Feed'          => Extension\Podcast\Feed::class,
26         'Slash\Entry'           => Extension\Slash\Entry::class,
27         'Syndication\Feed'      => Extension\Syndication\Feed::class,
28         'Thread\Entry'          => Extension\Thread\Entry::class,
29         'WellFormedWeb\Entry'   => Extension\WellFormedWeb\Entry::class,
30     ];
31
32     /**
33      * Do we have the extension?
34      *
35      * @param  string $extension
36      * @return bool
37      */
38     public function has($extension)
39     {
40         return array_key_exists($extension, $this->extensions);
41     }
42
43     /**
44      * Retrieve the extension
45      *
46      * @param  string $extension
47      * @return Extension\AbstractEntry|Extension\AbstractFeed
48      */
49     public function get($extension)
50     {
51         $class = $this->extensions[$extension];
52         return new $class();
53     }
54
55     /**
56      * Add an extension.
57      *
58      * @param string $name
59      * @param string $class
60      */
61     public function add($name, $class)
62     {
63         if (is_string($class)
64             && (
65                 is_a($class, Extension\AbstractEntry::class, true)
66                 || is_a($class, Extension\AbstractFeed::class, true)
67             )
68         ) {
69             $this->extensions[$name] = $class;
70             return;
71         }
72
73         throw new InvalidArgumentException(sprintf(
74             'Plugin of type %s is invalid; must implement %2$s\Extension\AbstractFeed '
75             . 'or %2$s\Extension\AbstractEntry',
76             $class,
77             __NAMESPACE__
78         ));
79     }
80
81     /**
82      * Remove an extension.
83      *
84      * @param string $name
85      */
86     public function remove($name)
87     {
88         unset($this->extensions[$name]);
89     }
90 }