/** * @test */ public function createReturnsAnInstanceOfTheDefaultPackageIfNoCustomPackageExists() { $packagePath = 'vfs://Packages/Some/Path/Some.Package/'; mkdir($packagePath, 0777, TRUE); file_put_contents($packagePath . 'composer.json', '{"name": "some/package", "type": "flow-test"}'); $package = $this->packageFactory->create('vfs://Packages/', 'Some/Path/Some.Package/', 'Some.Package'); $this->assertSame('TYPO3\\Flow\\Package\\Package', get_class($package)); }
/** * Requires and registers all packages which were defined in packageStatesConfiguration * * @param array $packageStatesConfiguration */ protected function registerPackagesFromConfiguration($packageStatesConfiguration) { foreach ($packageStatesConfiguration['packages'] as $composerName => $packageStateConfiguration) { $packagePath = isset($packageStateConfiguration['packagePath']) ? $packageStateConfiguration['packagePath'] : null; $packageClassInformation = isset($packageStateConfiguration['packageClassInformation']) ? $packageStateConfiguration['packageClassInformation'] : null; $package = $this->packageFactory->create($this->packagesBasePath, $packagePath, $packageStateConfiguration['packageKey'], $composerName, $packageStateConfiguration['autoloadConfiguration'], $packageClassInformation); $this->packageKeys[strtolower($package->getPackageKey())] = $package->getPackageKey(); $this->packages[$package->getPackageKey()] = $package; if (isset($packageStateConfiguration['state']) && $packageStateConfiguration['state'] === self::PACKAGE_STATE_ACTIVE || $package->isProtected()) { $this->activePackages[$package->getPackageKey()] = $package; } } }
/** * Requires and registers all packages which were defined in packageStatesConfiguration * * @return void * @throws \TYPO3\Flow\Package\Exception\CorruptPackageException */ protected function registerPackagesFromConfiguration() { foreach ($this->packageStatesConfiguration['packages'] as $packageKey => $stateConfiguration) { $packagePath = isset($stateConfiguration['packagePath']) ? $stateConfiguration['packagePath'] : null; $classesPath = isset($stateConfiguration['classesPath']) ? $stateConfiguration['classesPath'] : null; $manifestPath = isset($stateConfiguration['manifestPath']) ? $stateConfiguration['manifestPath'] : null; try { $package = $this->packageFactory->create($this->packagesBasePath, $packagePath, $packageKey, $classesPath, $manifestPath); } catch (\TYPO3\Flow\Package\Exception\InvalidPackagePathException $exception) { $this->unregisterPackageByPackageKey($packageKey); $this->systemLogger->log('Package ' . $packageKey . ' could not be loaded, it has been unregistered. Error description: "' . $exception->getMessage() . '" (' . $exception->getCode() . ')', LOG_WARNING); continue; } $this->registerPackage($package, false); if (!$this->packages[$packageKey] instanceof PackageInterface) { throw new \TYPO3\Flow\Package\Exception\CorruptPackageException(sprintf('The package class in package "%s" does not implement PackageInterface.', $packageKey), 1300782487); } $this->packageKeys[strtolower($packageKey)] = $packageKey; if ($stateConfiguration['state'] === 'active') { $this->activePackages[$packageKey] = $this->packages[$packageKey]; } } }
/** * Resolves package key from Composer manifest * * If it is a Flow package the name of the containing directory will be used. * * Else if the composer name of the package matches the first part of the lowercased namespace of the package, the mixed * case version of the composer name / namespace will be used, with backslashes replaced by dots. * * Else the composer name will be used with the slash replaced by a dot * * @param object $manifest * @param string $packagePath * @param string $packagesBasePath * @throws \TYPO3\Flow\Package\Exception\InvalidPackageManifestException * @return string */ public static function getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath) { if (!is_object($manifest)) { throw new \TYPO3\Flow\Package\Exception\InvalidPackageManifestException('Invalid composer manifest in package path: ' . $packagePath, 1348146451); } if (isset($manifest->type) && substr($manifest->type, 0, 10) === 'typo3-cms-') { $relativePackagePath = substr($packagePath, strlen($packagesBasePath)); $packageKey = substr($relativePackagePath, strpos($relativePackagePath, '/') + 1, -1); /** * @todo check that manifest name and directory follows convention */ $packageKey = preg_replace('/[^A-Za-z0-9._-]/', '', $packageKey); return $packageKey; } else { return parent::getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath); } }