/** * @param string $xmlFile * @return Project */ public function map($xmlFile) { $content = $this->loadXmlFile($xmlFile); $project = new Project(realpath(dirname($xmlFile))); $project->setSources($this->mapSources(isset($content['sources']) ? $content['sources'] : [])); return $project; }
/** * @param SourceCollection $sources * @return array */ private function generateAutoloaders(SourceCollection $sources) { $autoloaders = []; foreach ($sources as $source) { $composerAutoloadConfig = $this->loadComposerAutoloadConfig($this->project->getDir() . DIRECTORY_SEPARATOR . $source->getPath() . DIRECTORY_SEPARATOR . 'composer.json'); if (is_array($composerAutoloadConfig)) { foreach ($composerAutoloadConfig as $type => $autoloader) { if ($type === 'psr-4') { if (is_array($autoloader)) { foreach ($autoloader as &$paths) { if (!is_array($paths)) { $paths = [$paths]; } $sharedPaths = []; foreach ($paths as &$path) { $sharedPaths[] = '/../shared' . DIRECTORY_SEPARATOR . basename($source->getPath()) . DIRECTORY_SEPARATOR . trim($path, '\\/' . DIRECTORY_SEPARATOR); $path = DIRECTORY_SEPARATOR . trim($source->getPath(), '\\/' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $path; } $paths = array_merge($paths, $sharedPaths); } } else { $autoloader = []; } if (isset($autoloaders['psr-4'])) { $autoloaders['psr-4'] = array_merge($autoloaders['psr-4'], $autoloader); } else { $autoloaders['psr-4'] = $autoloader; } } } } } $retval = []; foreach ($autoloaders as $type => $autoloader) { if ($type === 'psr-4') { $retval['psr-4'] = $this->generatePsr4Autoloaders($autoloader); } } return $retval; }
/** * @return string */ private function getProjectAutoloaderDir() { return $this->project->getDir() . DIRECTORY_SEPARATOR . 'vendor/composer/project'; }