Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Bridge/ZfExtensionManagerSfContainer.php @ 0:4c8ae668cc8c
Initial import (non-working)
| author | Chris Cannam |
|---|---|
| date | Wed, 29 Nov 2017 16:09:58 +0000 |
| parents | |
| children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4c8ae668cc8c |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Drupal\Component\Bridge; | |
| 4 | |
| 5 use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
| 6 use Symfony\Component\DependencyInjection\ContainerInterface; | |
| 7 use Zend\Feed\Reader\ExtensionManagerInterface as ReaderManagerInterface; | |
| 8 use Zend\Feed\Writer\ExtensionManagerInterface as WriterManagerInterface; | |
| 9 | |
| 10 /** | |
| 11 * Defines a bridge between the ZF2 service manager to Symfony container. | |
| 12 */ | |
| 13 class ZfExtensionManagerSfContainer implements ReaderManagerInterface, WriterManagerInterface, ContainerAwareInterface { | |
| 14 | |
| 15 /** | |
| 16 * This property was based from Zend Framework (http://framework.zend.com/) | |
| 17 * | |
| 18 * @link http://github.com/zendframework/zf2 for the canonical source repository | |
| 19 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | |
| 20 * @license http://framework.zend.com/license/new-bsd New BSD License | |
| 21 * | |
| 22 * A map of characters to be replaced through strtr. | |
| 23 * | |
| 24 * @var array | |
| 25 * | |
| 26 * @see \Drupal\Component\Bridge\ZfExtensionManagerSfContainer::canonicalizeName(). | |
| 27 */ | |
| 28 protected $canonicalNamesReplacements = ['-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '']; | |
| 29 | |
| 30 /** | |
| 31 * The prefix to be used when retrieving plugins from the container. | |
| 32 * | |
| 33 * @var string | |
| 34 */ | |
| 35 protected $prefix = ''; | |
| 36 | |
| 37 /** | |
| 38 * The service container. | |
| 39 * | |
| 40 * @var \Symfony\Component\DependencyInjection\ContainerInterface | |
| 41 */ | |
| 42 protected $container; | |
| 43 | |
| 44 /** | |
| 45 * A local cache of computed canonical names. | |
| 46 * | |
| 47 * @var string[] | |
| 48 */ | |
| 49 protected $canonicalNames; | |
| 50 | |
| 51 /** | |
| 52 * Constructs a ZfExtensionManagerSfContainer object. | |
| 53 * | |
| 54 * @param string $prefix | |
| 55 * The prefix to be used when retrieving plugins from the container. | |
| 56 */ | |
| 57 public function __construct($prefix = '') { | |
| 58 $this->prefix = $prefix; | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * {@inheritdoc} | |
| 63 */ | |
| 64 public function get($extension) { | |
| 65 return $this->container->get($this->prefix . $this->canonicalizeName($extension)); | |
| 66 } | |
| 67 | |
| 68 /** | |
| 69 * {@inheritdoc} | |
| 70 */ | |
| 71 public function has($extension) { | |
| 72 return $this->container->has($this->prefix . $this->canonicalizeName($extension)); | |
| 73 } | |
| 74 | |
| 75 /** | |
| 76 * This method was based from Zend Framework (http://framework.zend.com/) | |
| 77 * | |
| 78 * @link http://github.com/zendframework/zf2 for the canonical source repository | |
| 79 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | |
| 80 * @license http://framework.zend.com/license/new-bsd New BSD License | |
| 81 * | |
| 82 * Canonicalize the extension name to a service name. | |
| 83 * | |
| 84 * @param string $name | |
| 85 * The extension name. | |
| 86 * | |
| 87 * @return string | |
| 88 * The service name, without the prefix. | |
| 89 */ | |
| 90 protected function canonicalizeName($name) { | |
| 91 if (isset($this->canonicalNames[$name])) { | |
| 92 return $this->canonicalNames[$name]; | |
| 93 } | |
| 94 // This is just for performance instead of using str_replace(). | |
| 95 return $this->canonicalNames[$name] = strtolower(strtr($name, $this->canonicalNamesReplacements)); | |
| 96 } | |
| 97 | |
| 98 /** | |
| 99 * {@inheritdoc} | |
| 100 */ | |
| 101 public function setContainer(ContainerInterface $container = NULL) { | |
| 102 $this->container = $container; | |
| 103 } | |
| 104 | |
| 105 } |
