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