Exemplo n.º 1
0
    /**
     * @dataProvider creationCases
     */
    public function testRepoCreation($type, $options, $exception = null)
    {
        if ($exception) {
            $this->setExpectedException($exception);
        }

        $rm = new RepositoryManager(
            $this->getMock('Composer\IO\IOInterface'),
            $config = $this->getMock('Composer\Config', array('get')),
            $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
        );

        $tmpdir = $this->tmpdir;
        $config
            ->expects($this->any())
            ->method('get')
            ->will($this->returnCallback(function ($arg) use ($tmpdir) {
                return 'cache-repo-dir' === $arg ? $tmpdir : null;
            }))
        ;

        $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
        $rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
        $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
        $rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
        $rm->setRepositoryClass('git', 'Composer\Repository\VcsRepository');
        $rm->setRepositoryClass('svn', 'Composer\Repository\VcsRepository');
        $rm->setRepositoryClass('perforce', 'Composer\Repository\VcsRepository');
        $rm->setRepositoryClass('hg', 'Composer\Repository\VcsRepository');
        $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository');

        $rm->createRepository('composer', array('url' => 'http://example.org'));
        $rm->createRepository($type, $options);
    }
Exemplo n.º 2
0
 /**
  * @dataProvider creationCases
  */
 public function testRepoCreation($type, $config)
 {
     $rm = new RepositoryManager($this->getMock('Composer\\IO\\IOInterface'), $this->getMock('Composer\\Config'), $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock());
     $rm->setRepositoryClass('composer', 'Composer\\Repository\\ComposerRepository');
     $rm->setRepositoryClass('vcs', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('package', 'Composer\\Repository\\PackageRepository');
     $rm->setRepositoryClass('pear', 'Composer\\Repository\\PearRepository');
     $rm->setRepositoryClass('git', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('svn', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('perforce', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('hg', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('artifact', 'Composer\\Repository\\ArtifactRepository');
     $rm->createRepository('composer', array('url' => 'http://example.org'));
     $rm->createRepository('composer', array('url' => 'http://example.org'));
     $rm->createRepository('composer', array('url' => 'http://example.org'));
 }
Exemplo n.º 3
0
 /**
  * Adds asset registry repositories.
  *
  * @param RepositoryManager $rm
  * @param VcsPackageFilter  $filter
  * @param array             $extra
  */
 public static function addRegistryRepositories(RepositoryManager $rm, VcsPackageFilter $filter, array $extra)
 {
     $opts = array_key_exists('asset-registry-options', $extra) ? $extra['asset-registry-options'] : array();
     foreach (Assets::getRegistries() as $assetType => $registryClass) {
         $config = array('repository-manager' => $rm, 'vcs-package-filter' => $filter, 'asset-options' => static::createAssetOptions($opts, $assetType));
         $rm->setRepositoryClass($assetType, $registryClass);
         $rm->addRepository($rm->createRepository($assetType, $config));
     }
 }
Exemplo n.º 4
0
 /**
  * Add a repository to collection of repositories.
  *
  * @param  \Composer\Repository\RepositoryManager  $repoManager
  * @param  array                                   $repositories
  * @param  array                                   $repoJson
  */
 private function addRepository(RepositoryManager $repoManager, array &$repositories, $repoJson)
 {
     if (isset($repoJson['type'])) {
         $this->getLogger()->info("Prepending {$repoJson['type']} repository");
         $repository = $repoManager->createRepository($repoJson['type'], $repoJson);
         $repoManager->prependRepository($repository);
         $repositories[] = $repository;
     }
 }
Exemplo n.º 5
0
    /**
     * @param RepositoryManager $rm         The repository mamanger
     * @param array             $repos      The list of already repository added (passed by reference)
     * @param string            $name       The name of the new repository
     * @param array             $repoConfig The config of the new repository
     * @param Pool|null         $pool       The pool
     */
    public static function addRepository(RepositoryManager $rm, array &$repos, $name, array $repoConfig, Pool $pool = null)
    {
        if (!isset($repos[$name])) {
            $repo = $rm->createRepository($repoConfig['type'], $repoConfig);
            $repos[$name] = $repo;
            $rm->addRepository($repo);

            if (null !== $pool) {
                $pool->addRepository($repo);
            }
        }
    }
 /**
  * @return RepositoryInterface[]
  */
 private static function createRepos(RepositoryManager $rm, array $repoConfigs)
 {
     $repos = array();
     foreach ($repoConfigs as $index => $repo) {
         if (is_string($repo)) {
             throw new \UnexpectedValueException('"repositories" should be an array of repository definitions, only a single repository was given');
         }
         if (!is_array($repo)) {
             throw new \UnexpectedValueException('Repository "' . $index . '" (' . json_encode($repo) . ') should be an array, ' . gettype($repo) . ' given');
         }
         if (!isset($repo['type'])) {
             throw new \UnexpectedValueException('Repository "' . $index . '" (' . json_encode($repo) . ') must have a type defined');
         }
         $name = is_int($index) && isset($repo['url']) ? preg_replace('{^https?://}i', '', $repo['url']) : $index;
         while (isset($repos[$name])) {
             $name .= '2';
         }
         if ($repo['type'] === 'filesystem') {
             $repos[$name] = new FilesystemRepository($repo['json']);
         } else {
             $repos[$name] = $rm->createRepository($repo['type'], $repo);
         }
     }
     return $repos;
 }
Exemplo n.º 7
0
 public function __construct()
 {
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     $this->config = new Config();
     $this->repositoryManager = $rm = new RepositoryManager(new NullIO(), $this->config);
     $rm->setRepositoryClass('composer', 'Composer\\Repository\\ComposerRepository');
     $rm->setRepositoryClass('vcs', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('package', 'Composer\\Repository\\PackageRepository');
     $rm->setRepositoryClass('pear', 'Composer\\Repository\\PearRepository');
     $rm->setRepositoryClass('git', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('svn', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('perforce', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('hg', 'Composer\\Repository\\VcsRepository');
     $rm->setRepositoryClass('artifact', 'Composer\\Repository\\ArtifactRepository');
     $home = $this->getHomeDir();
     $cache = $this->getCacheDir($home);
     $this->config->merge(array('config' => array('home' => $home, 'cache-dir' => $cache)));
     foreach ($this->config->getRepositories() as $index => $repo) {
         if (!is_array($repo)) {
             throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') should be an array, ' . gettype($repo) . ' given');
         }
         if (!isset($repo['type'])) {
             throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') must have a type defined');
         }
         $name = is_int($index) && isset($repo['url']) ? preg_replace('{^https?://}i', '', $repo['url']) : $index;
         while (isset($repos[$name])) {
             $name .= '2';
         }
         $repo_object = $rm->createRepository($repo['type'], $repo);
         $rm->addRepository($repo_object);
     }
 }
Exemplo n.º 8
0
 /**
  * Add repository config.
  *
  * @param IOInterface       $io         The IO instance
  * @param RepositoryManager $rm         The repository mamanger
  * @param array             $repos      The list of already repository added (passed by reference)
  * @param string            $name       The name of the new repository
  * @param array             $repoConfig The config of the new repository
  * @param Pool|null         $pool       The pool
  */
 public static function addRepository(IOInterface $io, RepositoryManager $rm, array &$repos, $name, array $repoConfig, Pool $pool = null)
 {
     $repo = $rm->createRepository($repoConfig['type'], $repoConfig);
     static::addRepositoryInstance($io, $rm, $repos, $name, $repo, $pool);
 }
Exemplo n.º 9
0
 /**
  * @param string $type
  * @param RepositoryManager $rm
  * @return mixed
  */
 protected static function buildRegistry($type, $rm)
 {
     $config = ['repository-manager' => $rm, 'asset-options' => []];
     $rm->setRepositoryClass($type, static::$classes[$type]);
     return $rm->createRepository($type, $config);
 }