data = $data; $this->pathPrefix = $path_prefix; } /** * @param ClassFinderAdapter $adapter */ function writeToAdapter(ClassFinderAdapter $adapter) { $data = $this->data; if (!empty($data['include-path'])) { $this->addIncludePaths((array)$data['include-path']); } if (!empty($data['autoload']['psr-0'])) { $map = $this->transformMultiple($data['autoload']['psr-0']); $adapter->addMultiplePsr0($map); } if (!empty($data['autoload']['psr-4'])) { $map = $this->transformMultiple($data['autoload']['psr-4']); $adapter->addMultiplePsr4($map); } if (!empty($data['autoload']['classmap'])) { $this->addClassmapSources($adapter, (array)$data['autoload']['classmap']); } if (!empty($data['autoload']['files'])) { foreach ($data['autoload']['files'] as $file) { require $this->pathPrefix . $file; } } } /** * @param array $multiple * * @return array[] */ protected function transformMultiple(array $multiple) { foreach ($multiple as &$paths) { $paths = (array)$paths; foreach ($paths as &$path) { if ('' === $path || '/' !== $path[0]) { $path = $this->pathPrefix . $path; } } } return $multiple; } /** * @param string[] $include_paths */ protected function addIncludePaths(array $include_paths) { foreach ($include_paths as &$path) { $path = $this->pathPrefix . $path; } array_push($include_paths, get_include_path()); set_include_path(join(PATH_SEPARATOR, $include_paths)); } /** * @param ClassFinderAdapter $adapter * @param string[] $sources_raw * Array of files and folders to scan for class implementations. */ protected function addClassmapSources($adapter, array $sources_raw) { foreach ($sources_raw as &$path) { $path = $this->pathPrefix . $path; } $adapter->addClassmapSources($sources_raw); } }