Exemplo n.º 1
0
 /**
  * Loads the package repository for a given project.
  *
  * @param ProjectEnvironment $environment        The project environment.
  * @param PackageFileStorage $packageFileStorage The package file storage.
  *
  * @throws FileNotFoundException If the install path of a package not exist.
  * @throws NoDirectoryException If the install path of a package points to a file.
  * @throws InvalidConfigException If a configuration file contains invalid configuration.
  * @throws NameConflictException If a package has the same name as another loaded package.
  */
 public function __construct(ProjectEnvironment $environment, PackageFileStorage $packageFileStorage)
 {
     $this->environment = $environment;
     $this->rootDir = $environment->getRootDirectory();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->packageFileStorage = $packageFileStorage;
 }
 public function testCreateWithDispatcher()
 {
     $config = new Config();
     $rootPackageFile = new RootPackageFile();
     $dispatcher = new EventDispatcher();
     $environment = new ProjectEnvironment(null, __DIR__, $config, $rootPackageFile, null, $dispatcher);
     $this->assertSame($dispatcher, $environment->getEventDispatcher());
 }
Exemplo n.º 3
0
    /**
     * Adds the createDiscovery() method.
     *
     * @param Clazz $class The factory class model.
     */
    private function addCreateDiscoveryMethod(Clazz $class)
    {
        $method = new Method('createDiscovery');
        $method->setDescription('Creates the resource discovery.');
        $arg = new Argument(self::REPO_VAR_NAME);
        $arg->setTypeHint('ResourceRepository');
        $arg->setType('ResourceRepository');
        $arg->setDescription('The resource repository to read from.');
        $method->addArgument($arg);
        $method->setReturnValue(new ReturnValue('$' . self::DISCOVERY_VAR_NAME, 'ResourceDiscovery', 'The created resource discovery.'));
        $method->addBody(<<<EOF
if (!interface_exists('Puli\\Discovery\\Api\\ResourceDiscovery')) {
    throw new RuntimeException('Please install puli/discovery to create ResourceDiscovery instances.');
}

EOF
);
        $class->addImport(new Import('Puli\\Repository\\Api\\ResourceRepository'));
        $class->addImport(new Import('Puli\\Discovery\\Api\\ResourceDiscovery'));
        $class->addImport(new Import('RuntimeException'));
        $class->addMethod($method);
        // Add method body
        $config = $this->environment->getConfig();
        $type = $config->get(Config::DISCOVERY_TYPE);
        $options = $this->camelizeKeys($config->get(Config::DISCOVERY));
        $options['rootDir'] = $this->rootDir;
        $generator = $this->generatorRegistry->getServiceGenerator(GeneratorRegistry::DISCOVERY, $type);
        $generator->generateNewInstance(self::DISCOVERY_VAR_NAME, $method, $this->generatorRegistry, $options);
    }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function prepareInstallation(AssetMapping $mapping)
 {
     $glob = $mapping->getGlob();
     $targetName = $mapping->getTargetName();
     $resources = $this->repo->find($glob);
     if ($resources->isEmpty()) {
         throw NotInstallableException::noResourceMatches($glob);
     }
     if (!$this->installTargets->contains($targetName)) {
         throw NotInstallableException::targetNotFound($targetName);
     }
     $target = $this->installTargets->get($targetName);
     $installerName = $target->getInstallerName();
     if (!$this->installerManager->hasInstallerDescriptor($installerName)) {
         throw NotInstallableException::installerNotFound($installerName);
     }
     $installerDescriptor = $this->installerManager->getInstallerDescriptor($installerName);
     $installer = $this->loadInstaller($installerDescriptor);
     $rootDir = $this->environment->getRootDirectory();
     $params = new InstallationParams($installer, $installerDescriptor, $resources, $mapping, $target, $rootDir);
     $installer->validateParams($params);
     return $params;
 }
Exemplo n.º 5
0
    public function testListPackagesWithFormat()
    {
        $args = self::$listCommand->parseArgs(new StringArgs('--format %name%:%installer%:%install_path%:%state%'));
        $rootDir = $this->environment->getRootDirectory();
        $statusCode = $this->handler->handleList($args, $this->io);
        $expected = <<<EOF
vendor/root::{$rootDir}:enabled
vendor/package1:spock:{$rootDir}/packages/package1:enabled
vendor/package2:spock:{$rootDir}/packages/package2:enabled
vendor/package3:kirk:{$rootDir}/packages/package3:not-found
vendor/package4:spock:{$rootDir}/packages/package4:not-loadable

EOF;
        $this->assertSame(0, $statusCode);
        $this->assertSame($expected, $this->io->fetchOutput());
        $this->assertEmpty($this->io->fetchErrors());
    }
Exemplo n.º 6
0
 /**
  * Creates a tag manager.
  *
  * @param ProjectEnvironment $environment
  * @param EditableDiscovery  $discovery
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  * @param LoggerInterface    $logger
  */
 public function __construct(ProjectEnvironment $environment, EditableDiscovery $discovery, PackageCollection $packages, PackageFileStorage $packageFileStorage, LoggerInterface $logger = null)
 {
     $this->environment = $environment;
     $this->discovery = $discovery;
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->logger = $logger ?: new NullLogger();
 }
 /**
  * Creates a repository manager.
  *
  * @param ProjectEnvironment $environment
  * @param EditableRepository $repo
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  */
 public function __construct(ProjectEnvironment $environment, EditableRepository $repo, PackageCollection $packages, PackageFileStorage $packageFileStorage)
 {
     $this->environment = $environment;
     $this->dispatcher = $environment->getEventDispatcher();
     $this->repo = $repo;
     $this->config = $environment->getConfig();
     $this->rootDir = $environment->getRootDirectory();
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
 }
Exemplo n.º 8
0
 private function activatePlugins()
 {
     foreach ($this->environment->getRootPackageFile()->getPluginClasses() as $pluginClass) {
         $this->validatePluginClass($pluginClass);
         /** @var PuliPlugin $plugin */
         $plugin = new $pluginClass();
         $plugin->activate($this);
     }
 }