diff vendor/zendframework/zend-feed/src/Reader/Reader.php @ 2:5311817fb629

Theme updates
author Chris Cannam
date Tue, 10 Jul 2018 13:19:18 +0000
parents c75dbcec494b
children a9cd425dd02b
line wrap: on
line diff
--- a/vendor/zendframework/zend-feed/src/Reader/Reader.php	Thu Jul 05 15:32:06 2018 +0100
+++ b/vendor/zendframework/zend-feed/src/Reader/Reader.php	Tue Jul 10 13:19:18 2018 +0000
@@ -12,9 +12,9 @@
 use DOMDocument;
 use DOMXPath;
 use Zend\Cache\Storage\StorageInterface as CacheStorage;
+use Zend\Feed\Reader\Exception\InvalidHttpClientException;
 use Zend\Http as ZendHttp;
 use Zend\Stdlib\ErrorHandler;
-use Zend\Feed\Reader\Exception\InvalidHttpClientException;
 
 /**
 */
@@ -222,7 +222,9 @@
             }
             $response = $client->get($uri, $headers);
             if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 304) {
-                throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
+                throw new Exception\RuntimeException(
+                    'Feed failed to load, got response code ' . $response->getStatusCode()
+                );
             }
             if ($response->getStatusCode() == 304) {
                 $responseXml = $data;
@@ -247,7 +249,9 @@
             }
             $response = $client->get($uri);
             if ((int) $response->getStatusCode() !== 200) {
-                throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
+                throw new Exception\RuntimeException(
+                    'Feed failed to load, got response code ' . $response->getStatusCode()
+                );
             }
             $responseXml = $response->getBody();
             $cache->setItem($cacheId, $responseXml);
@@ -255,7 +259,9 @@
         } else {
             $response = $client->get($uri);
             if ((int) $response->getStatusCode() !== 200) {
-                throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
+                throw new Exception\RuntimeException(
+                    'Feed failed to load, got response code ' . $response->getStatusCode()
+                );
             }
             $reader = static::importString($response->getBody());
             $reader->setOriginalSourceUri($uri);
@@ -289,7 +295,9 @@
         }
 
         if ((int) $response->getStatusCode() !== 200) {
-            throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
+            throw new Exception\RuntimeException(
+                'Feed failed to load, got response code ' . $response->getStatusCode()
+            );
         }
         $reader = static::importString($response->getBody());
         $reader->setOriginalSourceUri($uri);
@@ -307,7 +315,7 @@
     public static function importString($string)
     {
         $trimmed = trim($string);
-        if (!is_string($string) || empty($trimmed)) {
+        if (! is_string($string) || empty($trimmed)) {
             throw new Exception\InvalidArgumentException('Only non empty strings are allowed as input');
         }
 
@@ -325,7 +333,7 @@
         libxml_disable_entity_loader($oldValue);
         libxml_use_internal_errors($libxmlErrflag);
 
-        if (!$status) {
+        if (! $status) {
             // Build error message
             $error = libxml_get_last_error();
             if ($error && $error->message) {
@@ -384,7 +392,9 @@
         $client   = static::getHttpClient();
         $response = $client->get($uri);
         if ($response->getStatusCode() !== 200) {
-            throw new Exception\RuntimeException("Failed to access $uri, got response code " . $response->getStatusCode());
+            throw new Exception\RuntimeException(
+                "Failed to access $uri, got response code " . $response->getStatusCode()
+            );
         }
         $responseHtml = $response->getBody();
         $libxmlErrflag = libxml_use_internal_errors(true);
@@ -393,7 +403,7 @@
         $status = $dom->loadHTML(trim($responseHtml));
         libxml_disable_entity_loader($oldValue);
         libxml_use_internal_errors($libxmlErrflag);
-        if (!$status) {
+        if (! $status) {
             // Build error message
             $error = libxml_get_last_error();
             if ($error && $error->message) {
@@ -425,8 +435,8 @@
             $dom = $feed->getDomDocument();
         } elseif ($feed instanceof DOMDocument) {
             $dom = $feed;
-        } elseif (is_string($feed) && !empty($feed)) {
-            ErrorHandler::start(E_NOTICE|E_WARNING);
+        } elseif (is_string($feed) && ! empty($feed)) {
+            ErrorHandler::start(E_NOTICE | E_WARNING);
             ini_set('track_errors', 1);
             $oldValue = libxml_disable_entity_loader(true);
             $dom = new DOMDocument;
@@ -441,8 +451,8 @@
             libxml_disable_entity_loader($oldValue);
             ini_restore('track_errors');
             ErrorHandler::stop();
-            if (!$status) {
-                if (!isset($phpErrormsg)) {
+            if (! $status) {
+                if (! isset($phpErrormsg)) {
                     if (function_exists('xdebug_is_enabled')) {
                         $phpErrormsg = '(error message not available, when XDebug is running)';
                     } else {
@@ -552,7 +562,7 @@
      */
     public static function getExtensionManager()
     {
-        if (!isset(static::$extensionManager)) {
+        if (! isset(static::$extensionManager)) {
             static::setExtensionManager(new StandaloneExtensionManager());
         }
         return static::$extensionManager;
@@ -567,22 +577,27 @@
      */
     public static function registerExtension($name)
     {
-        $feedName  = $name . '\Feed';
-        $entryName = $name . '\Entry';
-        $manager   = static::getExtensionManager();
-        if (static::isRegistered($name)) {
-            if ($manager->has($feedName) || $manager->has($entryName)) {
-                return;
-            }
+        if (! static::hasExtension($name)) {
+            throw new Exception\RuntimeException(sprintf(
+                'Could not load extension "%s" using Plugin Loader.'
+                . ' Check prefix paths are configured and extension exists.',
+                $name
+            ));
         }
 
-        if (!$manager->has($feedName) && !$manager->has($entryName)) {
-            throw new Exception\RuntimeException('Could not load extension: ' . $name
-                . ' using Plugin Loader. Check prefix paths are configured and extension exists.');
+        // Return early if already registered.
+        if (static::isRegistered($name)) {
+            return;
         }
+
+        $manager   = static::getExtensionManager();
+
+        $feedName = $name . '\Feed';
         if ($manager->has($feedName)) {
             static::$extensions['feed'][] = $feedName;
         }
+
+        $entryName = $name . '\Entry';
         if ($manager->has($entryName)) {
             static::$extensions['entry'][] = $entryName;
         }
@@ -662,6 +677,18 @@
         static::registerExtension('WellFormedWeb');
         static::registerExtension('Thread');
         static::registerExtension('Podcast');
+
+        // Added in 2.10.0; check for it conditionally
+        static::hasExtension('GooglePlayPodcast')
+            ? static::registerExtension('GooglePlayPodcast')
+            : trigger_error(
+                sprintf(
+                    'Please update your %1$s\ExtensionManagerInterface implementation to add entries for'
+                    . ' %1$s\Extension\GooglePlayPodcast\Entry and %1$s\Extension\GooglePlayPodcast\Feed.',
+                    __NAMESPACE__
+                ),
+                \E_USER_NOTICE
+            );
     }
 
     /**
@@ -682,4 +709,28 @@
         }
         return $array;
     }
+
+    /**
+     * Does the extension manager have the named extension?
+     *
+     * This method exists to allow us to test if an extension is present in the
+     * extension manager. It may be used by registerExtension() to determine if
+     * the extension has items present in the manager, or by
+     * registerCoreExtension() to determine if the core extension has entries
+     * in the extension manager. In the latter case, this can be useful when
+     * adding new extensions in a minor release, as custom extension manager
+     * implementations may not yet have an entry for the extension, which would
+     * then otherwise cause registerExtension() to fail.
+     *
+     * @param string $name
+     * @return bool
+     */
+    protected static function hasExtension($name)
+    {
+        $feedName  = $name . '\Feed';
+        $entryName = $name . '\Entry';
+        $manager   = static::getExtensionManager();
+
+        return $manager->has($feedName) || $manager->has($entryName);
+    }
 }