5
* A PHP-Based RSS and Atom Feed Framework.
6
* Takes the hard work out of managing a complete RSS/Atom solution.
8
* Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
11
* Redistribution and use in source and binary forms, with or without modification, are
12
* permitted provided that the following conditions are met:
14
* * Redistributions of source code must retain the above copyright notice, this list of
15
* conditions and the following disclaimer.
17
* * Redistributions in binary form must reproduce the above copyright notice, this list
18
* of conditions and the following disclaimer in the documentation and/or other materials
19
* provided with the distribution.
21
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
22
* to endorse or promote products derived from this software without specific prior
25
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
26
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
28
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
* POSSIBILITY OF SUCH DAMAGE.
37
* @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
39
* @author Geoffrey Sneddon
41
* @link http://simplepie.org/ SimplePie
42
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
46
* Handles creating objects and calling methods
48
* Access this via {@see SimplePie::get_registry()}
52
class SimplePie_Registry
55
* Default class mapping
57
* Overriding classes *must* subclass these.
61
protected $default = array(
62
'Cache' => 'SimplePie_Cache',
63
'Locator' => 'SimplePie_Locator',
64
'Parser' => 'SimplePie_Parser',
65
'File' => 'SimplePie_File',
66
'Sanitize' => 'SimplePie_Sanitize',
67
'Item' => 'SimplePie_Item',
68
'Author' => 'SimplePie_Author',
69
'Category' => 'SimplePie_Category',
70
'Enclosure' => 'SimplePie_Enclosure',
71
'Caption' => 'SimplePie_Caption',
72
'Copyright' => 'SimplePie_Copyright',
73
'Credit' => 'SimplePie_Credit',
74
'Rating' => 'SimplePie_Rating',
75
'Restriction' => 'SimplePie_Restriction',
76
'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
77
'Source' => 'SimplePie_Source',
78
'Misc' => 'SimplePie_Misc',
79
'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
80
'Parse_Date' => 'SimplePie_Parse_Date',
89
protected $classes = array();
97
protected $legacy = array();
104
public function __construct() { }
109
* @param string $type See {@see $default} for names
110
* @param string $class Class name, must subclass the corresponding default
111
* @param bool $legacy Whether to enable legacy support for this class
112
* @return bool Successfulness
114
public function register($type, $class, $legacy = false)
116
if (!is_subclass_of($class, $this->default[$type]))
121
$this->classes[$type] = $class;
125
$this->legacy[] = $class;
132
* Get the class registered for a type
134
* Where possible, use {@see create()} or {@see call()} instead
136
* @param string $type
137
* @return string|null
139
public function get_class($type)
141
if (!empty($this->classes[$type]))
143
return $this->classes[$type];
145
if (!empty($this->default[$type]))
147
return $this->default[$type];
154
* Create a new instance of a given type
156
* @param string $type
157
* @param array $parameters Parameters to pass to the constructor
158
* @return object Instance of class
160
public function &create($type, $parameters = array())
162
$class = $this->get_class($type);
164
if (in_array($class, $this->legacy))
169
// Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
170
// Specified: file, timeout, useragent, max_checked_feeds
171
$replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
172
array_splice($parameters, 3, 1, $replacement);
177
if (!method_exists($class, '__construct'))
179
$instance = new $class;
183
$reflector = new ReflectionClass($class);
184
$instance = $reflector->newInstanceArgs($parameters);
187
if (method_exists($instance, 'set_registry'))
189
$instance->set_registry($this);
195
* Call a static method for a type
197
* @param string $type
198
* @param string $method
199
* @param array $parameters
202
public function &call($type, $method, $parameters = array())
204
$class = $this->get_class($type);
206
if (in_array($class, $this->legacy))
211
// For backwards compatibility with old non-static
212
// Cache::create() methods
213
if ($method === 'get_handler')
215
$result = @call_user_func_array(array($class, 'create'), $parameters);
222
$result = call_user_func_array(array($class, $method), $parameters);
b'\\ No newline at end of file'