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@0
|
12 use Zend\ServiceManager\AbstractPluginManager;
|
Chris@0
|
13 use Zend\ServiceManager\Exception\InvalidServiceException;
|
Chris@0
|
14 use Zend\ServiceManager\Factory\InvokableFactory;
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Plugin manager implementation for feed writer extensions
|
Chris@0
|
18 *
|
Chris@0
|
19 * Validation checks that we have an Entry, Feed, or Extension\AbstractRenderer.
|
Chris@0
|
20 */
|
Chris@12
|
21 class ExtensionPluginManager extends AbstractPluginManager implements ExtensionManagerInterface
|
Chris@0
|
22 {
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Aliases for default set of extension classes
|
Chris@0
|
25 *
|
Chris@0
|
26 * @var array
|
Chris@0
|
27 */
|
Chris@0
|
28 protected $aliases = [
|
Chris@0
|
29 'atomrendererfeed' => Extension\Atom\Renderer\Feed::class,
|
Chris@0
|
30 'atomRendererFeed' => Extension\Atom\Renderer\Feed::class,
|
Chris@0
|
31 'AtomRendererFeed' => Extension\Atom\Renderer\Feed::class,
|
Chris@12
|
32 'AtomRenderer\Feed' => Extension\Atom\Renderer\Feed::class,
|
Chris@12
|
33 'Atom\Renderer\Feed' => Extension\Atom\Renderer\Feed::class,
|
Chris@0
|
34 'contentrendererentry' => Extension\Content\Renderer\Entry::class,
|
Chris@0
|
35 'contentRendererEntry' => Extension\Content\Renderer\Entry::class,
|
Chris@0
|
36 'ContentRendererEntry' => Extension\Content\Renderer\Entry::class,
|
Chris@12
|
37 'ContentRenderer\Entry' => Extension\Content\Renderer\Entry::class,
|
Chris@12
|
38 'Content\Renderer\Entry' => Extension\Content\Renderer\Entry::class,
|
Chris@0
|
39 'dublincorerendererentry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@0
|
40 'dublinCoreRendererEntry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@0
|
41 'DublinCoreRendererEntry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@12
|
42 'DublinCoreRenderer\Entry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@12
|
43 'DublinCore\Renderer\Entry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@0
|
44 'dublincorerendererfeed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@0
|
45 'dublinCoreRendererFeed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@0
|
46 'DublinCoreRendererFeed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@12
|
47 'DublinCoreRenderer\Feed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@12
|
48 'DublinCore\Renderer\Feed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@16
|
49 'googleplaypodcastentry' => Extension\GooglePlayPodcast\Entry::class,
|
Chris@16
|
50 'googleplaypodcastEntry' => Extension\GooglePlayPodcast\Entry::class,
|
Chris@16
|
51 'googlePlayPodcastEntry' => Extension\GooglePlayPodcast\Entry::class,
|
Chris@16
|
52 'GooglePlayPodcastEntry' => Extension\GooglePlayPodcast\Entry::class,
|
Chris@16
|
53 'Googleplaypodcast\Entry' => Extension\GooglePlayPodcast\Entry::class,
|
Chris@16
|
54 'GooglePlayPodcast\Entry' => Extension\GooglePlayPodcast\Entry::class,
|
Chris@16
|
55 'googleplaypodcastfeed' => Extension\GooglePlayPodcast\Feed::class,
|
Chris@16
|
56 'googleplaypodcastFeed' => Extension\GooglePlayPodcast\Feed::class,
|
Chris@16
|
57 'googlePlayPodcastFeed' => Extension\GooglePlayPodcast\Feed::class,
|
Chris@16
|
58 'GooglePlayPodcastFeed' => Extension\GooglePlayPodcast\Feed::class,
|
Chris@16
|
59 'Googleplaypodcast\Feed' => Extension\GooglePlayPodcast\Feed::class,
|
Chris@16
|
60 'GooglePlayPodcast\Feed' => Extension\GooglePlayPodcast\Feed::class,
|
Chris@16
|
61 'googleplaypodcastrendererentry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
|
Chris@16
|
62 'googleplaypodcastRendererEntry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
|
Chris@16
|
63 'googlePlayPodcastRendererEntry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
|
Chris@16
|
64 'GooglePlayPodcastRendererEntry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
|
Chris@16
|
65 'GoogleplaypodcastRenderer\Entry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
|
Chris@16
|
66 'GooglePlayPodcast\Renderer\Entry' => Extension\GooglePlayPodcast\Renderer\Entry::class,
|
Chris@16
|
67 'googleplaypodcastrendererfeed' => Extension\GooglePlayPodcast\Renderer\Feed::class,
|
Chris@16
|
68 'googleplaypodcastRendererFeed' => Extension\GooglePlayPodcast\Renderer\Feed::class,
|
Chris@16
|
69 'googlePlayPodcastRendererFeed' => Extension\GooglePlayPodcast\Renderer\Feed::class,
|
Chris@16
|
70 'GooglePlayPodcastRendererFeed' => Extension\GooglePlayPodcast\Renderer\Feed::class,
|
Chris@16
|
71 'GoogleplaypodcastRenderer\Feed' => Extension\GooglePlayPodcast\Renderer\Feed::class,
|
Chris@16
|
72 'GooglePlayPodcast\Renderer\Feed' => Extension\GooglePlayPodcast\Renderer\Feed::class,
|
Chris@0
|
73 'itunesentry' => Extension\ITunes\Entry::class,
|
Chris@0
|
74 'itunesEntry' => Extension\ITunes\Entry::class,
|
Chris@0
|
75 'iTunesEntry' => Extension\ITunes\Entry::class,
|
Chris@0
|
76 'ItunesEntry' => Extension\ITunes\Entry::class,
|
Chris@12
|
77 'Itunes\Entry' => Extension\ITunes\Entry::class,
|
Chris@12
|
78 'ITunes\Entry' => Extension\ITunes\Entry::class,
|
Chris@0
|
79 'itunesfeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
80 'itunesFeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
81 'iTunesFeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
82 'ItunesFeed' => Extension\ITunes\Feed::class,
|
Chris@12
|
83 'Itunes\Feed' => Extension\ITunes\Feed::class,
|
Chris@12
|
84 'ITunes\Feed' => Extension\ITunes\Feed::class,
|
Chris@0
|
85 'itunesrendererentry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
86 'itunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
87 'iTunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
88 'ItunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@12
|
89 'ItunesRenderer\Entry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@12
|
90 'ITunes\Renderer\Entry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
91 'itunesrendererfeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
92 'itunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
93 'iTunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
94 'ItunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@12
|
95 'ItunesRenderer\Feed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@12
|
96 'ITunes\Renderer\Feed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
97 'slashrendererentry' => Extension\Slash\Renderer\Entry::class,
|
Chris@0
|
98 'slashRendererEntry' => Extension\Slash\Renderer\Entry::class,
|
Chris@0
|
99 'SlashRendererEntry' => Extension\Slash\Renderer\Entry::class,
|
Chris@12
|
100 'SlashRenderer\Entry' => Extension\Slash\Renderer\Entry::class,
|
Chris@12
|
101 'Slash\Renderer\Entry' => Extension\Slash\Renderer\Entry::class,
|
Chris@0
|
102 'threadingrendererentry' => Extension\Threading\Renderer\Entry::class,
|
Chris@0
|
103 'threadingRendererEntry' => Extension\Threading\Renderer\Entry::class,
|
Chris@0
|
104 'ThreadingRendererEntry' => Extension\Threading\Renderer\Entry::class,
|
Chris@12
|
105 'ThreadingRenderer\Entry' => Extension\Threading\Renderer\Entry::class,
|
Chris@12
|
106 'Threading\Renderer\Entry' => Extension\Threading\Renderer\Entry::class,
|
Chris@0
|
107 'wellformedwebrendererentry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@0
|
108 'wellFormedWebRendererEntry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@0
|
109 'WellFormedWebRendererEntry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@12
|
110 'WellFormedWebRenderer\Entry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@12
|
111 'WellFormedWeb\Renderer\Entry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@0
|
112 ];
|
Chris@0
|
113
|
Chris@0
|
114 /**
|
Chris@0
|
115 * Factories for default set of extension classes
|
Chris@0
|
116 *
|
Chris@0
|
117 * @var array
|
Chris@0
|
118 */
|
Chris@0
|
119 protected $factories = [
|
Chris@0
|
120 Extension\Atom\Renderer\Feed::class => InvokableFactory::class,
|
Chris@0
|
121 Extension\Content\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
122 Extension\DublinCore\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
123 Extension\DublinCore\Renderer\Feed::class => InvokableFactory::class,
|
Chris@16
|
124 Extension\GooglePlayPodcast\Entry::class => InvokableFactory::class,
|
Chris@16
|
125 Extension\GooglePlayPodcast\Feed::class => InvokableFactory::class,
|
Chris@16
|
126 Extension\GooglePlayPodcast\Renderer\Entry::class => InvokableFactory::class,
|
Chris@16
|
127 Extension\GooglePlayPodcast\Renderer\Feed::class => InvokableFactory::class,
|
Chris@0
|
128 Extension\ITunes\Entry::class => InvokableFactory::class,
|
Chris@0
|
129 Extension\ITunes\Feed::class => InvokableFactory::class,
|
Chris@0
|
130 Extension\ITunes\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
131 Extension\ITunes\Renderer\Feed::class => InvokableFactory::class,
|
Chris@0
|
132 Extension\Slash\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
133 Extension\Threading\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
134 Extension\WellFormedWeb\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
135 // Legacy (v2) due to alias resolution; canonical form of resolved
|
Chris@0
|
136 // alias is used to look up the factory, while the non-normalized
|
Chris@0
|
137 // resolved alias is used as the requested name passed to the factory.
|
Chris@0
|
138 'zendfeedwriterextensionatomrendererfeed' => InvokableFactory::class,
|
Chris@0
|
139 'zendfeedwriterextensioncontentrendererentry' => InvokableFactory::class,
|
Chris@0
|
140 'zendfeedwriterextensiondublincorerendererentry' => InvokableFactory::class,
|
Chris@0
|
141 'zendfeedwriterextensiondublincorerendererfeed' => InvokableFactory::class,
|
Chris@16
|
142 'zendfeedwriterextensiongoogleplaypodcastentry' => InvokableFactory::class,
|
Chris@16
|
143 'zendfeedwriterextensiongoogleplaypodcastfeed' => InvokableFactory::class,
|
Chris@16
|
144 'zendfeedwriterextensiongoogleplaypodcastrendererentry' => InvokableFactory::class,
|
Chris@16
|
145 'zendfeedwriterextensiongoogleplaypodcastrendererfeed' => InvokableFactory::class,
|
Chris@16
|
146
|
Chris@0
|
147 'zendfeedwriterextensionitunesentry' => InvokableFactory::class,
|
Chris@0
|
148 'zendfeedwriterextensionitunesfeed' => InvokableFactory::class,
|
Chris@0
|
149 'zendfeedwriterextensionitunesrendererentry' => InvokableFactory::class,
|
Chris@0
|
150 'zendfeedwriterextensionitunesrendererfeed' => InvokableFactory::class,
|
Chris@0
|
151 'zendfeedwriterextensionslashrendererentry' => InvokableFactory::class,
|
Chris@0
|
152 'zendfeedwriterextensionthreadingrendererentry' => InvokableFactory::class,
|
Chris@0
|
153 'zendfeedwriterextensionwellformedwebrendererentry' => InvokableFactory::class,
|
Chris@0
|
154 ];
|
Chris@0
|
155
|
Chris@0
|
156 /**
|
Chris@0
|
157 * Do not share instances (v2)
|
Chris@0
|
158 *
|
Chris@0
|
159 * @var bool
|
Chris@0
|
160 */
|
Chris@0
|
161 protected $shareByDefault = false;
|
Chris@0
|
162
|
Chris@0
|
163 /**
|
Chris@0
|
164 * Do not share instances (v3)
|
Chris@0
|
165 *
|
Chris@0
|
166 * @var bool
|
Chris@0
|
167 */
|
Chris@0
|
168 protected $sharedByDefault = false;
|
Chris@0
|
169
|
Chris@0
|
170 /**
|
Chris@0
|
171 * Validate the plugin (v3)
|
Chris@0
|
172 *
|
Chris@0
|
173 * Checks that the extension loaded is of a valid type.
|
Chris@0
|
174 *
|
Chris@0
|
175 * @param mixed $plugin
|
Chris@0
|
176 * @return void
|
Chris@0
|
177 * @throws InvalidServiceException if invalid
|
Chris@0
|
178 */
|
Chris@0
|
179 public function validate($plugin)
|
Chris@0
|
180 {
|
Chris@0
|
181 if ($plugin instanceof Extension\AbstractRenderer) {
|
Chris@0
|
182 // we're okay
|
Chris@0
|
183 return;
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 if ('Feed' == substr(get_class($plugin), -4)) {
|
Chris@0
|
187 // we're okay
|
Chris@0
|
188 return;
|
Chris@0
|
189 }
|
Chris@0
|
190
|
Chris@0
|
191 if ('Entry' == substr(get_class($plugin), -5)) {
|
Chris@0
|
192 // we're okay
|
Chris@0
|
193 return;
|
Chris@0
|
194 }
|
Chris@0
|
195
|
Chris@0
|
196 throw new InvalidServiceException(sprintf(
|
Chris@0
|
197 'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
|
Chris@0
|
198 . 'or the classname must end in "Feed" or "Entry"',
|
Chris@0
|
199 (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
|
Chris@0
|
200 __NAMESPACE__
|
Chris@0
|
201 ));
|
Chris@0
|
202 }
|
Chris@0
|
203
|
Chris@0
|
204 /**
|
Chris@0
|
205 * Validate plugin (v2)
|
Chris@0
|
206 *
|
Chris@0
|
207 * @param mixed $plugin
|
Chris@0
|
208 * @return void
|
Chris@0
|
209 * @throws Exception\InvalidArgumentException when invalid
|
Chris@0
|
210 */
|
Chris@0
|
211 public function validatePlugin($plugin)
|
Chris@0
|
212 {
|
Chris@0
|
213 try {
|
Chris@0
|
214 $this->validate($plugin);
|
Chris@0
|
215 } catch (InvalidServiceException $e) {
|
Chris@0
|
216 throw new Exception\InvalidArgumentException(sprintf(
|
Chris@0
|
217 'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
|
Chris@0
|
218 . 'or the classname must end in "Feed" or "Entry"',
|
Chris@0
|
219 (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
|
Chris@0
|
220 __NAMESPACE__
|
Chris@0
|
221 ));
|
Chris@0
|
222 }
|
Chris@0
|
223 }
|
Chris@0
|
224 }
|