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@0
|
21 class ExtensionPluginManager extends AbstractPluginManager
|
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@0
|
32 'contentrendererentry' => Extension\Content\Renderer\Entry::class,
|
Chris@0
|
33 'contentRendererEntry' => Extension\Content\Renderer\Entry::class,
|
Chris@0
|
34 'ContentRendererEntry' => Extension\Content\Renderer\Entry::class,
|
Chris@0
|
35 'dublincorerendererentry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@0
|
36 'dublinCoreRendererEntry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@0
|
37 'DublinCoreRendererEntry' => Extension\DublinCore\Renderer\Entry::class,
|
Chris@0
|
38 'dublincorerendererfeed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@0
|
39 'dublinCoreRendererFeed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@0
|
40 'DublinCoreRendererFeed' => Extension\DublinCore\Renderer\Feed::class,
|
Chris@0
|
41 'itunesentry' => Extension\ITunes\Entry::class,
|
Chris@0
|
42 'itunesEntry' => Extension\ITunes\Entry::class,
|
Chris@0
|
43 'iTunesEntry' => Extension\ITunes\Entry::class,
|
Chris@0
|
44 'ItunesEntry' => Extension\ITunes\Entry::class,
|
Chris@0
|
45 'itunesfeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
46 'itunesFeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
47 'iTunesFeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
48 'ItunesFeed' => Extension\ITunes\Feed::class,
|
Chris@0
|
49 'itunesrendererentry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
50 'itunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
51 'iTunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
52 'ItunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
|
Chris@0
|
53 'itunesrendererfeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
54 'itunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
55 'iTunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
56 'ItunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
|
Chris@0
|
57 'slashrendererentry' => Extension\Slash\Renderer\Entry::class,
|
Chris@0
|
58 'slashRendererEntry' => Extension\Slash\Renderer\Entry::class,
|
Chris@0
|
59 'SlashRendererEntry' => Extension\Slash\Renderer\Entry::class,
|
Chris@0
|
60 'threadingrendererentry' => Extension\Threading\Renderer\Entry::class,
|
Chris@0
|
61 'threadingRendererEntry' => Extension\Threading\Renderer\Entry::class,
|
Chris@0
|
62 'ThreadingRendererEntry' => Extension\Threading\Renderer\Entry::class,
|
Chris@0
|
63 'wellformedwebrendererentry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@0
|
64 'wellFormedWebRendererEntry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@0
|
65 'WellFormedWebRendererEntry' => Extension\WellFormedWeb\Renderer\Entry::class,
|
Chris@0
|
66 ];
|
Chris@0
|
67
|
Chris@0
|
68 /**
|
Chris@0
|
69 * Factories for default set of extension classes
|
Chris@0
|
70 *
|
Chris@0
|
71 * @var array
|
Chris@0
|
72 */
|
Chris@0
|
73 protected $factories = [
|
Chris@0
|
74 Extension\Atom\Renderer\Feed::class => InvokableFactory::class,
|
Chris@0
|
75 Extension\Content\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
76 Extension\DublinCore\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
77 Extension\DublinCore\Renderer\Feed::class => InvokableFactory::class,
|
Chris@0
|
78 Extension\ITunes\Entry::class => InvokableFactory::class,
|
Chris@0
|
79 Extension\ITunes\Feed::class => InvokableFactory::class,
|
Chris@0
|
80 Extension\ITunes\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
81 Extension\ITunes\Renderer\Feed::class => InvokableFactory::class,
|
Chris@0
|
82 Extension\Slash\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
83 Extension\Threading\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
84 Extension\WellFormedWeb\Renderer\Entry::class => InvokableFactory::class,
|
Chris@0
|
85 // Legacy (v2) due to alias resolution; canonical form of resolved
|
Chris@0
|
86 // alias is used to look up the factory, while the non-normalized
|
Chris@0
|
87 // resolved alias is used as the requested name passed to the factory.
|
Chris@0
|
88 'zendfeedwriterextensionatomrendererfeed' => InvokableFactory::class,
|
Chris@0
|
89 'zendfeedwriterextensioncontentrendererentry' => InvokableFactory::class,
|
Chris@0
|
90 'zendfeedwriterextensiondublincorerendererentry' => InvokableFactory::class,
|
Chris@0
|
91 'zendfeedwriterextensiondublincorerendererfeed' => InvokableFactory::class,
|
Chris@0
|
92 'zendfeedwriterextensionitunesentry' => InvokableFactory::class,
|
Chris@0
|
93 'zendfeedwriterextensionitunesfeed' => InvokableFactory::class,
|
Chris@0
|
94 'zendfeedwriterextensionitunesrendererentry' => InvokableFactory::class,
|
Chris@0
|
95 'zendfeedwriterextensionitunesrendererfeed' => InvokableFactory::class,
|
Chris@0
|
96 'zendfeedwriterextensionslashrendererentry' => InvokableFactory::class,
|
Chris@0
|
97 'zendfeedwriterextensionthreadingrendererentry' => InvokableFactory::class,
|
Chris@0
|
98 'zendfeedwriterextensionwellformedwebrendererentry' => InvokableFactory::class,
|
Chris@0
|
99 ];
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * Do not share instances (v2)
|
Chris@0
|
103 *
|
Chris@0
|
104 * @var bool
|
Chris@0
|
105 */
|
Chris@0
|
106 protected $shareByDefault = false;
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * Do not share instances (v3)
|
Chris@0
|
110 *
|
Chris@0
|
111 * @var bool
|
Chris@0
|
112 */
|
Chris@0
|
113 protected $sharedByDefault = false;
|
Chris@0
|
114
|
Chris@0
|
115 /**
|
Chris@0
|
116 * Validate the plugin (v3)
|
Chris@0
|
117 *
|
Chris@0
|
118 * Checks that the extension loaded is of a valid type.
|
Chris@0
|
119 *
|
Chris@0
|
120 * @param mixed $plugin
|
Chris@0
|
121 * @return void
|
Chris@0
|
122 * @throws InvalidServiceException if invalid
|
Chris@0
|
123 */
|
Chris@0
|
124 public function validate($plugin)
|
Chris@0
|
125 {
|
Chris@0
|
126 if ($plugin instanceof Extension\AbstractRenderer) {
|
Chris@0
|
127 // we're okay
|
Chris@0
|
128 return;
|
Chris@0
|
129 }
|
Chris@0
|
130
|
Chris@0
|
131 if ('Feed' == substr(get_class($plugin), -4)) {
|
Chris@0
|
132 // we're okay
|
Chris@0
|
133 return;
|
Chris@0
|
134 }
|
Chris@0
|
135
|
Chris@0
|
136 if ('Entry' == substr(get_class($plugin), -5)) {
|
Chris@0
|
137 // we're okay
|
Chris@0
|
138 return;
|
Chris@0
|
139 }
|
Chris@0
|
140
|
Chris@0
|
141 throw new InvalidServiceException(sprintf(
|
Chris@0
|
142 'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
|
Chris@0
|
143 . 'or the classname must end in "Feed" or "Entry"',
|
Chris@0
|
144 (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
|
Chris@0
|
145 __NAMESPACE__
|
Chris@0
|
146 ));
|
Chris@0
|
147 }
|
Chris@0
|
148
|
Chris@0
|
149 /**
|
Chris@0
|
150 * Validate plugin (v2)
|
Chris@0
|
151 *
|
Chris@0
|
152 * @param mixed $plugin
|
Chris@0
|
153 * @return void
|
Chris@0
|
154 * @throws Exception\InvalidArgumentException when invalid
|
Chris@0
|
155 */
|
Chris@0
|
156 public function validatePlugin($plugin)
|
Chris@0
|
157 {
|
Chris@0
|
158 try {
|
Chris@0
|
159 $this->validate($plugin);
|
Chris@0
|
160 } catch (InvalidServiceException $e) {
|
Chris@0
|
161 throw new Exception\InvalidArgumentException(sprintf(
|
Chris@0
|
162 'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
|
Chris@0
|
163 . 'or the classname must end in "Feed" or "Entry"',
|
Chris@0
|
164 (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
|
Chris@0
|
165 __NAMESPACE__
|
Chris@0
|
166 ));
|
Chris@0
|
167 }
|
Chris@0
|
168 }
|
Chris@0
|
169 }
|