aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/simplepie/simplepie/src/Registry.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/simplepie/simplepie/src/Registry.php')
-rw-r--r--vendor/simplepie/simplepie/src/Registry.php144
1 files changed, 99 insertions, 45 deletions
diff --git a/vendor/simplepie/simplepie/src/Registry.php b/vendor/simplepie/simplepie/src/Registry.php
index 1db2a619e..8e2ea13e3 100644
--- a/vendor/simplepie/simplepie/src/Registry.php
+++ b/vendor/simplepie/simplepie/src/Registry.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SimplePie
*
@@ -43,6 +45,10 @@
namespace SimplePie;
+use SimplePie\Content\Type\Sniffer;
+use SimplePie\Parse\Date;
+use SimplePie\XML\Declaration\Parser as DeclarationParser;
+
/**
* Handles creating objects and calling methods
*
@@ -57,9 +63,53 @@ class Registry
*
* Overriding classes *must* subclass these.
*
- * @var array
+ * @var array<class-string, class-string>
*/
protected $default = [
+ Cache::class => Cache::class,
+ Locator::class => Locator::class,
+ Parser::class => Parser::class,
+ File::class => File::class,
+ Sanitize::class => Sanitize::class,
+ Item::class => Item::class,
+ Author::class => Author::class,
+ Category::class => Category::class,
+ Enclosure::class => Enclosure::class,
+ Caption::class => Caption::class,
+ Copyright::class => Copyright::class,
+ Credit::class => Credit::class,
+ Rating::class => Rating::class,
+ Restriction::class => Restriction::class,
+ Sniffer::class => Sniffer::class,
+ Source::class => Source::class,
+ Misc::class => Misc::class,
+ DeclarationParser::class => DeclarationParser::class,
+ Date::class => Date::class,
+ ];
+
+ /**
+ * Class mapping
+ *
+ * @see register()
+ * @var array
+ */
+ protected $classes = [];
+
+ /**
+ * Legacy classes
+ *
+ * @see register()
+ * @var array<class-string>
+ */
+ protected $legacy = [];
+
+ /**
+ * Legacy types
+ *
+ * @see register()
+ * @var array<string, class-string>
+ */
+ private $legacyTypes = [
'Cache' => Cache::class,
'Locator' => Locator::class,
'Parser' => Parser::class,
@@ -74,30 +124,14 @@ class Registry
'Credit' => Credit::class,
'Rating' => Rating::class,
'Restriction' => Restriction::class,
- 'Content_Type_Sniffer' => Content\Type\Sniffer::class,
+ 'Content_Type_Sniffer' => Sniffer::class,
'Source' => Source::class,
'Misc' => Misc::class,
- 'XML_Declaration_Parser' => XML\Declaration\Parser::class,
- 'Parse_Date' => Parse\Date::class,
+ 'XML_Declaration_Parser' => DeclarationParser::class,
+ 'Parse_Date' => Date::class,
];
/**
- * Class mapping
- *
- * @see register()
- * @var array
- */
- protected $classes = [];
-
- /**
- * Legacy classes
- *
- * @see register()
- * @var array
- */
- protected $legacy = [];
-
- /**
* Constructor
*
* No-op
@@ -110,13 +144,30 @@ class Registry
* Register a class
*
* @param string $type See {@see $default} for names
- * @param string $class Class name, must subclass the corresponding default
+ * @param class-string $class Class name, must subclass the corresponding default
* @param bool $legacy Whether to enable legacy support for this class
* @return bool Successfulness
*/
public function register($type, $class, $legacy = false)
{
- if (!@is_subclass_of($class, $this->default[$type])) {
+ if (array_key_exists($type, $this->legacyTypes)) {
+ // trigger_error(sprintf('"%s"(): Using argument #1 ($type) with value "%s" is deprecated since SimplePie 1.8.0, use class-string "%s" instead.', __METHOD__, $type, $this->legacyTypes[$type]), \E_USER_DEPRECATED);
+
+ $type = $this->legacyTypes[$type];
+ }
+
+ if (! array_key_exists($type, $this->default)) {
+ return false;
+ }
+
+ if (!class_exists($class)) {
+ return false;
+ }
+
+ /** @var string */
+ $base_class = $this->default[$type];
+
+ if (!is_subclass_of($class, $base_class)) {
return false;
}
@@ -134,43 +185,43 @@ class Registry
*
* Where possible, use {@see create()} or {@see call()} instead
*
- * @param string $type
- * @return string|null
+ * @template T
+ * @param class-string<T> $type
+ * @return class-string<T>|null
*/
public function get_class($type)
{
- if (!empty($this->classes[$type])) {
- return $this->classes[$type];
+ if (array_key_exists($type, $this->legacyTypes)) {
+ // trigger_error(sprintf('"%s"(): Using argument #1 ($type) with value "%s" is deprecated since SimplePie 1.8.0, use class-string "%s" instead.', __METHOD__, $type, $this->legacyTypes[$type]), \E_USER_DEPRECATED);
+
+ $type = $this->legacyTypes[$type];
}
- if (!empty($this->default[$type])) {
- return $this->default[$type];
+
+ if (! array_key_exists($type, $this->default)) {
+ return null;
+ }
+
+ $class = $this->default[$type];
+
+ if (array_key_exists($type, $this->classes)) {
+ $class = $this->classes[$type];
}
- return null;
+ return $class;
}
/**
* Create a new instance of a given type
*
- * @param string $type
+ * @template T class-string $type
+ * @param class-string<T> $type
* @param array $parameters Parameters to pass to the constructor
- * @return object Instance of class
+ * @return T Instance of class
*/
public function &create($type, $parameters = [])
{
$class = $this->get_class($type);
- if (in_array($class, $this->legacy)) {
- switch ($type) {
- case 'locator':
- // Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
- // Specified: file, timeout, useragent, max_checked_feeds
- $replacement = [$this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer')];
- array_splice($parameters, 3, 1, $replacement);
- break;
- }
- }
-
if (!method_exists($class, '__construct')) {
$instance = new $class();
} else {
@@ -178,7 +229,10 @@ class Registry
$instance = $reflector->newInstanceArgs($parameters);
}
- if (method_exists($instance, 'set_registry')) {
+ if ($instance instanceof RegistryAware) {
+ $instance->set_registry($this);
+ } elseif (method_exists($instance, 'set_registry')) {
+ trigger_error(sprintf('Using the method "set_registry()" without implementing "%s" is deprecated since SimplePie 1.8.0, implement "%s" in "%s".', RegistryAware::class, RegistryAware::class, $class), \E_USER_DEPRECATED);
$instance->set_registry($this);
}
return $instance;
@@ -187,7 +241,7 @@ class Registry
/**
* Call a static method for a type
*
- * @param string $type
+ * @param class-string $type
* @param string $method
* @param array $parameters
* @return mixed
@@ -198,7 +252,7 @@ class Registry
if (in_array($class, $this->legacy)) {
switch ($type) {
- case 'Cache':
+ case Cache::class:
// For backwards compatibility with old non-static
// Cache::create() methods in PHP < 8.0.
// No longer supported as of PHP 8.0.