Neos\Flow\Package\PackageManager::createPackage PHP Метод

createPackage() публичный Метод

Create a package, given the package key
public createPackage ( string $packageKey, array $manifest = [], string $packagesPath = null ) : Neos\Flow\Package\PackageInterface
$packageKey string The package key of the new package
$manifest array A composer manifest as associative array. This is a preparation for the signature change in Flow 4.0. If you use this argument, then $packageMetaData and $packageType will be ignored.
$packagesPath string If specified, the package will be created in this path, otherwise the default "Application" directory is used
Результат Neos\Flow\Package\PackageInterface The newly created package
    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];
    }

Usage Example

 /**
  * @test
  */
 public function unfreezePackageEmitsPackageStatesUpdatedSignal()
 {
     $this->mockApplicationContext->expects($this->atLeastOnce())->method('isDevelopment')->will($this->returnValue(true));
     $this->packageManager->createPackage('Some.Package', ['name' => 'some/package', 'type' => 'neos-package']);
     $this->packageManager->freezePackage('Some.Package');
     $this->mockDispatcher->expects($this->once())->method('dispatch')->with(PackageManager::class, 'packageStatesUpdated');
     $this->packageManager->unfreezePackage('Some.Package');
 }