comparison core/lib/Drupal/Component/Bridge/ZfExtensionManagerSfContainer.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
2 2
3 namespace Drupal\Component\Bridge; 3 namespace Drupal\Component\Bridge;
4 4
5 use Symfony\Component\DependencyInjection\ContainerAwareInterface; 5 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface; 6 use Symfony\Component\DependencyInjection\ContainerInterface;
7 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
7 use Zend\Feed\Reader\ExtensionManagerInterface as ReaderManagerInterface; 8 use Zend\Feed\Reader\ExtensionManagerInterface as ReaderManagerInterface;
8 use Zend\Feed\Writer\ExtensionManagerInterface as WriterManagerInterface; 9 use Zend\Feed\Writer\ExtensionManagerInterface as WriterManagerInterface;
9 10
10 /** 11 /**
11 * Defines a bridge between the ZF2 service manager to Symfony container. 12 * Defines a bridge between the ZF2 service manager to Symfony container.
47 * @var string[] 48 * @var string[]
48 */ 49 */
49 protected $canonicalNames; 50 protected $canonicalNames;
50 51
51 /** 52 /**
53 * @var \Zend\Feed\Reader\ExtensionManagerInterface|\Zend\Feed\Writer\ExtensionManagerInterface
54 */
55 protected $standalone;
56
57 /**
52 * Constructs a ZfExtensionManagerSfContainer object. 58 * Constructs a ZfExtensionManagerSfContainer object.
53 * 59 *
54 * @param string $prefix 60 * @param string $prefix
55 * The prefix to be used when retrieving plugins from the container. 61 * The prefix to be used when retrieving plugins from the container.
56 */ 62 */
60 66
61 /** 67 /**
62 * {@inheritdoc} 68 * {@inheritdoc}
63 */ 69 */
64 public function get($extension) { 70 public function get($extension) {
65 return $this->container->get($this->prefix . $this->canonicalizeName($extension)); 71 try {
72 return $this->container->get($this->prefix . $this->canonicalizeName($extension));
73 }
74 catch (ServiceNotFoundException $e) {
75 if ($this->standalone && $this->standalone->has($extension)) {
76 return $this->standalone->get($extension);
77 }
78 throw $e;
79 }
66 } 80 }
67 81
68 /** 82 /**
69 * {@inheritdoc} 83 * {@inheritdoc}
70 */ 84 */
71 public function has($extension) { 85 public function has($extension) {
72 return $this->container->has($this->prefix . $this->canonicalizeName($extension)); 86 if ($this->container->has($this->prefix . $this->canonicalizeName($extension))) {
87 return TRUE;
88 }
89 return $this->standalone && $this->standalone->has($extension);
73 } 90 }
74 91
75 /** 92 /**
76 * This method was based from Zend Framework (http://framework.zend.com/) 93 * This method was based from Zend Framework (http://framework.zend.com/)
77 * 94 *
100 */ 117 */
101 public function setContainer(ContainerInterface $container = NULL) { 118 public function setContainer(ContainerInterface $container = NULL) {
102 $this->container = $container; 119 $this->container = $container;
103 } 120 }
104 121
122 /**
123 * @param $class
124 */
125 public function setStandalone($class) {
126 if (!is_subclass_of($class, ReaderManagerInterface::class) && !is_subclass_of($class, WriterManagerInterface::class)) {
127 throw new \RuntimeException("$class must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface");
128 }
129 $this->standalone = new $class();
130 }
131
105 } 132 }