예제 #1
0
파일: Environment.php 프로젝트: Jobu/core
 /**
  * Returns a list of Contao paths.
  * Multiple paths mean there's likely a problem with the installation (e.g. Contao in root and vendor folder).
  *
  * @param RootPackageInterface $package The package to check if a root has been specified in the extra section.
  *
  * @return array
  *
  * @throws RuntimeException When the current working directory could not be determined.
  */
 public static function findContaoRoots(RootPackageInterface $package = null)
 {
     $roots = array();
     $cwd = getcwd();
     if (!$cwd) {
         throw new RuntimeException('Could not determine current working directory.');
     }
     // Check if we have a Contao installation in the current working dir. See #15.
     if (static::isContao($cwd)) {
         $roots['root'] = $cwd;
     }
     if (static::isContao(dirname($cwd))) {
         $roots['parent'] = dirname($cwd);
     }
     if (null !== $package) {
         $extra = $package->getExtra();
         if (!empty($extra['contao']['root']) && static::isContao($cwd . DIRECTORY_SEPARATOR . $extra['contao']['root'])) {
             $roots['extra'] = $cwd . DIRECTORY_SEPARATOR . $extra['contao']['root'];
         }
     }
     // test, do we have the core within vendor/contao/core.
     $vendorRoot = $cwd . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'contao' . DIRECTORY_SEPARATOR . 'core';
     if (static::isContao($vendorRoot)) {
         $roots['vendor'] = $vendorRoot;
     }
     return $roots;
 }
 /**
  * Returns the version for the given package either from the "require" or "require-dev" packages array.
  *
  * @param RootPackageInterface $package
  * @param string $packageName
  * @throws \RuntimeException
  * @return mixed
  */
 public static function getRequiredVersion(RootPackageInterface $package, $packageName = 'jerome-breton/casperjs-installer')
 {
     foreach (array($package->getRequires(), $package->getDevRequires()) as $requiredPackages) {
         if (isset($requiredPackages[$packageName])) {
             return $requiredPackages[$packageName]->getPrettyConstraint();
         }
     }
     throw new \RuntimeException('Can not determine required version of ' . $packageName);
 }
 /**
  *
  * @param PackageInterface $package        	
  *
  * @return string a path relative to the root of the composer.json that is being installed.
  */
 public function getInstallPath(PackageInterface $package)
 {
     // custom install path only when it is the keeko/keeko package
     if ($this->root->getName() == 'keeko/keeko') {
         return 'packages/' . $package->getName();
     }
     // ... anyway return the default
     return parent::getInstallPath($package);
 }
예제 #4
0
 /**
  * Get extra config.
  *
  * @param  \Composer\Package\RootPackageInterface    $root
  * @param  \Arcanedev\Composer\Entities\PluginState  $state
  * @param  array                                     $extra
  *
  * @return array
  */
 private function getExtra(RootPackageInterface $root, PluginState $state, $extra)
 {
     $rootExtra = $root->getExtra();
     if ($state->replaceDuplicateLinks()) {
         return self::mergeExtraArray($state->shouldMergeExtraDeep(), $rootExtra, $extra);
     }
     if (!$state->shouldMergeExtraDeep()) {
         foreach (array_intersect(array_keys($extra), array_keys($rootExtra)) as $key) {
             $this->getLogger()->info("Ignoring duplicate <comment>{$key}</comment> in " . "<comment>{$this->getPath()}</comment> extra config.");
         }
     }
     return static::mergeExtraArray($state->shouldMergeExtraDeep(), $extra, $rootExtra);
 }
예제 #5
0
 /**
  * Initialize.
  */
 protected function initialize()
 {
     $this->requires = array_merge(
         $this->package->getRequires(),
         $this->package->getDevRequires()
     );
 }
 /**
  * @test
  */
 public function removePackageUsageWithData()
 {
     $this->initializePackageData();
     $dataManager = new SharedPackageDataManager($this->composer);
     $dataManager->setVendorDir($this->vendorDir);
     $this->rootPackage->expects($this->exactly(2))->method('getName')->will($this->onConsecutiveCalls('letudiant/root-package', 'letudiant/root-package2'));
     $package = $this->getMock('Composer\\Package\\PackageInterface');
     $package->expects($this->exactly(4))->method('getPrettyName')->willReturn('letudiant/foo-bar');
     $package->expects($this->exactly(4))->method('getPrettyVersion')->willReturn('dev-develop');
     $package->expects($this->exactly(0))->method('getInstallationSource');
     // Remove the right package
     $this->initializePackageData();
     $dataManager->removePackageUsage($package);
     $this->assertFileExists($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $content = file_get_contents($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $this->assertJson($content);
     $this->assertEquals(array(), json_decode($content, true));
     // Remove another package, should not remove the initial package
     $this->initializePackageData();
     $dataManager = new SharedPackageDataManager($this->composer);
     $dataManager->setVendorDir($this->vendorDir);
     $dataManager->removePackageUsage($package);
     $this->assertFileExists($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $content = file_get_contents($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $this->assertJson($content);
     $this->assertEquals(array('letudiant/foo-bar/dev-develop' => array('installation-source' => 'source', 'project-usage' => array('letudiant/root-package'))), json_decode($content, true));
 }
 public function testCreateWithCustomIgnoreSection()
 {
     $extra = array('custom-ignore-files' => array('foo-asset/foo' => array('PATTERN'), 'foo-asset/bar' => array()));
     $this->rootPackage->expects($this->any())->method('getExtra')->will($this->returnValue($extra));
     $manager = IgnoreFactory::create($this->composer, $this->package, null, 'custom-ignore-files');
     $this->assertTrue($manager->isEnabled());
     $this->assertTrue($manager->hasPattern());
     $this->validateInstallDir($manager, $this->config->get('vendor-dir') . '/' . $this->package->getName());
 }
 /**
  * Initialize the installed package.
  */
 private function initInstalledPackages()
 {
     /* @var PackageInterface $package */
     foreach ($this->installedRepository->getPackages() as $package) {
         $operator = $this->getFilterOperator($package);
         /* @var Link $link */
         $link = current($this->arrayLoader->parseLinks($this->package->getName(), $this->package->getVersion(), 'installed', array($package->getName() => $operator . $package->getPrettyVersion())));
         $link = $this->includeRootConstraint($package, $link);
         $this->requires[$package->getName()] = $link;
     }
 }
예제 #9
0
 private function getRootAliases()
 {
     if (!$this->update && $this->locker->isLocked()) {
         $aliases = $this->locker->getAliases();
     } else {
         $aliases = $this->package->getAliases();
     }
     $normalizedAliases = array();
     foreach ($aliases as $alias) {
         $normalizedAliases[$alias['package']][$alias['version']] = array('alias' => $alias['alias'], 'alias_normalized' => $alias['alias_normalized']);
     }
     return $normalizedAliases;
 }
예제 #10
0
 /**
  * Determine the constraint defined for a given package (if required via root project).
  *
  * @param string $packageName The name of the package to retrieve the constraint for.
  *
  * @return string|null
  */
 private function getConstraint($packageName)
 {
     $requires = $this->rootPackage->getRequires();
     if (isset($requires[$packageName])) {
         /** @var Link $link */
         $link = $requires[$packageName];
         return $link->getConstraint()->getPrettyString();
     }
     foreach ($requires as $link) {
         /** @var Link $link */
         if ($link->getTarget() == $packageName) {
             return $link->getConstraint()->getPrettyString();
         }
     }
     return null;
 }
예제 #11
0
 /**
  * @param Pool                        $pool
  * @param PolicyInterface             $policy
  * @param WritableRepositoryInterface $localRepo
  * @param array                       $repositories
  */
 private function processPackageUrls($pool, $policy, $localRepo, $repositories)
 {
     if (!$this->update) {
         return;
     }
     $rootRefs = $this->package->getReferences();
     foreach ($localRepo->getCanonicalPackages() as $package) {
         // find similar packages (name/version) in all repositories
         $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()));
         foreach ($matches as $index => $match) {
             // skip local packages
             if (!in_array($match->getRepository(), $repositories, true)) {
                 unset($matches[$index]);
                 continue;
             }
             // skip providers/replacers
             if ($match->getName() !== $package->getName()) {
                 unset($matches[$index]);
                 continue;
             }
             $matches[$index] = $match->getId();
         }
         // select preferred package according to policy rules
         if ($matches && ($matches = $policy->selectPreferredPackages($pool, array(), $matches))) {
             $newPackage = $pool->literalToPackage($matches[0]);
             // update the dist and source URLs
             $sourceUrl = $package->getSourceUrl();
             $newSourceUrl = $newPackage->getSourceUrl();
             $newReference = $newPackage->getSourceReference();
             if ($package->isDev() && isset($rootRefs[$package->getName()]) && $package->getSourceReference() === $rootRefs[$package->getName()]) {
                 $newReference = $rootRefs[$package->getName()];
             }
             $this->updatePackageUrl($package, $newSourceUrl, $newPackage->getSourceType(), $newReference, $newPackage->getDistUrl());
             if ($package instanceof CompletePackage && $newPackage instanceof CompletePackage) {
                 $package->setAbandoned($newPackage->getReplacementPackage() ?: $newPackage->isAbandoned());
             }
         }
     }
 }
예제 #12
0
 /**
  * @param array $tag
  * @param string $current_version
  * @param int $result
  *
  * @return UpdateCommand
  */
 protected function getCommandToExecute(array $tag, $current_version, $result)
 {
     $that = $this;
     $installer = $this->getMockBuilder('\\Composer\\Installer')->disableOriginalConstructor()->getMock();
     $installer->expects($this->once())->method('run')->will($this->returnValue($result));
     $this->container->expects($that->at(0))->method('get')->will($this->returnValue($this->composer))->with('anime_db.composer');
     $this->container->expects($that->at(1))->method('get')->will($this->returnValue($this->github))->with('anime_db.client.github');
     $this->composer->expects($this->once())->method('setIO')->will($this->returnCallback(function ($io) use($that) {
         $that->assertInstanceOf('\\Composer\\IO\\ConsoleIO', $io);
     }));
     $this->github->expects($this->once())->method('getLastRelease')->will($this->returnValue($tag))->with('anime-db/anime-db');
     $this->composer->expects($this->atLeastOnce())->method('getRootPackage')->will($this->returnValue($this->package));
     $this->composer->expects($this->once())->method('getInstaller')->will($this->returnValue($installer));
     $this->package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue($current_version));
     /* @var $helper_set HelperSet */
     $helper_set = $this->getMockBuilder('\\Symfony\\Component\\Console\\Helper\\HelperSet')->disableOriginalConstructor()->getMock();
     $this->output->expects($this->at(0))->method('writeln')->with('Search for a new version of the application');
     $command = new UpdateCommand();
     $command->setHelperSet($helper_set);
     $command->setContainer($this->container);
     return $command;
 }
 /**
  * Update Links with a 'self.version' constraint with the root package's
  * version.
  *
  * @param string $type Link type
  * @param array $links
  * @param RootPackageInterface $root
  * @return array
  */
 protected function replaceSelfVersionDependencies($type, array $links, RootPackageInterface $root)
 {
     $linkType = BasePackage::$supportedLinkTypes[$type];
     $version = $root->getVersion();
     $prettyVersion = $root->getPrettyVersion();
     $vp = $this->versionParser;
     return array_map(function ($link) use($linkType, $version, $prettyVersion, $vp) {
         if ('self.version' === $link->getPrettyConstraint()) {
             return new Link($link->getSource(), $link->getTarget(), $vp->parseConstraints($version), $linkType['description'], $prettyVersion);
         }
         return $link;
     }, $links);
 }
 private function getRootAliases(RootPackageInterface $rootPackage)
 {
     $aliases = $rootPackage->getAliases();
     $normalizedAliases = array();
     foreach ($aliases as $alias) {
         $normalizedAliases[$alias['package']][$alias['version']] = array('alias' => $alias['alias'], 'alias_normalized' => $alias['alias_normalized']);
     }
     return $normalizedAliases;
 }
예제 #15
0
 /**
  * Returns the version for the given package either from the "require" or "require-dev" packages array.
  *
  * @param RootPackageInterface $package
  * @param string $packageName
  * @throws \RuntimeException
  * @return mixed
  */
 public static function getRequiredVersion(RootPackageInterface $package)
 {
     foreach (array($package->getRequires(), $package->getDevRequires()) as $requiredPackages) {
         if (isset($requiredPackages[self::PACKAGE_NAME])) {
             return $requiredPackages[self::PACKAGE_NAME]->getPrettyConstraint();
         }
     }
     throw new \RuntimeException('Can not determine required version of ' . self::PACKAGE_NAME);
 }
예제 #16
0
 /**
  * Rewrites the class map to have lowercased keys to be able to load classes with wrong casing
  * Defaults to case sensitivity (composer loader default)
  *
  * @param RootPackageInterface $mainPackage
  * @param string $targetDir
  * @return bool
  */
 protected static function caseSensitiveClassLoading(RootPackageInterface $mainPackage, $targetDir)
 {
     $extra = $mainPackage->getExtra();
     $caseSensitiveClassLoading = true;
     if (isset($extra['autoload-case-sensitivity'])) {
         $caseSensitiveClassLoading = (bool) $extra['autoload-case-sensitivity'];
     }
     if (!$caseSensitiveClassLoading) {
         $classMapContents = file_get_contents($targetDir . '/autoload_classmap.php');
         $classMapContents = preg_replace_callback('/    \'[^\']*\' => /', function ($match) {
             return strtolower($match[0]);
         }, $classMapContents);
         file_put_contents($targetDir . '/autoload_classmap.php', $classMapContents);
     }
     return $caseSensitiveClassLoading;
 }
 /**
  * Update Links with a 'self.version' constraint with the root package's
  * version.
  *
  * @param string $type Link type
  * @param array $links
  * @param RootPackageInterface $root
  * @return array
  */
 protected function replaceSelfVersionDependencies($type, array $links, RootPackageInterface $root)
 {
     $linkType = BasePackage::$supportedLinkTypes[$type];
     $version = $root->getVersion();
     $prettyVersion = $root->getPrettyVersion();
     $vp = $this->versionParser;
     $method = 'get' . ucfirst($linkType['method']);
     $packages = $root->{$method}();
     return array_map(function ($link) use($linkType, $version, $prettyVersion, $vp, $packages) {
         if ('self.version' === $link->getPrettyConstraint()) {
             if (isset($packages[$link->getSource()])) {
                 /** @var Link $package */
                 $package = $packages[$link->getSource()];
                 return new Link($link->getSource(), $link->getTarget(), $vp->parseConstraints($package->getConstraint()->getPrettyString()), $linkType['description'], $package->getPrettyConstraint());
             }
             return new Link($link->getSource(), $link->getTarget(), $vp->parseConstraints($version), $linkType['description'], $prettyVersion);
         }
         return $link;
     }, $links);
 }
예제 #18
0
 protected function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo)
 {
     $request = new Request($pool);
     $constraint = new VersionConstraint('=', $rootPackage->getVersion());
     $constraint->setPrettyString($rootPackage->getPrettyVersion());
     $request->install($rootPackage->getName(), $constraint);
     $fixedPackages = $platformRepo->getPackages();
     /*if ($this->additionalInstalledRepository) {
     			$additionalFixedPackages = $this->additionalInstalledRepository->getPackages();
     			$fixedPackages = array_merge($fixedPackages, $additionalFixedPackages);
     		}*/
     // fix the version of all platform packages + additionally installed packages
     // to prevent the solver trying to remove or update those
     $provided = $rootPackage->getProvides();
     foreach ($fixedPackages as $package) {
         $constraint = new VersionConstraint('=', $package->getVersion());
         $constraint->setPrettyString($package->getPrettyVersion());
         // skip platform packages that are provided by the root package
         if ($package->getRepository() !== $platformRepo || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) {
             $request->install($package->getName(), $constraint);
         }
     }
     return $request;
 }
예제 #19
0
 /**
  * Check the extra option.
  *
  * @param RootPackageInterface $package The root package
  * @param string               $name    The extra option name
  *
  * @return bool
  */
 public static function checkExtraOption(RootPackageInterface $package, $name)
 {
     $extra = $package->getExtra();
     return !array_key_exists($name, $extra) || true === $extra[$name];
 }
예제 #20
0
 /**
  * @param Locker               $locker
  * @param RootPackageInterface $rootPackage
  *
  * @return \Generator|\string[]
  */
 private static function getVersions(Locker $locker, RootPackageInterface $rootPackage)
 {
     $lockData = $locker->getLockData();
     $lockData['packages-dev'] = isset($lockData['packages-dev']) ? $lockData['packages-dev'] : [];
     foreach (array_merge($lockData['packages'], $lockData['packages-dev']) as $package) {
         (yield $package['name'] => $package['version'] . '@' . (isset($package['source']['reference']) ? $package['source']['reference'] : (isset($package['dist']['reference']) ? $package['dist']['reference'] : '')));
     }
     (yield $rootPackage->getName() => $rootPackage->getVersion() . '@' . $rootPackage->getSourceReference());
 }
예제 #21
0
파일: FidoPlugin.php 프로젝트: rtens/fido
 private function processFetches(RootPackageInterface $package, $fetches)
 {
     $targets = array();
     $requires = $package->getRequires();
     foreach ($fetches as $key => $data) {
         if ($key == 'base-dir') {
             continue;
         }
         $data = $this->handleShortSyntax($key, $data);
         $name = $this->packageName($data['source']);
         try {
             $fetcher = $this->createFetcher($this->determineType($data));
             $targets += $fetcher->fetch($data, $name);
         } catch (\Exception $e) {
             throw new \Exception("Cannot fetch [{$key}]: " . $e->getMessage(), 0, $e);
         }
         $requires[$name] = new Link($package->getName(), $name);
     }
     $package->setRequires($requires);
     return $targets;
 }
예제 #22
0
 /**
  * @param Locker               $locker
  * @param RootPackageInterface $rootPackage
  *
  * @return \Generator|\string[]
  */
 private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) : \Generator
 {
     $lockData = $locker->getLockData();
     foreach (array_merge($lockData['packages'], $lockData['packages-dev']) as $package) {
         (yield $package['name'] => $package['version'] . '@' . $package['source']['reference']);
     }
     (yield $rootPackage->getName() => $rootPackage->getVersion() . '@' . $rootPackage->getSourceReference());
 }
예제 #23
0
 /**
  * Extract and merge stability flags from the given collection of
  * requires and merge them into a RootPackage.
  *
  * @param  \Composer\Package\RootPackageInterface  $root
  * @param  \Composer\Package\Link[]                $requires
  */
 protected function mergeStabilityFlags(RootPackageInterface $root, array $requires)
 {
     $flags = StabilityFlags::extract($root->getStabilityFlags(), $root->getMinimumStability(), $requires);
     self::unwrapIfNeeded($root, 'setStabilityFlags')->setStabilityFlags($flags);
 }
예제 #24
0
 /**
  * Add a collection of repositories described by the given configuration
  * to the given package and the global repository manager.
  *
  * @param array $repositories
  * @param RootPackageInterface $root
  */
 protected function addRepositories(array $repositories, RootPackageInterface $root)
 {
     $repoManager = $this->composer->getRepositoryManager();
     $newRepos = array();
     foreach ($repositories as $repoJson) {
         $this->debug("Adding {$repoJson['type']} repository");
         $repo = $repoManager->createRepository($repoJson['type'], $repoJson);
         $repoManager->addRepository($repo);
         $newRepos[] = $repo;
     }
     $root->setRepositories(array_merge($newRepos, $root->getRepositories()));
 }
 /**
  * Build a list of not yet installed packages.
  *
  * @param RepositoryInterface $repository
  *
  * @return array
  */
 public function buildNotInstalledList(RootPackageInterface $rootPackage, RepositoryInterface $localRepository)
 {
     $requires = $rootPackage->getRequires();
     $notInstalledList = array();
     /** @var Link $requiredConstraint */
     foreach ($requires as $requiredName => $requiredConstraint) {
         $packages = $localRepository->findPackages($requiredName);
         if (empty($packages)) {
             $notInstalledList[$requiredName] = $requiredConstraint;
         }
     }
     return $notInstalledList;
 }
예제 #26
0
 private function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo)
 {
     $request = new Request($pool);
     $constraint = new VersionConstraint('=', $rootPackage->getVersion());
     $constraint->setPrettyString($rootPackage->getPrettyVersion());
     $request->install($rootPackage->getName(), $constraint);
     $fixedPackages = $platformRepo->getPackages();
     if ($this->additionalInstalledRepository) {
         $additionalFixedPackages = $this->additionalInstalledRepository->getPackages();
         $fixedPackages = array_merge($fixedPackages, $additionalFixedPackages);
     }
     $provided = $rootPackage->getProvides();
     foreach ($fixedPackages as $package) {
         $constraint = new VersionConstraint('=', $package->getVersion());
         $constraint->setPrettyString($package->getPrettyVersion());
         if ($package->getRepository() !== $platformRepo || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) {
             $request->install($package->getName(), $constraint);
         }
     }
     return $request;
 }