public function createPackage($packageKey, array $manifest = [], $packagesPath = null)
{
if (!$this->isPackageKeyValid($packageKey)) {
throw new Exception\InvalidPackageKeyException('The package key "' . $packageKey . '" is invalid', 1220722210);
}
if ($this->isPackageAvailable($packageKey)) {
throw new Exception\PackageKeyAlreadyExistsException('The package key "' . $packageKey . '" already exists', 1220722873);
}
if ($packagesPath === null) {
$packagesPath = 'Application';
$packageType = isset($manifest['type']) ? $manifest['type'] : PackageInterface::DEFAULT_COMPOSER_TYPE;
if (is_array($this->settings['package']['packagesPathByType']) && isset($this->settings['package']['packagesPathByType'][$packageType])) {
$packagesPath = $this->settings['package']['packagesPathByType'][$packageType];
}
$packagesPath = Files::getUnixStylePath(Files::concatenatePaths([$this->packagesBasePath, $packagesPath]));
}
$packagePath = Files::concatenatePaths([$packagesPath, $packageKey]) . '/';
Files::createDirectoryRecursively($packagePath);
foreach ([PackageInterface::DIRECTORY_CLASSES, PackageInterface::DIRECTORY_CONFIGURATION, PackageInterface::DIRECTORY_RESOURCES, PackageInterface::DIRECTORY_TESTS_UNIT, PackageInterface::DIRECTORY_TESTS_FUNCTIONAL] as $path) {
Files::createDirectoryRecursively(Files::concatenatePaths([$packagePath, $path]));
}
$manifest = ComposerUtility::writeComposerManifest($packagePath, $packageKey, $manifest);
$refreshedPackageStatesConfiguration = $this->rescanPackages(false);
$this->packageStatesConfiguration = $refreshedPackageStatesConfiguration;
$this->registerPackageFromStateConfiguration($manifest['name'], $this->packageStatesConfiguration['packages'][$manifest['name']]);
return $this->packages[$packageKey];
}