Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Component / Bridge / ZfExtensionManagerSfContainer.php
index c6579465eeef008231dfe2aa09af64450362b8ae..59ae9f56464b6d01bd07219967888b793f82ad7d 100644 (file)
@@ -4,6 +4,7 @@ namespace Drupal\Component\Bridge;
 
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
 use Zend\Feed\Reader\ExtensionManagerInterface as ReaderManagerInterface;
 use Zend\Feed\Writer\ExtensionManagerInterface as WriterManagerInterface;
 
@@ -48,6 +49,11 @@ class ZfExtensionManagerSfContainer implements ReaderManagerInterface, WriterMan
    */
   protected $canonicalNames;
 
+  /**
+   * @var \Zend\Feed\Reader\ExtensionManagerInterface|\Zend\Feed\Writer\ExtensionManagerInterface
+   */
+  protected $standalone;
+
   /**
    * Constructs a ZfExtensionManagerSfContainer object.
    *
@@ -62,14 +68,25 @@ class ZfExtensionManagerSfContainer implements ReaderManagerInterface, WriterMan
    * {@inheritdoc}
    */
   public function get($extension) {
-    return $this->container->get($this->prefix . $this->canonicalizeName($extension));
+    try {
+      return $this->container->get($this->prefix . $this->canonicalizeName($extension));
+    }
+    catch (ServiceNotFoundException $e) {
+      if ($this->standalone && $this->standalone->has($extension)) {
+        return $this->standalone->get($extension);
+      }
+      throw $e;
+    }
   }
 
   /**
    * {@inheritdoc}
    */
   public function has($extension) {
-    return $this->container->has($this->prefix . $this->canonicalizeName($extension));
+    if ($this->container->has($this->prefix . $this->canonicalizeName($extension))) {
+      return TRUE;
+    }
+    return $this->standalone && $this->standalone->has($extension);
   }
 
   /**
@@ -102,4 +119,14 @@ class ZfExtensionManagerSfContainer implements ReaderManagerInterface, WriterMan
     $this->container = $container;
   }
 
+  /**
+   * @param $class
+   */
+  public function setStandalone($class) {
+    if (!is_subclass_of($class, ReaderManagerInterface::class) && !is_subclass_of($class, WriterManagerInterface::class)) {
+      throw new \RuntimeException("$class must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface");
+    }
+    $this->standalone = new $class();
+  }
+
 }