library/SimplePie/Registry.php Quellcode

Registry.php
gehe zur Dokumentation dieser Datei
1 <?php
53 {
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',
81  );
82 
89  protected $classes = array();
90 
97  protected $legacy = array();
98 
104  public function __construct() { }
105 
114  public function register($type, $class, $legacy = false)
115  {
116  if (!is_subclass_of($class, $this->default[$type]))
117  {
118  return false;
119  }
120 
121  $this->classes[$type] = $class;
122 
123  if ($legacy)
124  {
125  $this->legacy[] = $class;
126  }
127 
128  return true;
129  }
130 
139  public function get_class($type)
140  {
141  if (!empty($this->classes[$type]))
142  {
143  return $this->classes[$type];
144  }
145  if (!empty($this->default[$type]))
146  {
147  return $this->default[$type];
148  }
149 
150  return null;
151  }
152 
160  public function &create($type, $parameters = array())
161  {
162  $class = $this->get_class($type);
163 
164  if (in_array($class, $this->legacy))
165  {
166  switch ($type)
167  {
168  case 'locator':
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);
173  break;
174  }
175  }
176 
177  if (!method_exists($class, '__construct'))
178  {
179  $instance = new $class;
180  }
181  else
182  {
183  $reflector = new ReflectionClass($class);
184  $instance = $reflector->newInstanceArgs($parameters);
185  }
186 
187  if (method_exists($instance, 'set_registry'))
188  {
189  $instance->set_registry($this);
190  }
191  return $instance;
192  }
193 
202  public function &call($type, $method, $parameters = array())
203  {
204  $class = $this->get_class($type);
205 
206  if (in_array($class, $this->legacy))
207  {
208  switch ($type)
209  {
210  case 'Cache':
211  // For backwards compatibility with old non-static
212  // Cache::create() methods
213  if ($method === 'get_handler')
214  {
215  $result = @call_user_func_array(array($class, 'create'), $parameters);
216  return $result;
217  }
218  break;
219  }
220  }
221 
222  $result = call_user_func_array(array($class, $method), $parameters);
223  return $result;
224  }
225 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.