/** * Constructor. * * @param array $configuration Dependency injection configuration. */ public function __construct(array $configuration = []) { $this->_Container = new StandardContainer($configuration); $this->_Http = $this->_Container->get('Http'); $this->_Crawler = $this->_Container->get('Crawler'); $this->_Extractor = $this->_Container->get('Extractor'); $this->_Replacer = $this->_Container->get('Replacer'); }
/** * Finds providers of the given url. * * @todo Use PHP generators to yield providers. * @param string $url An url which may be extracted. * @return array An array of Essence\Provider. */ public function providers($url) { $filters = $this->_Container->get('filters'); foreach ($filters as $name => $filter) { if ($this->_matches($filter, $url)) { (yield $this->_Container->get($name)); } } }
/** * Lazy loads a provider given its name and configuration. * * @param string $name Name. * @param string $config Configuration. * @return Provider Instance. */ protected function _provider($name, $config) { if (!isset($this->_providers[$name])) { $class = $config['class']; $Provider = $this->_Container->has($class) ? $this->_Container->get($class) : new $class(); $Provider->configure($config); $this->_providers[$name] = $Provider; } return $this->_providers[$name]; }
/** * Constructs a provider given its configuration. * * @param string $config Configuration. * @return Provider Instance. */ protected function _buildProvider($config) { $name = $config['class']; if (!$this->_Container->has($name)) { throw new Exception("The '{$name}' provider is not configured."); } $Provider = $this->_Container->get($name); $Provider->configure($config); return $Provider; }