Chris@0: '', '_' => '', ' ' => '', '\\' => '', '/' => '']; Chris@0: Chris@0: /** Chris@0: * The prefix to be used when retrieving plugins from the container. Chris@0: * Chris@0: * @var string Chris@0: */ Chris@0: protected $prefix = ''; Chris@0: Chris@0: /** Chris@0: * The service container. Chris@0: * Chris@0: * @var \Symfony\Component\DependencyInjection\ContainerInterface Chris@0: */ Chris@0: protected $container; Chris@0: Chris@0: /** Chris@0: * A local cache of computed canonical names. Chris@0: * Chris@0: * @var string[] Chris@0: */ Chris@0: protected $canonicalNames; Chris@0: Chris@0: /** Chris@17: * @var \Zend\Feed\Reader\ExtensionManagerInterface|\Zend\Feed\Writer\ExtensionManagerInterface Chris@17: */ Chris@17: protected $standalone; Chris@17: Chris@17: /** Chris@0: * Constructs a ZfExtensionManagerSfContainer object. Chris@0: * Chris@0: * @param string $prefix Chris@0: * The prefix to be used when retrieving plugins from the container. Chris@0: */ Chris@0: public function __construct($prefix = '') { Chris@0: $this->prefix = $prefix; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function get($extension) { Chris@17: try { Chris@17: return $this->container->get($this->prefix . $this->canonicalizeName($extension)); Chris@17: } Chris@17: catch (ServiceNotFoundException $e) { Chris@17: if ($this->standalone && $this->standalone->has($extension)) { Chris@17: return $this->standalone->get($extension); Chris@17: } Chris@17: throw $e; Chris@17: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function has($extension) { Chris@17: if ($this->container->has($this->prefix . $this->canonicalizeName($extension))) { Chris@17: return TRUE; Chris@17: } Chris@17: return $this->standalone && $this->standalone->has($extension); Chris@0: } Chris@0: Chris@0: /** Chris@0: * This method was based from Zend Framework (http://framework.zend.com/) Chris@0: * Chris@0: * @link http://github.com/zendframework/zf2 for the canonical source repository Chris@0: * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) Chris@0: * @license http://framework.zend.com/license/new-bsd New BSD License Chris@0: * Chris@0: * Canonicalize the extension name to a service name. Chris@0: * Chris@0: * @param string $name Chris@0: * The extension name. Chris@0: * Chris@0: * @return string Chris@0: * The service name, without the prefix. Chris@0: */ Chris@0: protected function canonicalizeName($name) { Chris@0: if (isset($this->canonicalNames[$name])) { Chris@0: return $this->canonicalNames[$name]; Chris@0: } Chris@0: // This is just for performance instead of using str_replace(). Chris@0: return $this->canonicalNames[$name] = strtolower(strtr($name, $this->canonicalNamesReplacements)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setContainer(ContainerInterface $container = NULL) { Chris@0: $this->container = $container; Chris@0: } Chris@0: Chris@17: /** Chris@17: * @param $class Chris@17: */ Chris@17: public function setStandalone($class) { Chris@17: if (!is_subclass_of($class, ReaderManagerInterface::class) && !is_subclass_of($class, WriterManagerInterface::class)) { Chris@17: throw new \RuntimeException("$class must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface"); Chris@17: } Chris@17: $this->standalone = new $class(); Chris@17: } Chris@17: Chris@0: }