3 namespace Drupal\Component\Bridge;
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;
11 * Defines a bridge between the ZF2 service manager to Symfony container.
13 class ZfExtensionManagerSfContainer implements ReaderManagerInterface, WriterManagerInterface, ContainerAwareInterface {
16 * This property was based from Zend Framework (http://framework.zend.com/)
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
22 * A map of characters to be replaced through strtr.
26 * @see \Drupal\Component\Bridge\ZfExtensionManagerSfContainer::canonicalizeName().
28 protected $canonicalNamesReplacements = ['-' => '', '_' => '', ' ' => '', '\\' => '', '/' => ''];
31 * The prefix to be used when retrieving plugins from the container.
35 protected $prefix = '';
38 * The service container.
40 * @var \Symfony\Component\DependencyInjection\ContainerInterface
45 * A local cache of computed canonical names.
49 protected $canonicalNames;
52 * Constructs a ZfExtensionManagerSfContainer object.
54 * @param string $prefix
55 * The prefix to be used when retrieving plugins from the container.
57 public function __construct($prefix = '') {
58 $this->prefix = $prefix;
64 public function get($extension) {
65 return $this->container->get($this->prefix . $this->canonicalizeName($extension));
71 public function has($extension) {
72 return $this->container->has($this->prefix . $this->canonicalizeName($extension));
76 * This method was based from Zend Framework (http://framework.zend.com/)
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
82 * Canonicalize the extension name to a service name.
88 * The service name, without the prefix.
90 protected function canonicalizeName($name) {
91 if (isset($this->canonicalNames[$name])) {
92 return $this->canonicalNames[$name];
94 // This is just for performance instead of using str_replace().
95 return $this->canonicalNames[$name] = strtolower(strtr($name, $this->canonicalNamesReplacements));
101 public function setContainer(ContainerInterface $container = NULL) {
102 $this->container = $container;