This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathExtensionPluginManager.php
180 lines (169 loc) · 8.54 KB
/
ExtensionPluginManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Writer;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;
/**
* Plugin manager implementation for feed writer extensions
*
* Validation checks that we have an Entry, Feed, or Extension\AbstractRenderer.
*/
class ExtensionPluginManager extends AbstractPluginManager implements ExtensionManagerInterface
{
/**
* Aliases for default set of extension classes
*
* @var array
*/
protected $aliases = [
'atomrendererfeed' => Extension\Atom\Renderer\Feed::class,
'atomRendererFeed' => Extension\Atom\Renderer\Feed::class,
'AtomRendererFeed' => Extension\Atom\Renderer\Feed::class,
'AtomRenderer\Feed' => Extension\Atom\Renderer\Feed::class,
'contentrendererentry' => Extension\Content\Renderer\Entry::class,
'contentRendererEntry' => Extension\Content\Renderer\Entry::class,
'ContentRendererEntry' => Extension\Content\Renderer\Entry::class,
'ContentRenderer\Entry' => Extension\Content\Renderer\Entry::class,
'dublincorerendererentry' => Extension\DublinCore\Renderer\Entry::class,
'dublinCoreRendererEntry' => Extension\DublinCore\Renderer\Entry::class,
'DublinCoreRendererEntry' => Extension\DublinCore\Renderer\Entry::class,
'DublinCoreRenderer\Entry' => Extension\DublinCore\Renderer\Entry::class,
'dublincorerendererfeed' => Extension\DublinCore\Renderer\Feed::class,
'dublinCoreRendererFeed' => Extension\DublinCore\Renderer\Feed::class,
'DublinCoreRendererFeed' => Extension\DublinCore\Renderer\Feed::class,
'DublinCoreRenderer\Feed' => Extension\DublinCore\Renderer\Feed::class,
'itunesentry' => Extension\ITunes\Entry::class,
'itunesEntry' => Extension\ITunes\Entry::class,
'iTunesEntry' => Extension\ITunes\Entry::class,
'ItunesEntry' => Extension\ITunes\Entry::class,
'Itunes\Entry' => Extension\ITunes\Entry::class,
'itunesfeed' => Extension\ITunes\Feed::class,
'itunesFeed' => Extension\ITunes\Feed::class,
'iTunesFeed' => Extension\ITunes\Feed::class,
'ItunesFeed' => Extension\ITunes\Feed::class,
'Itunes\Feed' => Extension\ITunes\Feed::class,
'itunesrendererentry' => Extension\ITunes\Renderer\Entry::class,
'itunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
'iTunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
'ItunesRendererEntry' => Extension\ITunes\Renderer\Entry::class,
'ItunesRenderer\Entry' => Extension\ITunes\Renderer\Entry::class,
'itunesrendererfeed' => Extension\ITunes\Renderer\Feed::class,
'itunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
'iTunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
'ItunesRendererFeed' => Extension\ITunes\Renderer\Feed::class,
'ItunesRenderer\Feed' => Extension\ITunes\Renderer\Feed::class,
'slashrendererentry' => Extension\Slash\Renderer\Entry::class,
'slashRendererEntry' => Extension\Slash\Renderer\Entry::class,
'SlashRendererEntry' => Extension\Slash\Renderer\Entry::class,
'SlashRenderer\Entry' => Extension\Slash\Renderer\Entry::class,
'threadingrendererentry' => Extension\Threading\Renderer\Entry::class,
'threadingRendererEntry' => Extension\Threading\Renderer\Entry::class,
'ThreadingRendererEntry' => Extension\Threading\Renderer\Entry::class,
'ThreadingRenderer\Entry' => Extension\Threading\Renderer\Entry::class,
'wellformedwebrendererentry' => Extension\WellFormedWeb\Renderer\Entry::class,
'wellFormedWebRendererEntry' => Extension\WellFormedWeb\Renderer\Entry::class,
'WellFormedWebRendererEntry' => Extension\WellFormedWeb\Renderer\Entry::class,
'WellFormedWebRenderer\Entry' => Extension\WellFormedWeb\Renderer\Entry::class,
];
/**
* Factories for default set of extension classes
*
* @var array
*/
protected $factories = [
Extension\Atom\Renderer\Feed::class => InvokableFactory::class,
Extension\Content\Renderer\Entry::class => InvokableFactory::class,
Extension\DublinCore\Renderer\Entry::class => InvokableFactory::class,
Extension\DublinCore\Renderer\Feed::class => InvokableFactory::class,
Extension\ITunes\Entry::class => InvokableFactory::class,
Extension\ITunes\Feed::class => InvokableFactory::class,
Extension\ITunes\Renderer\Entry::class => InvokableFactory::class,
Extension\ITunes\Renderer\Feed::class => InvokableFactory::class,
Extension\Slash\Renderer\Entry::class => InvokableFactory::class,
Extension\Threading\Renderer\Entry::class => InvokableFactory::class,
Extension\WellFormedWeb\Renderer\Entry::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution; canonical form of resolved
// alias is used to look up the factory, while the non-normalized
// resolved alias is used as the requested name passed to the factory.
'zendfeedwriterextensionatomrendererfeed' => InvokableFactory::class,
'zendfeedwriterextensioncontentrendererentry' => InvokableFactory::class,
'zendfeedwriterextensiondublincorerendererentry' => InvokableFactory::class,
'zendfeedwriterextensiondublincorerendererfeed' => InvokableFactory::class,
'zendfeedwriterextensionitunesentry' => InvokableFactory::class,
'zendfeedwriterextensionitunesfeed' => InvokableFactory::class,
'zendfeedwriterextensionitunesrendererentry' => InvokableFactory::class,
'zendfeedwriterextensionitunesrendererfeed' => InvokableFactory::class,
'zendfeedwriterextensionslashrendererentry' => InvokableFactory::class,
'zendfeedwriterextensionthreadingrendererentry' => InvokableFactory::class,
'zendfeedwriterextensionwellformedwebrendererentry' => InvokableFactory::class,
];
/**
* Do not share instances (v2)
*
* @var bool
*/
protected $shareByDefault = false;
/**
* Do not share instances (v3)
*
* @var bool
*/
protected $sharedByDefault = false;
/**
* Validate the plugin (v3)
*
* Checks that the extension loaded is of a valid type.
*
* @param mixed $plugin
* @return void
* @throws InvalidServiceException if invalid
*/
public function validate($plugin)
{
if ($plugin instanceof Extension\AbstractRenderer) {
// we're okay
return;
}
if ('Feed' == substr(get_class($plugin), -4)) {
// we're okay
return;
}
if ('Entry' == substr(get_class($plugin), -5)) {
// we're okay
return;
}
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
. 'or the classname must end in "Feed" or "Entry"',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
/**
* Validate plugin (v2)
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException when invalid
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must implement %s\Extension\RendererInterface '
. 'or the classname must end in "Feed" or "Entry"',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
}
}