/** * Returns a package instance. * * @param string $packagesBasePath the base install path of packages, * @param string $packagePath path to package, relative to base path * @param string $packageKey key / name of the package * @param string $classesPath path to the classes directory, relative to the package path * @param string $manifestPath path to the package's Composer manifest, relative to package path, defaults to same path * @return \TYPO3\Flow\Package\PackageInterface * @throws Exception\CorruptPackageException */ public function create($packagesBasePath, $packagePath, $packageKey, $classesPath = null, $manifestPath = null) { $absolutePackagePath = Files::concatenatePaths(array($packagesBasePath, $packagePath)) . '/'; $absoluteManifestPath = $manifestPath === null ? $absolutePackagePath : Files::concatenatePaths(array($absolutePackagePath, $manifestPath)) . '/'; $autoLoadDirectives = array(); try { $autoLoadDirectives = (array) PackageManager::getComposerManifest($absoluteManifestPath, 'autoload'); } catch (MissingPackageManifestException $exception) { } if (isset($autoLoadDirectives[Package::AUTOLOADER_TYPE_PSR4])) { $packageClassPathAndFilename = Files::concatenatePaths(array($absolutePackagePath, 'Classes', 'Package.php')); } else { $packageClassPathAndFilename = Files::concatenatePaths(array($absolutePackagePath, 'Classes', str_replace('.', '/', $packageKey), 'Package.php')); } $package = null; if (file_exists($packageClassPathAndFilename)) { require_once $packageClassPathAndFilename; $packageClassContents = file_get_contents($packageClassPathAndFilename); $packageClassName = (new PhpAnalyzer($packageClassContents))->extractFullyQualifiedClassName(); if ($packageClassName === null) { throw new Exception\CorruptPackageException(sprintf('The package "%s" does not contain a valid package class. Check if the file "%s" really contains a class.', $packageKey, $packageClassPathAndFilename), 1327587091); } $package = new $packageClassName($this->packageManager, $packageKey, $absolutePackagePath, $classesPath, $manifestPath); if (!$package instanceof PackageInterface) { throw new Exception\CorruptPackageException(sprintf('The package class of package "%s" does not implement \\TYPO3\\Flow\\Package\\PackageInterface. Check the file "%s".', $packageKey, $packageClassPathAndFilename), 1427193370); } return $package; } return new Package($this->packageManager, $packageKey, $absolutePackagePath, $classesPath, $manifestPath); }
/** * Returns contents of Composer manifest - or part there of. * * @param string $key Optional. Only return the part of the manifest indexed by 'key' * @return mixed|NULL * @see json_decode for return values */ public function getComposerManifest($key = null) { if (!isset($this->composerManifest)) { $this->composerManifest = PackageManager::getComposerManifest($this->getManifestPath()); } return PackageManager::getComposerManifest($this->getManifestPath(), $key, $this->composerManifest); }