public function testSetGetLocker()
 {
     $composer = new Composer();
     $locker = $this->getMockBuilder('Composer\\Package\\Locker')->disableOriginalConstructor()->getMock();
     $composer->setLocker($locker);
     $this->assertSame($locker, $composer->getLocker());
 }
Exemple #2
0
 /**
  * Creates a Composer instance
  *
  * @param  IOInterface $io          IO instance
  * @param  mixed       $localConfig either a configuration array or a filename to read from, if null it will read from the default filename
  * @return Composer
  */
 public function createComposer(IOInterface $io, $localConfig = null)
 {
     // load Composer configuration
     if (null === $localConfig) {
         $localConfig = $this->getComposerFile();
     }
     if (is_string($localConfig)) {
         $composerFile = $localConfig;
         $file = new JsonFile($localConfig, new RemoteFilesystem($io));
         if (!$file->exists()) {
             if ($localConfig === 'composer.json') {
                 $message = 'Composer could not find a composer.json file in ' . getcwd();
             } else {
                 $message = 'Composer could not find the config file: ' . $localConfig;
             }
             $instructions = 'To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section';
             throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
         }
         $file->validateSchema(JsonFile::LAX_SCHEMA);
         $localConfig = $file->read();
     }
     // Configuration defaults
     $config = static::createConfig();
     $config->merge($localConfig);
     $vendorDir = $config->get('vendor-dir');
     $binDir = $config->get('bin-dir');
     // setup process timeout
     ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
     // initialize repository manager
     $rm = $this->createRepositoryManager($io, $config);
     // load default repository unless it's explicitly disabled
     $localConfig = $this->addPackagistRepository($localConfig);
     // load local repository
     $this->addLocalRepository($rm, $vendorDir);
     // load package
     $loader = new Package\Loader\RootPackageLoader($rm);
     $package = $loader->load($localConfig);
     // initialize download manager
     $dm = $this->createDownloadManager($io);
     // initialize installation manager
     $im = $this->createInstallationManager($rm, $dm, $vendorDir, $binDir, $io);
     // purge packages if they have been deleted on the filesystem
     $this->purgePackages($rm, $im);
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     $composer->setPackage($package);
     $composer->setRepositoryManager($rm);
     $composer->setDownloadManager($dm);
     $composer->setInstallationManager($im);
     // init locker if possible
     if (isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Package\Locker(new JsonFile($lockFile, new RemoteFilesystem($io)), $rm, md5_file($composerFile));
         $composer->setLocker($locker);
     }
     return $composer;
 }
Exemple #3
0
 /**
  * Creates a Composer instance
  *
  * @return Composer
  */
 public function createComposer(IOInterface $io, $composerFile = null)
 {
     // load Composer configuration
     if (null === $composerFile) {
         $composerFile = getenv('COMPOSER') ?: 'composer.json';
     }
     $file = new JsonFile($composerFile);
     if (!$file->exists()) {
         if ($composerFile === 'composer.json') {
             $message = 'Composer could not find a composer.json file in ' . getcwd();
         } else {
             $message = 'Composer could not find the config file: ' . $composerFile;
         }
         $instructions = 'To initialize a project, please create a composer.json file as described on the http://packagist.org/ "Getting Started" section';
         throw new \InvalidArgumentException($message . PHP_EOL . $instructions);
     }
     // Configuration defaults
     $composerConfig = array('vendor-dir' => 'vendor', 'process-timeout' => 300);
     $packageConfig = $file->read();
     if (isset($packageConfig['config']) && is_array($packageConfig['config'])) {
         $packageConfig['config'] = array_merge($composerConfig, $packageConfig['config']);
     } else {
         $packageConfig['config'] = $composerConfig;
     }
     $vendorDir = getenv('COMPOSER_VENDOR_DIR') ?: $packageConfig['config']['vendor-dir'];
     if (!isset($packageConfig['config']['bin-dir'])) {
         $packageConfig['config']['bin-dir'] = $vendorDir . '/bin';
     }
     $binDir = getenv('COMPOSER_BIN_DIR') ?: $packageConfig['config']['bin-dir'];
     // setup process timeout
     $processTimeout = getenv('COMPOSER_PROCESS_TIMEOUT') ?: $packageConfig['config']['process-timeout'];
     ProcessExecutor::setTimeout((int) $processTimeout);
     // initialize repository manager
     $rm = $this->createRepositoryManager($io);
     // load default repository unless it's explicitly disabled
     $loadPackagist = true;
     if (isset($packageConfig['repositories'])) {
         foreach ($packageConfig['repositories'] as $repo) {
             if (isset($repo['packagist']) && $repo['packagist'] === false) {
                 $loadPackagist = false;
             }
         }
     }
     if ($loadPackagist) {
         $this->addPackagistRepository($rm);
     }
     // load local repository
     $this->addLocalRepository($rm, $vendorDir);
     // load package
     $loader = new Package\Loader\RootPackageLoader($rm);
     $package = $loader->load($packageConfig);
     // initialize download manager
     $dm = $this->createDownloadManager($io);
     // initialize installation manager
     $im = $this->createInstallationManager($rm, $dm, $vendorDir, $binDir, $io);
     // init locker
     $lockFile = substr($composerFile, -5) === '.json' ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
     $locker = new Package\Locker(new JsonFile($lockFile), $rm, md5_file($composerFile));
     // initialize composer
     $composer = new Composer();
     $composer->setPackage($package);
     $composer->setLocker($locker);
     $composer->setRepositoryManager($rm);
     $composer->setDownloadManager($dm);
     $composer->setInstallationManager($im);
     return $composer;
 }
Exemple #4
0
 public function createComposer()
 {
     $cwd = sprintf('%s/%s', getcwd(), '.eva');
     $factory = new Factory();
     if (false) {
         $composer = $factory->createComposer($this->io, $config, true, $cwd);
     }
     //  -----------------
     //  -----------------
     //  -----------------
     $fullLoad = true;
     $composerFile = $cwd . '/manifest.composer.json';
     $file = new JsonFile($composerFile);
     $file->validateSchema(JsonFile::LAX_SCHEMA);
     $localConfig = $file->read();
     //  -----------------
     //  -----------------
     //  -----------------
     // Load config and override with local config/auth config
     //        $config = Factory::createConfig($this->io, $cwd);
     $vendorDir = $cwd . '/manifests/vendor';
     $config = $factory::createConfig($this->io, $cwd);
     $config->merge($localConfig);
     $config->merge(['config' => ['vendor-dir' => $vendorDir]]);
     $localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
     if ($localAuthFile->exists()) {
         if ($this->io && $this->io->isDebug()) {
             $this->io->writeError('Loading config file ' . $localAuthFile->getPath());
         }
         $config->merge(array('config' => $localAuthFile->read()));
         $config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
     }
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     // initialize event dispatcher
     $dispatcher = new EventDispatcher($composer, $this->io);
     $composer->setEventDispatcher($dispatcher);
     // initialize repository manager
     //        $rm = $this->createRepositoryManager($io, $config, $dispatcher);
     //        $composer->setRepositoryManager($rm);
     $rm = new RepositoryManager($this->io, $config, $dispatcher);
     $rm->setRepositoryClass('composer', ComposerRepository::class);
     $composer->setRepositoryManager($rm);
     // load local repository
     $rm->setLocalRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
     // load package
     $parser = new VersionParser();
     $guesser = new VersionGuesser($config, new ProcessExecutor($this->io), $parser);
     $loader = new RootPackageLoader($rm, $config, $parser, $guesser);
     $package = $loader->load($localConfig);
     $composer->setPackage($package);
     // initialize installation manager
     $im = new InstallationManager();
     $composer->setInstallationManager($im);
     if ($fullLoad) {
         // initialize download manager
         $dm = $factory->createDownloadManager($this->io, $config, $dispatcher);
         $composer->setDownloadManager($dm);
         // initialize autoload generator
         $generator = new AutoloadGenerator($dispatcher, $this->io);
         $composer->setAutoloadGenerator($generator);
     }
     // add installers to the manager (must happen after download manager is created since they read it out of $composer)
     $im->addInstaller(new Installer\LibraryInstaller($this->io, $composer, null));
     $im->addInstaller(new Installer\PearInstaller($this->io, $composer, 'pear-library'));
     $im->addInstaller(new Installer\PluginInstaller($this->io, $composer));
     $im->addInstaller(new Installer\MetapackageInstaller($this->io));
     //        if ($fullLoad) {
     //            $globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
     //            $pm = $this->createPluginManager($io, $composer, $globalComposer);
     //            $composer->setPluginManager($pm);
     //
     //            if (!$disablePlugins) {
     //                $pm->loadInstalledPlugins();
     //            }
     //
     //            // once we have plugins and custom installers we can
     //            // purge packages from local repos if they have been deleted on the filesystem
     //            if ($rm->getLocalRepository()) {
     //                $this->purgePackages($rm->getLocalRepository(), $im);
     //            }
     //        }
     // init locker if possible
     if ($fullLoad && isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Locker($this->io, new JsonFile($lockFile, new RemoteFilesystem($this->io, $config)), $rm, $im, file_get_contents($composerFile));
         $composer->setLocker($locker);
     }
     //  -----------------
     //  -----------------
     //  -----------------
     return $composer;
 }