/** * @return \PhpToZephir\Converter\Dispatcher */ private static function createInstance() { $dirName = __DIR__ . '/Printer/'; $directory = new \RecursiveDirectoryIterator($dirName); $iterator = new \RecursiveIteratorIterator($directory); $regex = new \RegexIterator($iterator, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH); $classes = new PrinterCollection(array()); include 'SimplePrinter.php'; foreach ($regex as $fileInfo) { $declaredClasses = get_declared_classes(); include $fileInfo[0]; $className = current(array_diff(get_declared_classes(), $declaredClasses)); $classes->offsetSet($className::getType(), $className); } return new Dispatcher($classes, include __DIR__ . '/PrecedenceMap.php'); }
/** * @param string $type * * @throws \Exception * * @return object */ private function getClass($type) { if (isset($this->classes[$type]) === false) { if ($this->printerCollection->offsetExists($type) === false) { throw new \Exception(sprintf('Printer "%s" does not exist', $type)); } $className = $this->printerCollection->offsetGet($type); $this->classes[$type] = $this->dynamicConstruct($className); } return $this->classes[$type]; }