Example #1
0
 /**
  *
  * @param string $packageName
  * @return CompletePackage
  */
 public function getComposerPackage($packageName)
 {
     if ($this->composerCache->has($packageName)) {
         return $this->composerCache->get($packageName);
     }
     $package = $this->loader->load($this->getJson($this->getFile($packageName)));
     $this->composerCache->set($packageName, $package);
     return $package;
 }
Example #2
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     foreach ($this->getUrlMatches() as $url) {
         $path = realpath($url) . DIRECTORY_SEPARATOR;
         $composerFilePath = $path . 'composer.json';
         if (!file_exists($composerFilePath)) {
             continue;
         }
         $json = file_get_contents($composerFilePath);
         $package = JsonFile::parseJson($json, $composerFilePath);
         $package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => '');
         if (!isset($package['version'])) {
             $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
         }
         $output = '';
         if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
             $package['dist']['reference'] = trim($output);
         } else {
             $package['dist']['reference'] = Locker::getContentHash($json);
         }
         $package = $this->loader->load($package);
         $this->addPackage($package);
     }
     if (count($this->getPackages()) == 0) {
         throw new \RuntimeException(sprintf('No `composer.json` file found in any path repository in "%s"', $this->url));
     }
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!$this->file->exists()) {
         return;
     }
     $packages = $this->file->read();
     if (!is_array($packages)) {
         throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
     }
     $loader = new ArrayLoader();
     foreach ($packages as $packageData) {
         $package = $loader->load($packageData);
         // package was installed as alias, so we only add the alias
         if ($this instanceof InstalledRepositoryInterface && !empty($packageData['installed-as-alias'])) {
             $alias = $packageData['installed-as-alias'];
             $package->setAlias($alias);
             $package->setPrettyAlias($alias);
             $package->setInstalledAsAlias(true);
             $this->addPackage($this->createAliasPackage($package, $alias, $alias));
         } else {
             // only add regular package - if it's not an installed repo the alias will be created on the fly
             $this->addPackage($package);
         }
     }
 }
Example #4
0
 public function load($config)
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     if (!isset($config['version'])) {
         $config['version'] = '1.0.0';
     }
     $package = parent::load($config);
     if (isset($config['repositories'])) {
         foreach ($config['repositories'] as $index => $repo) {
             if (isset($repo['packagist']) && $repo['packagist'] === false) {
                 continue;
             }
             if (!is_array($repo)) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' should be an array, ' . gettype($repo) . ' given');
             }
             if (!isset($repo['type'])) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' must have a type defined');
             }
             $repository = $this->manager->createRepository($repo['type'], $repo);
             $this->manager->addRepository($repository);
         }
         $package->setRepositories($config['repositories']);
     }
     return $package;
 }
Example #5
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     foreach ($this->getUrlMatches() as $url) {
         $path = realpath($url) . DIRECTORY_SEPARATOR;
         $composerFilePath = $path . 'composer.json';
         if (!file_exists($composerFilePath)) {
             continue;
         }
         $json = file_get_contents($composerFilePath);
         $package = JsonFile::parseJson($json, $composerFilePath);
         $package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => sha1($json));
         $package['transport-options'] = $this->options;
         if (!isset($package['version'])) {
             $versionData = $this->versionGuesser->guessVersion($package, $path);
             $package['version'] = $versionData['version'] ?: 'dev-master';
         }
         $output = '';
         if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
             $package['dist']['reference'] = trim($output);
         }
         $package = $this->loader->load($package);
         $this->addPackage($package);
     }
 }
 /**
  * Mock the controller.
  *
  * @return \PHPUnit_Framework_MockObject_MockObject|PackageController
  */
 private function prepareController()
 {
     $manager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->setMethods(null)->getMock();
     $config = new Config();
     $config->merge(array('repositories' => array('packagist' => false)));
     $loader = new RootPackageLoader($manager, $config);
     $rootPackage = $loader->load(json_decode($this->readFixture('composer.json'), true));
     $loader = new ArrayLoader();
     $json = json_decode($this->readFixture('installed.json'), true);
     $packages = [];
     foreach ($json as $package) {
         $packages[] = $loader->load($package);
     }
     $manager->setLocalRepository(new WritableArrayRepository($packages));
     $composer = $this->getMockBuilder(Composer::class)->setMethods(['getPackage', 'getRepositoryManager'])->getMock();
     $composer->method('getPackage')->willReturn($rootPackage);
     $composer->method('getRepositoryManager')->willReturn($manager);
     $controller = $this->getMockBuilder(PackageController::class)->setMethods(['getComposer', 'forward'])->getMock();
     $controller->method('getComposer')->willReturn($composer);
     $home = $this->getMock(HomePathDeterminator::class, ['homeDir']);
     $home->method('homeDir')->willReturn($this->getTempDir());
     $composerJson = $this->provideFixture('composer.json');
     $this->provideFixture('composer.lock');
     $this->provideFixture('installed.json', 'vendor/composer/installed.json');
     $container = new Container();
     $container->set('tenside.home', $home);
     $container->set('tenside.composer_json', new ComposerJson($composerJson));
     /** @var PackageController $controller */
     $controller->setContainer($container);
     return $controller;
 }
Example #7
0
 public function load(array $config, $class = 'Composer\\Package\\RootPackage')
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     $autoVersioned = false;
     if (!isset($config['version'])) {
         // override with env var if available
         if (getenv('COMPOSER_ROOT_VERSION')) {
             $version = getenv('COMPOSER_ROOT_VERSION');
         } else {
             $version = $this->versionGuesser->guessVersion($config, getcwd());
         }
         if (!$version) {
             $version = '1.0.0';
             $autoVersioned = true;
         }
         $config['version'] = $version;
     }
     $realPackage = $package = parent::load($config, $class);
     if ($realPackage instanceof AliasPackage) {
         $realPackage = $package->getAliasOf();
     }
     if ($autoVersioned) {
         $realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)');
     }
     if (isset($config['minimum-stability'])) {
         $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
     }
     $aliases = array();
     $stabilityFlags = array();
     $references = array();
     foreach (array('require', 'require-dev') as $linkType) {
         if (isset($config[$linkType])) {
             $linkInfo = BasePackage::$supportedLinkTypes[$linkType];
             $method = 'get' . ucfirst($linkInfo['method']);
             $links = array();
             foreach ($realPackage->{$method}() as $link) {
                 $links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
             }
             $aliases = $this->extractAliases($links, $aliases);
             $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability());
             $references = $this->extractReferences($links, $references);
         }
     }
     $realPackage->setAliases($aliases);
     $realPackage->setStabilityFlags($stabilityFlags);
     $realPackage->setReferences($references);
     if (isset($config['prefer-stable'])) {
         $realPackage->setPreferStable((bool) $config['prefer-stable']);
     }
     $repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
     foreach ($repos as $repo) {
         $this->manager->addRepository($repo);
     }
     $realPackage->setRepositories($this->config->getRepositories());
     return $package;
 }
 public function load($config)
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     if (!isset($config['version'])) {
         $version = '1.0.0';
         // try to fetch current version from git branch
         if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output)) {
             foreach ($this->process->splitLines($output) as $branch) {
                 if ($branch && preg_match('{^(?:\\* ) *(?:[^/ ]+?/)?(\\S+) *[a-f0-9]+ .*$}', $branch, $match)) {
                     $version = 'dev-' . $match[1];
                 }
             }
         }
         // override with env var if available
         if (getenv('COMPOSER_ROOT_VERSION')) {
             $version = getenv('COMPOSER_ROOT_VERSION');
         }
         $config['version'] = $version;
     } else {
         $version = $config['version'];
     }
     $package = parent::load($config);
     $aliases = array();
     $stabilityFlags = array();
     $references = array();
     foreach (array('require', 'require-dev') as $linkType) {
         if (isset($config[$linkType])) {
             $aliases = $this->extractAliases($config[$linkType], $aliases);
             $stabilityFlags = $this->extractStabilityFlags($config[$linkType], $stabilityFlags);
             $references = $this->extractReferences($config[$linkType], $references);
         }
     }
     $package->setAliases($aliases);
     $package->setStabilityFlags($stabilityFlags);
     $package->setReferences($references);
     if (isset($config['minimum-stability'])) {
         $package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
     }
     if (isset($config['repositories'])) {
         foreach ($config['repositories'] as $index => $repo) {
             if (isset($repo['packagist']) && $repo['packagist'] === false) {
                 continue;
             }
             if (!is_array($repo)) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' should be an array, ' . gettype($repo) . ' given');
             }
             if (!isset($repo['type'])) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') must have a type defined');
             }
             $repository = $this->manager->createRepository($repo['type'], $repo);
             $this->manager->addRepository($repository);
         }
         $package->setRepositories($config['repositories']);
     }
     return $package;
 }
Example #9
0
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     $loader = new ArrayLoader();
     foreach ($this->config as $package) {
         $package = $loader->load($package);
         $this->addPackage($package);
     }
 }
 /**
  * @return CompletePackage
  */
 protected function jsonToPackage($json)
 {
     $package = $this->loader->load($json);
     // @codeCoverageIgnoreStart
     if (!$package instanceof CompletePackage) {
         throw new UnexpectedValueException('Expected instance of CompletePackage, got ' . get_class($package));
     }
     // @codeCoverageIgnoreEnd
     return $package;
 }
Example #11
0
    public function testNotAbandoned()
    {
        $config = array(
            'name' => 'A',
            'version' => '1.2.3.4'
        );

        $package = $this->loader->load($config);
        $this->assertFalse($package->isAbandoned());
    }
 /**
  * @param  array            $config
  * @param  string           $class
  * @return PackageInterface
  */
 public function load(array $config, $class = 'Composer\\Package\\RootPackage')
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     if (!isset($config['version'])) {
         $config['version'] = '999999';
     }
     return parent::load($config, $class);
 }
Example #13
0
 public function load($json)
 {
     if ($json instanceof JsonFile) {
         $config = $json->read();
     } elseif (file_exists($json)) {
         $config = JsonFile::parseJson(file_get_contents($json));
     } elseif (is_string($json)) {
         $config = JsonFile::parseJson($json);
     }
     return parent::load($config);
 }
Example #14
0
 public function load($config)
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     if (!isset($config['version'])) {
         // override with env var if available
         if (getenv('COMPOSER_ROOT_VERSION')) {
             $version = getenv('COMPOSER_ROOT_VERSION');
         } else {
             $version = $this->guessVersion($config);
         }
         if (!$version) {
             $version = '1.0.0';
         }
         $config['version'] = $version;
     } else {
         $version = $config['version'];
     }
     $package = parent::load($config);
     $aliases = array();
     $stabilityFlags = array();
     $references = array();
     foreach (array('require', 'require-dev') as $linkType) {
         if (isset($config[$linkType])) {
             $aliases = $this->extractAliases($config[$linkType], $aliases);
             $stabilityFlags = $this->extractStabilityFlags($config[$linkType], $stabilityFlags);
             $references = $this->extractReferences($config[$linkType], $references);
         }
     }
     $package->setAliases($aliases);
     $package->setStabilityFlags($stabilityFlags);
     $package->setReferences($references);
     if (isset($config['minimum-stability'])) {
         $package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
     }
     if (isset($config['repositories'])) {
         foreach ($config['repositories'] as $index => $repo) {
             if (isset($repo['packagist']) && $repo['packagist'] === false) {
                 continue;
             }
             if (!is_array($repo)) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' should be an array, ' . gettype($repo) . ' given');
             }
             if (!isset($repo['type'])) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') must have a type defined');
             }
             $repository = $this->manager->createRepository($repo['type'], $repo);
             $this->manager->addRepository($repository);
         }
         $package->setRepositories($config['repositories']);
     }
     return $package;
 }
Example #15
0
 /**
  * Convert json to Package.
  *
  * @param  array  $json
  *
  * @return \Composer\Package\CompletePackage
  *
  * @throws \Arcanedev\Composer\Exceptions\InvalidPackageException
  */
 public static function convert(array $json)
 {
     $loader = new ArrayLoader();
     $package = $loader->load($json);
     if ($package instanceof CompletePackage) {
         return $package;
     }
     // @codeCoverageIgnoreStart
     throw new InvalidPackageException('Expected instance of CompletePackage, got ' . get_class($package));
     // @codeCoverageIgnoreEnd
 }
Example #16
0
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!is_numeric(key($this->config))) {
         $this->config = array($this->config);
     }
     $loader = new ArrayLoader();
     foreach ($this->config as $package) {
         $package = $loader->load($package);
         $this->addPackage($package);
     }
 }
Example #17
0
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!$this->file->exists()) {
         return;
     }
     $packages = $this->file->read();
     if (!is_array($packages)) {
         throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
     }
     $loader = new ArrayLoader();
     foreach ($packages as $package) {
         $this->addPackage($loader->load($package));
     }
 }
Example #18
0
 protected function initialize()
 {
     parent::initialize();
     $json = new JsonFile($this->url . '/packages.json');
     $packages = $json->read();
     if (!$packages) {
         throw new \UnexpectedValueException('Could not parse package list from the ' . $this->url . ' repository');
     }
     $loader = new ArrayLoader();
     foreach ($packages as $data) {
         foreach ($data['versions'] as $rev) {
             $this->addPackage($loader->load($rev));
         }
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $loader = new ArrayLoader(null, true);
     $directories = glob($this->directory . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR | GLOB_NOSORT);
     foreach ($directories as $directory) {
         if (!file_exists($directory . DIRECTORY_SEPARATOR . 'composer.json')) {
             continue;
         }
         $jsonFile = new JsonFile($directory . DIRECTORY_SEPARATOR . 'composer.json');
         $packageData = $jsonFile->read();
         $packageData['version'] = '1.0';
         $package = $loader->load($packageData);
         $this->addPackage($package);
     }
 }
Example #20
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     $composerFilePath = $this->path . 'composer.json';
     if (!file_exists($composerFilePath)) {
         throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $this->path));
     }
     $json = file_get_contents($composerFilePath);
     $package = JsonFile::parseJson($json, $composerFilePath);
     $package['dist'] = array('type' => 'path', 'url' => $this->path, 'reference' => '');
     if (!isset($package['version'])) {
         $package['version'] = $this->versionGuesser->guessVersion($package, $this->path) ?: 'dev-master';
     }
     if (is_dir($this->path . '/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $this->path)) {
         $package['dist']['reference'] = trim($output);
     }
     $package = $this->loader->load($package);
     $this->addPackage($package);
 }
Example #21
0
 public function load($config)
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     if (!isset($config['version'])) {
         // override with env var if available
         if (getenv('COMPOSER_ROOT_VERSION')) {
             $version = getenv('COMPOSER_ROOT_VERSION');
         } else {
             $version = $this->guessVersion($config);
         }
         if (!$version) {
             $version = '1.0.0';
         }
         $config['version'] = $version;
     } else {
         $version = $config['version'];
     }
     $package = parent::load($config);
     $aliases = array();
     $stabilityFlags = array();
     $references = array();
     foreach (array('require', 'require-dev') as $linkType) {
         if (isset($config[$linkType])) {
             $aliases = $this->extractAliases($config[$linkType], $aliases);
             $stabilityFlags = $this->extractStabilityFlags($config[$linkType], $stabilityFlags);
             $references = $this->extractReferences($config[$linkType], $references);
         }
     }
     $package->setAliases($aliases);
     $package->setStabilityFlags($stabilityFlags);
     $package->setReferences($references);
     if (isset($config['minimum-stability'])) {
         $package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
     }
     $repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
     foreach ($repos as $repo) {
         $this->manager->addRepository($repo);
     }
     $package->setRepositories($this->config->getRepositories());
     return $package;
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!$this->file->exists()) {
         return;
     }
     try {
         $packages = $this->file->read();
         if (!is_array($packages)) {
             throw new \UnexpectedValueException('Could not parse package list from the repository');
         }
     } catch (\Exception $e) {
         throw new InvalidRepositoryException('Invalid repository data in ' . $this->file->getPath() . ', packages could not be loaded: [' . get_class($e) . '] ' . $e->getMessage());
     }
     $loader = new ArrayLoader(null, true);
     foreach ($packages as $packageData) {
         $package = $loader->load($packageData);
         $this->addPackage($package);
     }
 }
Example #23
0
 /**
  * Read a JSON file and merge its contents
  *
  * @param RootPackageInterface $root
  * @param string $path
  */
 protected function loadFile($root, $path)
 {
     if (in_array($path, $this->loadedFiles)) {
         $this->debug("Skipping duplicate <comment>{$path}</comment>...");
         return;
     } else {
         $this->loadedFiles[] = $path;
     }
     $this->debug("Loading <comment>{$path}</comment>...");
     $json = $this->readPackageJson($path);
     $package = $this->loader->load($json);
     $this->mergeRequires($root, $package);
     $this->mergeDevRequires($root, $package);
     if (isset($json['repositories'])) {
         $this->addRepositories($json['repositories'], $root);
     }
     if ($package->getSuggests()) {
         $root->setSuggests(array_merge($root->getSuggests(), $package->getSuggests()));
     }
     if ($this->recurse && isset($json['extra']['merge-plugin'])) {
         $this->mergePackages($json['extra']['merge-plugin']);
     }
 }
Example #24
0
 public function load($config)
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     if (!isset($config['version'])) {
         $config['version'] = '1.0.0';
     }
     $package = parent::load($config);
     if (isset($config['require'])) {
         $aliases = array();
         foreach ($config['require'] as $reqName => $reqVersion) {
             if (preg_match('{^([^,\\s]+) +as +([^,\\s]+)$}', $reqVersion, $match)) {
                 $aliases[] = array('package' => strtolower($reqName), 'version' => $this->versionParser->normalize($match[1]), 'alias' => $match[2], 'alias_normalized' => $this->versionParser->normalize($match[2]));
             }
         }
         $package->setAliases($aliases);
     }
     if (isset($config['repositories'])) {
         foreach ($config['repositories'] as $index => $repo) {
             if (isset($repo['packagist']) && $repo['packagist'] === false) {
                 continue;
             }
             if (!is_array($repo)) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' should be an array, ' . gettype($repo) . ' given');
             }
             if (!isset($repo['type'])) {
                 throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') must have a type defined');
             }
             $repository = $this->manager->createRepository($repo['type'], $repo);
             $this->manager->addRepository($repository);
         }
         $package->setRepositories($config['repositories']);
     }
     return $package;
 }
Example #25
0
 /**
  * Tests the Installer's getComponentPath function.
  *
  * @param $expected
  *   The expected install path for the package.
  * @param $package
  *   The package to test upon.
  *
  * @dataProvider providerGetComponentPath
  *
  * @see \ComponentInstaller\Installer::getComponentPath()
  */
 public function testGetComponentPath($expected, $package)
 {
     // Construct the mock objects.
     $installer = new Installer($this->io, $this->composer, 'component');
     $loader = new ArrayLoader();
     // Test the results.
     $result = $installer->getComponentPath($loader->load($package));
     $this->assertEquals($this->componentDir . '/' . $expected, $result);
 }
Example #26
0
 /**
  * Loads previously dumped Packages in order to merge with updates.
  *
  * @return PackageInterface[]
  */
 public function load()
 {
     $packages = array();
     $repoJson = new JsonFile($this->filename);
     $dirName = dirname($this->filename);
     if ($repoJson->exists()) {
         $loader = new ArrayLoader();
         $jsonIncludes = $repoJson->read();
         $jsonIncludes = isset($jsonIncludes['includes']) && is_array($jsonIncludes['includes']) ? $jsonIncludes['includes'] : array();
         foreach ($jsonIncludes as $includeFile => $includeConfig) {
             $includeJson = new JsonFile($dirName . '/' . $includeFile);
             if (!$includeJson->exists()) {
                 $this->output->writeln(sprintf('<error>File \'%s\' does not exist, defined in "includes" in \'%s\'</error>', $includeJson->getPath(), $repoJson->getPath()));
                 continue;
             }
             $jsonPackages = $includeJson->read();
             $jsonPackages = isset($jsonPackages['packages']) && is_array($jsonPackages['packages']) ? $jsonPackages['packages'] : array();
             foreach ($jsonPackages as $jsonPackage) {
                 if (is_array($jsonPackage)) {
                     foreach ($jsonPackage as $jsonVersion) {
                         if (is_array($jsonVersion)) {
                             if (isset($jsonVersion['name']) && in_array($jsonVersion['name'], $this->packagesFilter)) {
                                 continue;
                             }
                             $package = $loader->load($jsonVersion);
                             $packages[$package->getUniqueName()] = $package;
                         }
                     }
                 }
             }
         }
     }
     return $packages;
 }
Example #27
0
 /**
  * Extracts the dev packages out of the localRepo
  *
  * This works by faking the operations so we can see what the dev packages
  * would be at the end of the operation execution. This lets us then remove
  * the dev packages from the list of operations accordingly if we are in a
  * --no-dev install or update.
  *
  * @return array
  */
 private function extractDevPackages(array $operations, RepositoryInterface $localRepo, PlatformRepository $platformRepo, array $aliases)
 {
     if (!$this->package->getDevRequires()) {
         return array();
     }
     // fake-apply all operations to this clone of the local repo so we see the complete set of package we would end up with
     $tempLocalRepo = clone $localRepo;
     foreach ($operations as $operation) {
         switch ($operation->getJobType()) {
             case 'install':
             case 'markAliasInstalled':
                 if (!$tempLocalRepo->hasPackage($operation->getPackage())) {
                     $tempLocalRepo->addPackage(clone $operation->getPackage());
                 }
                 break;
             case 'uninstall':
             case 'markAliasUninstalled':
                 $tempLocalRepo->removePackage($operation->getPackage());
                 break;
             case 'update':
                 $tempLocalRepo->removePackage($operation->getInitialPackage());
                 if (!$tempLocalRepo->hasPackage($operation->getTargetPackage())) {
                     $tempLocalRepo->addPackage(clone $operation->getTargetPackage());
                 }
                 break;
             default:
                 throw new \LogicException('Unknown type: ' . $operation->getJobType());
         }
     }
     // we have to reload the local repo to handle aliases properly
     // but as it is not persisted on disk we use a loader/dumper
     // to reload it in memory
     $localRepo = new InstalledArrayRepository(array());
     $loader = new ArrayLoader(null, true);
     $dumper = new ArrayDumper();
     foreach ($tempLocalRepo->getCanonicalPackages() as $pkg) {
         $localRepo->addPackage($loader->load($dumper->dump($pkg)));
     }
     unset($tempLocalRepo, $loader, $dumper);
     $policy = $this->createPolicy();
     $pool = $this->createPool();
     $installedRepo = $this->createInstalledRepo($localRepo, $platformRepo);
     $pool->addRepository($installedRepo, $aliases);
     // creating requirements request without dev requirements
     $request = $this->createRequest($this->package, $platformRepo);
     $request->updateAll();
     foreach ($this->package->getRequires() as $link) {
         $request->install($link->getTarget(), $link->getConstraint());
     }
     // solve deps to see which get removed
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
     $solver = new Solver($policy, $pool, $installedRepo, $this->io);
     $ops = $solver->solve($request, $this->ignorePlatformReqs);
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
     $devPackages = array();
     foreach ($ops as $op) {
         if ($op->getJobType() === 'uninstall') {
             $devPackages[] = $op->getPackage();
         }
     }
     return $devPackages;
 }
 /**
  * @param array $json
  * @return CompletePackage
  */
 protected function loadPackage(array $json)
 {
     $loader = new ArrayLoader();
     $package = $loader->load($json);
     // @codeCoverageIgnoreStart
     if (!$package instanceof CompletePackage) {
         throw new UnexpectedValueException('Expected instance of CompletePackage, got ' . get_class($package));
     }
     // @codeCoverageIgnoreEnd
     return $package;
 }
Example #29
0
 /**
  * @param  string                    $packagesLink
  * @return void
  * @throws \InvalidArgumentException
  */
 private function fetchPear2Packages($packagesLink)
 {
     $loader = new ArrayLoader();
     $packagesXml = $this->requestXml($packagesLink);
     $informations = $packagesXml->getElementsByTagName('pi');
     foreach ($informations as $information) {
         $package = $information->getElementsByTagName('p')->item(0);
         $packageName = $package->getElementsByTagName('n')->item(0)->nodeValue;
         $fullName = 'pear-' . $this->channel . '/' . $packageName;
         $packageData = array('name' => $fullName, 'type' => 'library', 'autoload' => array('classmap' => array('')));
         $packageKeys = array('l' => 'license', 'd' => 'description');
         foreach ($packageKeys as $pear => $composer) {
             if ($package->getElementsByTagName($pear)->length > 0 && ($pear = $package->getElementsByTagName($pear)->item(0)->nodeValue)) {
                 $packageData[$composer] = $pear;
             }
         }
         $depsData = array();
         foreach ($information->getElementsByTagName('deps') as $depElement) {
             $depsVersion = $depElement->getElementsByTagName('v')->item(0)->nodeValue;
             $depsData[$depsVersion] = $this->parseDependencies($depElement->getElementsByTagName('d')->item(0)->nodeValue);
         }
         $releases = $information->getElementsByTagName('a')->item(0);
         if (!$releases) {
             continue;
         }
         $releases = $releases->getElementsByTagName('r');
         $packageUrl = $this->url . '/get/' . $packageName;
         foreach ($releases as $release) {
             $version = $release->getElementsByTagName('v')->item(0)->nodeValue;
             $releaseData = array('dist' => array('type' => 'pear', 'url' => $packageUrl . '-' . $version . '.tgz'), 'version' => $version);
             if (isset($depsData[$version])) {
                 $releaseData += $depsData[$version];
             }
             $package = $packageData + $releaseData;
             try {
                 $this->addPackage($loader->load($package));
                 if ($this->io->isVerbose()) {
                     $this->io->write('Loaded ' . $package['name'] . ' ' . $package['version']);
                 }
             } catch (\UnexpectedValueException $e) {
                 if ($this->io->isVerbose()) {
                     $this->io->write('Could not load ' . $package['name'] . ' ' . $package['version'] . ': ' . $e->getMessage());
                 }
                 continue;
             }
         }
     }
 }
Example #30
0
 /**
  * Get installed packages from the installed.json file.
  *
  * @param Composer $composer  Composer model
  * @param string   $directory The installed repositories directory
  *
  * @return array Array of PackageInterface
  */
 protected function getInstalledPackages($directory)
 {
     $file = new JsonFile($directory . '/installed.json');
     if (!$file->exists()) {
         return array();
     }
     $loader = new ArrayLoader();
     $packages = array();
     foreach ($file->read() as $config) {
         $package = $loader->load($config);
         $packages[$package->getPrettyName()] = $package;
     }
     return $packages;
 }