예제 #1
0
 public function build($rootDirectory, $optimize = false, $noDevMode = false)
 {
     $packages = $this->loadPackages($rootDirectory);
     $evm = new EventDispatcher(new Composer(), $this->io);
     $generator = new AutoloadGenerator($evm, $this->io);
     $generator->setDevMode(!$noDevMode);
     $installationManager = new InstallationManager();
     $installationManager->addInstaller(new FiddlerInstaller());
     $this->io->write('Building fiddler.json projects.');
     foreach ($packages as $packageName => $config) {
         if (strpos($packageName, 'vendor') === 0) {
             continue;
         }
         $this->io->write(' [Build] <info>' . $packageName . '</info>');
         $mainPackage = new Package($packageName, "@stable", "@stable");
         $mainPackage->setType('fiddler');
         $mainPackage->setAutoload($config['autoload']);
         $mainPackage->setDevAutoload($config['autoload-dev']);
         $localRepo = new FiddlerInstalledRepository();
         $this->resolvePackageDependencies($localRepo, $packages, $packageName);
         $composerConfig = new Config(true, $rootDirectory);
         $composerConfig->merge(array('config' => array('vendor-dir' => $config['path'] . '/vendor')));
         $generator->dump($composerConfig, $localRepo, $mainPackage, $installationManager, 'composer', $optimize);
     }
 }
예제 #2
0
 /**
  * Search for a given package version.
  *
  * Usage examples : Composition::has('php', '5.3.*') // PHP version
  *                  Composition::has('ext-memcache') // PHP extension
  *                  Composition::has('vendor/package', '>2.1') // Package version
  *
  * @param type $packageName  The package name
  * @param type $prettyString An optional version constraint
  *
  * @return boolean           Wether or not the package has been found.
  */
 public static function has($packageName, $prettyString = '*')
 {
     if (null === self::$pool) {
         if (null === self::$rootDir) {
             self::$rootDir = getcwd();
             if (!file_exists(self::$rootDir . '/composer.json')) {
                 throw new \RuntimeException('Unable to guess the project root dir, please specify it manually using the Composition::setRootDir method.');
             }
         }
         $minimumStability = 'dev';
         $config = new Config();
         $file = new JsonFile(self::$rootDir . '/composer.json');
         if ($file->exists()) {
             $projectConfig = $file->read();
             $config->merge($projectConfig);
             if (isset($projectConfig['minimum-stability'])) {
                 $minimumStability = $projectConfig['minimum-stability'];
             }
         }
         $vendorDir = self::$rootDir . '/' . $config->get('vendor-dir');
         $pool = new Pool($minimumStability);
         $pool->addRepository(new PlatformRepository());
         $pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
         $pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed_dev.json')));
         self::$pool = $pool;
     }
     $parser = new VersionParser();
     $constraint = $parser->parseConstraints($prettyString);
     $packages = self::$pool->whatProvides($packageName, $constraint);
     return empty($packages) ? false : true;
 }
예제 #3
0
 /**
  * @param string $url
  * @param string $destination
  * @param bool $useRedirector
  * @param IO\IOInterface $io
  * @param Config $config
  */
 public function __construct($url, $destination, $useRedirector, IO\IOInterface $io, Config $config)
 {
     $this->setURL($url);
     $this->setDestination($destination);
     $this->setCA($config->get('capath'), $config->get('cafile'));
     $this->setupAuthentication($io, $useRedirector, $config->get('github-domains') ?: array(), $config->get('gitlab-domains') ?: array());
 }
예제 #4
0
파일: BaseIO.php 프로젝트: neon64/composer
 /**
  * {@inheritDoc}
  */
 public function loadConfiguration(Config $config)
 {
     $bitbucketOauth = $config->get('bitbucket-oauth') ?: array();
     $githubOauth = $config->get('github-oauth') ?: array();
     $gitlabOauth = $config->get('gitlab-oauth') ?: array();
     $httpBasic = $config->get('http-basic') ?: array();
     // reload oauth tokens from config if available
     foreach ($bitbucketOauth as $domain => $cred) {
         $this->checkAndSetAuthentication($domain, $cred['consumer-key'], $cred['consumer-secret']);
     }
     foreach ($githubOauth as $domain => $token) {
         if (!preg_match('{^[a-z0-9]+$}', $token)) {
             throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
         }
         $this->checkAndSetAuthentication($domain, $token, 'x-oauth-basic');
     }
     foreach ($gitlabOauth as $domain => $token) {
         $this->checkAndSetAuthentication($domain, $token, 'oauth2');
     }
     // reload http basic credentials from config if available
     foreach ($httpBasic as $domain => $cred) {
         $this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']);
     }
     // setup process timeout
     ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
 }
예제 #5
0
 /**
  * {@inheritDoc}
  */
 public function loadConfiguration(Config $config)
 {
     // reload oauth token from config if available
     if ($tokens = $config->get('github-oauth')) {
         foreach ($tokens as $domain => $token) {
             if (!preg_match('{^[a-z0-9]+$}', $token)) {
                 throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
             }
             $this->setAuthentication($domain, $token, 'x-oauth-basic');
         }
     }
     if ($tokens = $config->get('gitlab-oauth')) {
         foreach ($tokens as $domain => $token) {
             $this->setAuthentication($domain, $token, 'oauth2');
         }
     }
     // reload http basic credentials from config if available
     if ($creds = $config->get('http-basic')) {
         foreach ($creds as $domain => $cred) {
             $this->setAuthentication($domain, $cred['username'], $cred['password']);
         }
     }
     // setup process timeout
     ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
 }
    protected function setUp()
    {
        /* @var IOInterface $io */
        $io = $this->getMock('Composer\IO\IOInterface');
        $config = new Config();
        $config->merge(array(
            'config' => array(
                'home' => sys_get_temp_dir() . '/composer-test',
                'cache-repo-dir' => sys_get_temp_dir() . '/composer-test-cache-repo',
            ),
        ));
        $rm = new RepositoryManager($io, $config);
        $rm->setRepositoryClass($this->getType() . '-vcs', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\MockAssetRepository');
        $repoConfig = array(
            'repository-manager' => $rm,
            'asset-options' => array(
                'searchable' => true,
            ),
        );

        $this->io = $io;
        $this->config = $config;
        $this->rm = $rm;
        $this->registry = $this->getRegistry($repoConfig, $io, $config);
        $this->pool = $this->getMock('Composer\DependencyResolver\Pool');
    }
 protected function setUp()
 {
     $this->fs = new Filesystem();
     $that = $this;
     $this->workingDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'cmptest-' . md5(uniqid('', true));
     $this->fs->ensureDirectoryExists($this->workingDir);
     $this->vendorDir = $this->workingDir . DIRECTORY_SEPARATOR . 'composer-test-autoload';
     $this->ensureDirectoryExistsAndClear($this->vendorDir);
     $this->config = $this->getMock('Composer\\Config');
     $this->configValueMap = array('vendor-dir' => function () use($that) {
         return $that->vendorDir;
     });
     $this->config->expects($this->atLeastOnce())->method('get')->will($this->returnCallback(function ($arg) use($that) {
         $ret = null;
         if (isset($that->configValueMap[$arg])) {
             $ret = $that->configValueMap[$arg];
             if (is_callable($ret)) {
                 $ret = $ret();
             }
         }
         return $ret;
     }));
     $this->origDir = getcwd();
     chdir($this->workingDir);
     $this->im = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock();
     $this->im->expects($this->any())->method('getInstallPath')->will($this->returnCallback(function ($package) use($that) {
         $targetDir = $package->getTargetDir();
         return $that->vendorDir . '/' . $package->getName() . ($targetDir ? '/' . $targetDir : '');
     }));
     $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface');
     $this->eventDispatcher = $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $this->generator = new AutoloadGenerator($this->eventDispatcher);
 }
예제 #8
0
 protected function getConfig()
 {
     $config = new Config();
     $settings = array('config' => array('home' => $this->testPath));
     $config->merge($settings);
     return $config;
 }
예제 #9
0
 protected function setUp()
 {
     $this->fs = new Filesystem();
     $this->composer = new Composer();
     $this->config = new Config();
     $this->composer->setConfig($this->config);
     $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor';
     $this->ensureDirectoryExistsAndClear($this->vendorDir);
     $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-bin';
     $this->ensureDirectoryExistsAndClear($this->binDir);
     $this->config->merge(array('config' => array('vendor-dir' => $this->vendorDir, 'bin-dir' => $this->binDir)));
     $this->dm = $this->getMockBuilder('Composer\\Downloader\\DownloadManager')->disableOriginalConstructor()->getMock();
     /* @var DownloadManager $dm */
     $dm = $this->dm;
     $this->composer->setDownloadManager($dm);
     $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface');
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->type = $this->getMock('Fxp\\Composer\\AssetPlugin\\Type\\AssetTypeInterface');
     $this->type->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $this->type->expects($this->any())->method('getComposerVendorName')->will($this->returnValue('foo-asset'));
     $this->type->expects($this->any())->method('getComposerType')->will($this->returnValue('foo-asset-library'));
     $this->type->expects($this->any())->method('getFilename')->will($this->returnValue('foo.json'));
     $this->type->expects($this->any())->method('getVersionConverter')->will($this->returnValue($this->getMock('Fxp\\Composer\\AssetPlugin\\Converter\\VersionConverterInterface')));
     $this->type->expects($this->any())->method('getPackageConverter')->will($this->returnValue($this->getMock('Fxp\\Composer\\AssetPlugin\\Converter\\PackageConverterInterface')));
 }
예제 #10
0
 public function __construct(SVNRepositoryConfig $repoConfig, IOInterface $io, Config $config)
 {
     // @TODO: add event dispatcher?
     $this->repoConfig = $repoConfig;
     $this->plugin = $repoConfig->getPlugin();
     // check url immediately - can't do anything without it
     $urls = [];
     foreach ((array) $repoConfig->get('url') as $url) {
         if (($urlParts = parse_url($url)) === false || empty($urlParts['scheme'])) {
             continue;
         }
         // untrailingslashit
         $urls[] = rtrim($url, '/');
     }
     if (!count($urls)) {
         throw new \UnexpectedValueException('No valid URLs for SVN repository: ' . print_r($repoConfig->get('url'), true));
     }
     $repoConfig->set('url', $urls);
     // use the cache TTL from the config?
     if ($repoConfig->get('cache-ttl') === 'config') {
         $repoConfig->set('cache-ttl', $config->get('cache-files-ttl'));
     }
     $this->io = $io;
     $this->cache = new Cache($io, $config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', reset($urls)));
     $this->loader = new ArrayLoader();
     // clear out stale cache
     $this->cache->gc($repoConfig->get('cache-ttl'), $config->get('cache-files-maxsize'));
     $this->vendors = $repoConfig->get('vendors');
     $this->defaultVendor = key($this->vendors);
     // create an SvnUtil to execute commands
     $this->svnUtil = new SvnUtil($io, $repoConfig->get('trust-cert'));
 }
예제 #11
0
 /**
  * @param string $origin domain text
  * @param string $url
  * @param IO\IOInterface $io
  * @param CConfig $config
  * @param array $pluginConfig
  * @return Aspects\HttpGetRequest
  */
 public static function getHttpGetRequest($origin, $url, IO\IOInterface $io, CConfig $config, array $pluginConfig)
 {
     if (substr($origin, -10) === 'github.com') {
         $origin = 'github.com';
         $requestClass = 'GitHub';
     } elseif (in_array($origin, $config->get('github-domains') ?: array())) {
         $requestClass = 'GitHub';
     } elseif (in_array($origin, $config->get('gitlab-domains') ?: array())) {
         $requestClass = 'GitLab';
     } else {
         $requestClass = 'HttpGet';
     }
     $requestClass = __NAMESPACE__ . '\\Aspects\\' . $requestClass . 'Request';
     $request = new $requestClass($origin, $url, $io);
     $request->verbose = $pluginConfig['verbose'];
     if ($pluginConfig['insecure']) {
         $request->curlOpts[CURLOPT_SSL_VERIFYPEER] = false;
     }
     if (!empty($pluginConfig['capath'])) {
         $request->curlOpts[CURLOPT_CAPATH] = $pluginConfig['capath'];
     }
     if (!empty($pluginConfig['userAgent'])) {
         $request->curlOpts[CURLOPT_USERAGENT] = $pluginConfig['userAgent'];
     }
     return $request;
 }
예제 #12
0
 /**
  * @return string[]
  */
 public function scan()
 {
     $parameters = ['command' => 'dump-autoload', '--no-interaction' => true, '--working-dir' => $this->directory, '--optimize' => true, '--no-dev' => true];
     $this->createComposerApplication()->run(new ArrayInput($parameters), $this->output);
     $config = new Config(true, $this->directory);
     return require $config->get('vendor-dir') . '/composer/autoload_classmap.php';
 }
예제 #13
0
 /**
  * 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;
 }
예제 #14
0
 public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
 {
     if (!preg_match('{^[\\w.]+\\??://}', $repoConfig['url'])) {
         // assume http as the default protocol
         $repoConfig['url'] = 'http://' . $repoConfig['url'];
     }
     $repoConfig['url'] = rtrim($repoConfig['url'], '/');
     if ('https?' === substr($repoConfig['url'], 0, 6)) {
         $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
     }
     $urlBits = parse_url($repoConfig['url']);
     if ($urlBits === false || empty($urlBits['scheme'])) {
         throw new \UnexpectedValueException('Invalid url given for Composer repository: ' . $repoConfig['url']);
     }
     if (!isset($repoConfig['options'])) {
         $repoConfig['options'] = array();
     }
     if (isset($repoConfig['allow_ssl_downgrade']) && true === $repoConfig['allow_ssl_downgrade']) {
         $this->allowSslDowngrade = true;
     }
     $this->config = $config;
     $this->options = $repoConfig['options'];
     $this->url = $repoConfig['url'];
     $this->baseUrl = rtrim(preg_replace('{^(.*)(?:/packages.json)?(?:[?#].*)?$}', '$1', $this->url), '/');
     $this->io = $io;
     $this->cache = new Cache($io, $config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
     $this->loader = new ArrayLoader();
     $this->rfs = new RemoteFilesystem($this->io, $this->config, $this->options);
     $this->eventDispatcher = $eventDispatcher;
 }
예제 #15
0
 /**
  * @param IO\IOInterface $io
  * @param Config $config
  * @param Operation\OperationInterface[] $ops
  */
 public function fetchAllFromOperations(IO\IOInterface $io, Config $config, array $ops)
 {
     $cachedir = rtrim($config->get('cache-files-dir'), '\\/');
     $requests = array();
     foreach ($ops as $op) {
         switch ($op->getJobType()) {
             case 'install':
                 $p = $op->getPackage();
                 break;
             case 'update':
                 $p = $op->getTargetPackage();
                 break;
             default:
                 continue 2;
         }
         $url = $this->getUrlFromPackage($p);
         if (!$url) {
             continue;
         }
         $destination = $cachedir . DIRECTORY_SEPARATOR . FileDownloaderDummy::getCacheKeyCompat($p, $url);
         if (file_exists($destination)) {
             continue;
         }
         $useRedirector = (bool) preg_match('%^(?:https|git)://github\\.com%', $p->getSourceUrl());
         try {
             $request = new CopyRequest($url, $destination, $useRedirector, $io, $config);
             $requests[] = $request;
         } catch (FetchException $e) {
             // do nothing
         }
     }
     if (count($requests) > 0) {
         $this->fetchAll($io, $requests);
     }
 }
예제 #16
0
 /**
  * @return Config
  */
 public static function createConfig()
 {
     // load main Composer configuration
     if (!($home = getenv('COMPOSER_HOME'))) {
         if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
             $home = getenv('APPDATA') . '/Composer';
         } else {
             $home = getenv('HOME') . '/.composer';
         }
     }
     // Protect directory against web access
     if (!file_exists($home . '/.htaccess')) {
         if (!is_dir($home)) {
             @mkdir($home, 0777, true);
         }
         @file_put_contents($home . '/.htaccess', 'Deny from all');
     }
     $config = new Config();
     $file = new JsonFile($home . '/config.json');
     if ($file->exists()) {
         $config->merge($file->read());
     }
     // add home dir to the config
     $config->merge(array('config' => array('home' => $home)));
     return $config;
 }
예제 #17
0
 public function testOverrideGithubProtocols()
 {
     $config = new Config(false);
     $config->merge(array('config' => array('github-protocols' => array('https', 'git'))));
     $config->merge(array('config' => array('github-protocols' => array('https'))));
     $this->assertEquals(array('https'), $config->get('github-protocols'));
 }
예제 #18
0
 /**
  * testRequireJson
  *
  * @dataProvider providerRequireJson
  */
 public function testRequireJson(array $packages, array $config, $expected = null)
 {
     $configObject = new Config();
     $configObject->merge(array('config' => $config));
     $this->composer->setConfig($configObject);
     $this->process->init();
     $result = $this->process->requireJson($packages);
     $this->assertEquals($result, $expected, sprintf('Fail to get proper expected require.js configuration'));
 }
예제 #19
0
 /**
  * @dataProvider dataAddPackagistRepository
  */
 public function testAddPackagistRepository($expected, $localConfig, $systemConfig = null)
 {
     $config = new Config();
     if ($systemConfig) {
         $config->merge(array('repositories' => $systemConfig));
     }
     $config->merge(array('repositories' => $localConfig));
     $this->assertEquals($expected, $config->getRepositories());
 }
예제 #20
0
 public function setUp()
 {
     $this->config = new Config();
     $this->config->merge(array(
         'config' => array(
             'home'           => sys_get_temp_dir() . '/composer-test',
             'cache-repo-dir' => sys_get_temp_dir() . '/composer-test-cache',
         ),
     ));
 }
예제 #21
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     // Run through the Library Installer Test set up.
     parent::setUp();
     // Also be sure to set up the Component directory.
     $this->componentDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-component';
     $this->ensureDirectoryExistsAndClear($this->componentDir);
     // Merge the component-dir setting in so that it applies correctly.
     $this->config->merge(array('config' => array('component-dir' => $this->componentDir)));
 }
예제 #22
0
 public function getClassmap() : \Traversable
 {
     $filesystem = new Filesystem();
     $vendorPath = $filesystem->normalizePath(realpath($this->config->get('vendor-dir')));
     $classmapPath = $vendorPath . '/composer/autoload_classmap.php';
     if (!is_file($classmapPath)) {
         throw new \RuntimeException('Th dumped classmap does not exists. Try to run `composer dump-autoload --optimize` first.');
     }
     yield from (include $vendorPath . '/composer/autoload_classmap.php');
 }
예제 #23
0
 public function testCredentialsFromConfig()
 {
     $url = 'http://svn.apache.org';
     $config = new Config();
     $config->merge(array('config' => array('http-basic' => array('svn.apache.org' => array('username' => 'foo', 'password' => 'bar')))));
     $svn = new Svn($url, new NullIO(), $config);
     $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
     $reflMethod->setAccessible(true);
     $this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
 }
예제 #24
0
 public function loadConfiguration(Config $config)
 {
     if ($tokens = $config->get('github-oauth')) {
         foreach ($tokens as $domain => $token) {
             if (!preg_match('{^[a-z0-9]+$}', $token)) {
                 throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
             }
             $this->setAuthentication($domain, $token, 'x-oauth-basic');
         }
     }
 }
예제 #25
0
 public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, RemoteFilesystem $rfs = null, Filesystem $filesystem = null)
 {
     $this->io = $io;
     $this->config = $config;
     $this->eventDispatcher = $eventDispatcher;
     $this->rfs = $rfs ?: new RemoteFilesystem($io);
     $this->filesystem = $filesystem ?: new Filesystem();
     $this->cache = $cache;
     if ($this->cache && $this->cache->gcIsNecessary()) {
         $this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
     }
 }
예제 #26
0
 /**
  * Constructor.
  *
  * @param IOInterface      $io         The IO instance
  * @param Config           $config     The config
  * @param Cache            $cache      Optional cache instance
  * @param RemoteFilesystem $rfs        The remote filesystem
  * @param Filesystem       $filesystem The filesystem
  */
 public function __construct(IOInterface $io, Config $config, Cache $cache = null, RemoteFilesystem $rfs = null, Filesystem $filesystem = null)
 {
     $this->io = $io;
     $this->config = $config;
     $this->rfs = $rfs ?: new RemoteFilesystem($io);
     $this->filesystem = $filesystem ?: new Filesystem();
     $this->cache = $cache;
     if ($this->cache && !self::$cacheCollected && !mt_rand(0, 50)) {
         $this->cache->gc($config->get('cache-ttl'), $config->get('cache-files-maxsize'));
     }
     self::$cacheCollected = true;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->localConfigPath = realpath(__DIR__ . '/../fixtures/local');
     $this->globalConfigPath = realpath(__DIR__ . '/../fixtures/home');
     $this->config = new Config(false, $this->localConfigPath);
     $this->config->merge(['config' => ['home' => $this->globalConfigPath]]);
     $package = new RootPackage('my/project', '1.0.0', '1.0.0');
     $package->setExtra(['my-local-config' => ['foo' => 'bar']]);
     $this->composer = new Composer();
     $this->composer->setConfig($this->config);
     $this->composer->setPackage($package);
     $this->SUT = new ConfigLocator($this->composer);
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 public function init()
 {
     // Retrieve the configuration variables.
     $this->config = $this->composer->getConfig();
     if (isset($this->config)) {
         if ($this->config->has('component-dir')) {
             $this->componentDir = $this->config->get('component-dir');
         }
     }
     // Get the available packages.
     $allPackages = array();
     /** @var \Composer\Package\Locker $locker */
     $locker = $this->composer->getLocker();
     if ($locker !== null && $locker->isLocked()) {
         $lockData = $locker->getLockData();
         $allPackages = $lockData['packages'];
         // Also merge in any of the development packages.
         $dev = isset($lockData['packages-dev']) ? $lockData['packages-dev'] : array();
         foreach ($dev as $package) {
             $allPackages[] = $package;
         }
     }
     // Only add those packages that we can reasonably
     // assume are components into our packages list
     /** @var \Composer\Package\RootPackageInterface $rootPackage */
     $rootPackage = $this->composer->getPackage();
     $rootExtras = $rootPackage ? $rootPackage->getExtra() : array();
     $customComponents = isset($rootExtras['component']) ? $rootExtras['component'] : array();
     foreach ($allPackages as $package) {
         $name = $package['name'];
         if (isset($customComponents[$name]) && is_array($customComponents[$name])) {
             $package['extra'] = array('component' => $customComponents[$name]);
             $this->packages[] = $package;
         } else {
             $extra = isset($package['extra']) ? $package['extra'] : array();
             if (isset($extra['component']) && is_array($extra['component'])) {
                 $this->packages[] = $package;
             }
         }
     }
     // Add the root package to the packages list.
     $root = $this->composer->getPackage();
     if ($root) {
         $dumper = new ArrayDumper();
         $package = $dumper->dump($root);
         $package['is-root'] = true;
         $this->packages[] = $package;
     }
     return true;
 }
예제 #29
0
 public function testDownloadUsesCustomVariousProtocolsForGithub()
 {
     $packageMock = $this->getMock('Composer\\Package\\PackageInterface');
     $packageMock->expects($this->any())->method('getSourceReference')->will($this->returnValue('ref'));
     $packageMock->expects($this->any())->method('getSourceUrl')->will($this->returnValue('https://github.com/composer/composer'));
     $packageMock->expects($this->any())->method('getPrettyVersion')->will($this->returnValue('1.0.0'));
     $processExecutor = $this->getMock('Composer\\Util\\ProcessExecutor');
     $expectedGitCommand = $this->getCmd("git clone 'http://github.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'http://github.com/composer/composer' && git fetch composer");
     $processExecutor->expects($this->at(0))->method('execute')->with($this->equalTo($expectedGitCommand))->will($this->returnValue(0));
     $processExecutor->expects($this->exactly(4))->method('execute')->will($this->returnValue(0));
     $config = new Config();
     $config->merge(array('config' => array('github-protocols' => array('http'))));
     $downloader = $this->getDownloaderMock(null, $config, $processExecutor);
     $downloader->download($packageMock, 'composerPath');
 }
예제 #30
0
 public function __construct(array $repoConfig, IOInterface $io, Config $config)
 {
     if (!preg_match('{^\\w+://}', $repoConfig['url'])) {
         // assume http as the default protocol
         $repoConfig['url'] = 'http://' . $repoConfig['url'];
     }
     $repoConfig['url'] = rtrim($repoConfig['url'], '/');
     if (function_exists('filter_var') && !filter_var($repoConfig['url'], FILTER_VALIDATE_URL)) {
         throw new \UnexpectedValueException('Invalid url given for Composer repository: ' . $repoConfig['url']);
     }
     $this->config = $config;
     $this->url = $repoConfig['url'];
     $this->io = $io;
     $this->cache = new Cache($io, $config->get('home') . '/cache/' . preg_replace('{[^a-z0-9.]}', '-', $this->url));
 }