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