Neos\Flow\Package\PackageFactory::create PHP Method

create() public method

Returns a package instance.
public create ( string $packagesBasePath, string $packagePath, string $packageKey, string $composerName, array $autoloadConfiguration = [], array $packageClassInformation = null ) : Neos\Flow\Package\PackageInterface
$packagesBasePath string the base install path of packages,
$packagePath string path to package, relative to base path
$packageKey string key / name of the package
$composerName string
$autoloadConfiguration array Autoload configuration as defined in composer.json
$packageClassInformation array
return Neos\Flow\Package\PackageInterface
    public function create($packagesBasePath, $packagePath, $packageKey, $composerName, array $autoloadConfiguration = [], array $packageClassInformation = null)
    {
        $absolutePackagePath = Files::concatenatePaths([$packagesBasePath, $packagePath]) . '/';
        if ($packageClassInformation === null) {
            $packageClassInformation = $this->detectFlowPackageFilePath($packageKey, $absolutePackagePath);
        }
        $packageClassName = Package::class;
        if (!empty($packageClassInformation)) {
            $packageClassName = $packageClassInformation['className'];
            $packageClassPath = Files::concatenatePaths(array($absolutePackagePath, $packageClassInformation['pathAndFilename']));
            require_once $packageClassPath;
        }
        $package = new $packageClassName($packageKey, $composerName, $absolutePackagePath, $autoloadConfiguration);
        if (!$package instanceof PackageInterface) {
            throw new Exception\CorruptPackageException(sprintf('The package class of package "%s" does not implement \\Neos\\Flow\\Package\\PackageInterface. Check the file "%s".', $packageKey, $packageClassInformation['pathAndFilename']), 1427193370);
        }
        return $package;
    }

Usage Example

コード例 #1
0
 /**
  * @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": "neos-test"}');
     $package = $this->packageFactory->create('vfs://Packages/', 'Some/Path/Some.Package/', 'Some.Package', 'some/package');
     $this->assertSame(Package::class, get_class($package));
 }
All Usage Examples Of Neos\Flow\Package\PackageFactory::create