/** * {@inheritDoc} */ protected function getPackageBasePath(PackageInterface $package) { $ssp_path = '.'; $ssp_pack = $this->composer->getRepositoryManager()->getLocalRepository()->findPackage('simplesamlphp/simplesamlphp', '*'); if ($ssp_pack !== null) { $ssp_path = $this->composer->getInstallationManager()->getInstallPath($ssp_pack); } $name = $package->getPrettyName(); if (!preg_match('@^.*/simplesamlphp-module-(.+)$@', $name, $matches)) { throw new \InvalidArgumentException('Unable to install module ' . $name . ', package name must be on the form "VENDOR/simplesamlphp-module-MODULENAME".'); } $moduleDir = $matches[1]; if (!preg_match('@^[a-z0-9_.-]*$@', $moduleDir)) { throw new \InvalidArgumentException('Unable to install module ' . $name . ', module name must only contain characters from a-z, 0-9, "_", "." and "-".'); } if ($moduleDir[0] === '.') { throw new \InvalidArgumentException('Unable to install module ' . $name . ', module name cannot start with ".".'); } /* Composer packages are supposed to only contain lowercase letters, but historically many modules have had names in mixed case. * We must provide a way to handle those. Here we allow the module directory to be overridden with a mixed case name. */ $extraData = $package->getExtra(); if (isset($extraData['ssp-mixedcase-module-name'])) { $mixedCaseModuleName = $extraData['ssp-mixedcase-module-name']; if (!is_string($mixedCaseModuleName)) { throw new \InvalidArgumentException('Unable to install module ' . $name . ', "ssp-mixedcase-module-name" must be a string.'); } if (mb_strtolower($mixedCaseModuleName, 'utf-8') !== $moduleDir) { throw new \InvalidArgumentException('Unable to install module ' . $name . ', "ssp-mixedcase-module-name" must match the package name except that it can contain uppercase letters.'); } $moduleDir = $mixedCaseModuleName; } return $ssp_path . '/modules/' . $moduleDir; }
function run(PackageInterface $package, $isMain = true) { $extra = $package->getExtra(); if (!isset($extra['bower'])) { return; } if (isset($extra['bower']['dependencies']) and is_array($extra['bower']['dependencies'])) { foreach ($extra['bower']['dependencies'] as $package => $version) { $this->installPackage($package, $version); } } if (isset($extra['bower']['files']) and is_array($extra['bower']['files'])) { foreach ($extra['bower']['files'] as $file) { $path = getcwd() . "/" . $file; if (is_file($path)) { $bower = json_decode(file_get_contents($path)); if (isset($bower->dependencies)) { foreach ($bower->dependencies as $package => $version) { $this->installPackage($package, $version); } } } elseif ($isMain) { throw new \OutOfRangeException("File {$file} defined in composer section extra.bower.files does not exist on path: {$path}"); } } } }
/** * Gets the destination Component directory. * * @param PackageInterface $package * @return string * The path to where the final Component should be installed. */ public function getComponentPath(PackageInterface $package) { // Parse the pretty name for the vendor and package name. $name = $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); unset($vendor); } // First look for an override in root package's extra, then try the package's extra $rootPackage = $this->composer->getPackage(); $rootExtras = $rootPackage ? $rootPackage->getExtra() : array(); $customComponents = isset($rootExtras['component']) ? $rootExtras['component'] : array(); if (isset($customComponents[$prettyName]) && is_array($customComponents[$prettyName])) { $component = $customComponents[$prettyName]; } else { $extra = $package->getExtra(); $component = isset($extra['component']) ? $extra['component'] : array(); } // Allow the component to define its own name. if (isset($component['name'])) { $name = $component['name']; } // Find where the package should be located. return $this->getComponentDir() . DIRECTORY_SEPARATOR . $name; }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $ref = escapeshellarg($target->getSourceReference()); $path = escapeshellarg($path); $this->io->write(" Checking out " . $target->getSourceReference()); $this->process->execute(sprintf('cd %s && git fetch && git checkout %2$s && git reset --hard %2$s', $path, $ref), $ignoredOutput); }
/** * @param PackageInterface $package * @param bool $allowDevMaster * * @return \string[] */ public function validatePackage(PackageInterface $package, $allowDevMaster = false) { $errors = []; $versionParser = new VersionParser(); /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $devMaster = new Constraint('==', $versionParser->normalize('dev-master')); foreach ($package->getRequires() as $link) { $linkConstraint = $link->getConstraint(); if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) { continue; } if ($linkConstraint->matches($devMaster)) { if ($allowDevMaster) { continue; } $errors[] = sprintf('Package "%s" is required with branch constraint %s', $link->getTarget(), $linkConstraint->getPrettyString()); } $constraints = [$linkConstraint]; if ($linkConstraint instanceof MultiConstraint) { $constraints = (new ConstraintAccessor($linkConstraint))->getConstraints(); } foreach ($constraints as $constraint) { if ('dev-' === substr($constraint->getPrettyString(), 0, 4)) { $errors[] = sprintf('Package "%s" is required with branch constraint %s', $link->getTarget(), $linkConstraint->getPrettyString()); } } } return $errors; }
/** * {@inheritDoc} * * @throws \RuntimeException */ public function getPackageBasePath(PackageInterface $package) { $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { return 'plugins/' . $extra['installer-name']; } $primaryNS = null; $autoLoad = $package->getAutoload(); foreach ($autoLoad as $type => $pathMap) { if ($type !== 'psr-4') { continue; } $count = count($pathMap); if ($count === 1) { $primaryNS = key($pathMap); break; } $matches = preg_grep('#^(\\./)?src/?$#', $pathMap); if ($matches) { $primaryNS = key($matches); break; } foreach (['', '.'] as $path) { $key = array_search($path, $pathMap, true); if ($key !== false) { $primaryNS = $key; } } break; } if (!$primaryNS) { throw new \RuntimeException('Unable to get CakePHP plugin name.'); } return 'plugins/' . trim(str_replace('\\', '/', $primaryNS), '/'); }
/** * {@inheritdoc} */ public function getInstallPath(PackageInterface $package) { $this->initializeVendorDir(); $targetDir = $package->getTargetDir(); list(, $name) = explode('/', $package->getPrettyName(), 2); return ($this->vendorDir ? $this->vendorDir . '/' : '') . $name . ($targetDir ? '/' . $targetDir : ''); }
public function getInstallPath(PackageInterface $package) { $packageName = $package->getPrettyName(); $packageExtra = $this->composer->getPackage()->getExtra(); if (false === array_key_exists('wordpress-install-dir', $packageExtra)) { return parent::getInstallPath($package); } $installDirs = $packageExtra['wordpress-install-dir']; if (false === is_array($installDirs)) { throw new InvalidPackageException(['Installation directory must be a key value array of packages and install directories.'], [], [$installDirs]); } if (false === array_key_exists($packageName, $installDirs)) { throw new InvalidPackageException(['Installation directory must be a key value array of packages and install directories.'], [], [$installDirs]); } $packageInstallDir = $installDirs[$packageName]; $installDirCount = 0; foreach ($installDirs as $installDir) { if ($installDir === $packageInstallDir) { $installDirCount++; } } if ($installDirCount > 1) { throw new InvalidPackageException(['Two packages cannot have the same install directory'], [], $installDirs); } return $installDirs[$packageName]; }
protected function getCoreInstallPath(PackageInterface $package) { $type = $package->getType(); $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $availableVars = compact('name', 'vendor', 'type'); $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $availableVars['name'] = $extra['installer-name']; } if ($this->composer->getPackage()) { $extra = $this->composer->getPackage()->getExtra(); if (!empty($extra['installer-paths'])) { $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type); if ($customPath !== false) { return $this->templatePath($customPath, $availableVars); } } } $path = self::DEFAULT_TARGET_PATH; return $this->templatePath($path, $availableVars); }
/** * @param PackageInterface $package * * @return string */ public function getPackageBasePath(PackageInterface $package) { $extra = $package->getExtra(); print_r($extra); // get dependency glue packages return parent::getPackageBasePath($package); }
public static function getPackageInstallPath(PackageInterface $package, Composer $composer) { $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $availableVars = compact('name', 'vendor'); $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $availableVars['name'] = $extra['installer-name']; } if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['installer-paths'])) { $customPath = self::mapCustomInstallPaths($extra['installer-paths'], $prettyName); if (false !== $customPath) { return self::templatePath($customPath, $availableVars); } } } return NULL; }
protected function getPackageBasePath(PackageInterface $package) { if (!$this->supports($package->getType())) { throw new \InvalidArgumentException("Package type [{$type}] is not supported"); } return self::$allowedTypes[$package->getType()] . '/' . $package->getPrettyName(); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $ref = escapeshellarg($target->getSourceReference()); $path = escapeshellarg($path); $this->io->write(" Updating to " . $target->getSourceReference()); $this->process->execute(sprintf('cd %s && hg pull && hg up %s', $path, $ref), $ignoredOutput); }
/** * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) { $installationDir = false; $prettyName = $package->getPrettyName(); if ($this->composer->getPackage()) { $topExtra = $this->composer->getPackage()->getExtra(); if (!empty($topExtra['wordpress-install-dir'])) { $installationDir = $topExtra['wordpress-install-dir']; if (is_array($installationDir)) { $installationDir = empty($installationDir[$prettyName]) ? false : $installationDir[$prettyName]; } } } $extra = $package->getExtra(); if (!$installationDir && !empty($extra['wordpress-install-dir'])) { $installationDir = $extra['wordpress-install-dir']; } if (!$installationDir) { $installationDir = 'wordpress'; } if (!empty(self::$_installedPaths[$installationDir]) && $prettyName !== self::$_installedPaths[$installationDir]) { throw new \InvalidArgumentException('Two packages cannot share the same directory!'); } self::$_installedPaths[$installationDir] = $prettyName; return $installationDir; }
/** * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) { $prettyName = explode('/', $package->getPrettyName()); $devName = $prettyName[0]; $themeName = $prettyName[1]; return 'theme/' . $devName . '/' . $themeName . '/'; }
/** * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) { if (substr($package->getPrettyName(), 0, 23) != 'phpdocumentor/template-') { throw new \InvalidArgumentException('Unable to install template, phpdocumentor templates should always start their package name with "phpdocumentor/template."'); } return 'data/templates/' . substr($package->getPrettyName(), 23); }
protected function createConflictRule(PackageInterface $issuer, PackageInterface $provider, $reason, $reasonData = null) { if ($issuer === $provider) { return null; } return new Rule($this->pool, array(-$issuer->getId(), -$provider->getId()), $reason, $reasonData); }
/** * Get the primary namespace for a plugin package. * * @param \Composer\Package\PackageInterface $package composer object * @return string The package's primary namespace. * @throws \RuntimeException When the package's primary namespace cannot be determined. */ public function primaryNamespace($package) { $primaryNs = null; $autoLoad = $package->getAutoload(); foreach ($autoLoad as $type => $pathMap) { if ($type !== 'psr-4') { continue; } $count = count($pathMap); if ($count === 1) { $primaryNs = key($pathMap); break; } $matches = preg_grep('#^(\\./)?src/?$#', $pathMap); if ($matches) { $primaryNs = key($matches); break; } foreach (['', '.'] as $path) { $key = array_search($path, $pathMap, true); if ($key !== false) { $primaryNs = $key; } } break; } if (!$primaryNs) { throw new RuntimeException(sprintf("Unable to get primary namespace for package %s." . "\nEnsure you have added proper 'autoload' section to your plugin's config", $package->getName())); } return trim($primaryNs, '\\'); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { GitUtil::cleanEnv(); if (!$this->hasMetadataRepository($path)) { throw new \RuntimeException('The .git directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information'); } $updateOriginUrl = false; if (0 === $this->process->execute('git remote -v', $output, $path) && preg_match('{^origin\\s+(?P<url>\\S+)}m', $output, $originMatch) && preg_match('{^composer\\s+(?P<url>\\S+)}m', $output, $composerMatch)) { if ($originMatch['url'] === $composerMatch['url'] && $composerMatch['url'] !== $target->getSourceUrl()) { $updateOriginUrl = true; } } $ref = $target->getSourceReference(); $this->io->writeError(" Checking out " . $ref); $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer'; $commandCallable = function ($url) use($command) { return sprintf($command, ProcessExecutor::escape($url)); }; $this->gitUtil->runCommand($commandCallable, $url, $path); if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) { if ($target->getDistReference() === $target->getSourceReference()) { $target->setDistReference($newRef); } $target->setSourceReference($newRef); } if ($updateOriginUrl) { $this->updateOriginUrl($path, $target->getSourceUrl()); } }
/** * Try to determine the build number from a composer package * * @param \Composer\Package\PackageInterface $package * * @return string */ public static function determineBuildNumberFromPackage(PackageInterface $package) { if ($package->isDev()) { $buildNumber = self::determineBuildNumberFromBrowscapBuildFile(); if (is_null($buildNumber)) { $buildNumber = substr($package->getSourceReference(), 0, 8); } } else { $installedVersion = $package->getPrettyVersion(); // SemVer supports build numbers, but fall back to just using // version number if not available; at time of writing, composer // did not support SemVer 2.0.0 build numbers fully: // @see https://github.com/composer/composer/issues/2422 $plusPos = strpos($installedVersion, '+'); if ($plusPos !== false) { $buildNumber = substr($installedVersion, $plusPos + 1); } else { $buildNumber = self::determineBuildNumberFromBrowscapBuildFile(); if (is_null($buildNumber)) { $buildNumber = $installedVersion; } } } return $buildNumber; }
/** * Returns the installation path of a package * * @param PackageInterface $package Package * * @return string */ public function getInstallPath(PackageInterface $package) { switch ($package->getType()) { case self::TYPE_WORDPRESS: return 'wp'; } }
/** * {@inheritDoc} */ public function getPackageBasePath(PackageInterface $package) { $themes = __DIR__ . '/../../../../themes/'; $prefix = $package->getPrettyName(); $prefix = preg_replace('/[^\\w]+/', '_', $prefix); return $themes . $prefix; }
/** * Get the installation directory of the package. * * @param Composer $composer The composer instance * @param PackageInterface $package The package instance * @param string|null $installDir The custom installation directory * * @return string The installation directory */ protected static function getInstallDir(Composer $composer, PackageInterface $package, $installDir = null) { if (null === $installDir) { $installDir = rtrim($composer->getConfig()->get('vendor-dir'), '/') . '/' . $package->getName(); } return rtrim($installDir, '/'); }
/** * Returns Claromentis application name (folder) * * @param PackageInterface $package * * @return string */ protected function getApplicationCode(PackageInterface $package) { $pkg_name = $package->getName(); list(, $app_name) = explode('/', $pkg_name); $app_name = preg_replace("/-(src|obf|php5?|php7)\$/", '', $app_name); return $app_name; }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $url = $target->getSourceUrl(); $ref = $target->getSourceReference(); $this->io->write(" Checking out " . $ref); $this->execute($url, "svn switch", sprintf("%s/%s", $url, $ref), $path); }
/** * Return the install path based on package type. * * @param PackageInterface $package * @param string $frameworkType * @return string */ public function getInstallPath(PackageInterface $package, $frameworkType = '') { $type = $this->package->getType(); $prettyName = $this->package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type')); $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $availableVars['name'] = $extra['installer-name']; } if ($this->composer->getPackage()) { $extra = $this->composer->getPackage()->getExtra(); if (!empty($extra['installer-paths'])) { $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type); if ($customPath !== false) { return $this->templatePath($customPath, $availableVars); } } } $packageType = substr($type, strlen($frameworkType) + 1); $locations = $this->getLocations(); if (!isset($locations[$packageType])) { throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type)); } return $this->templatePath($locations[$packageType], $availableVars); }
/** * Provides installation path for package. Kudos go to * https://github.com/johnpbloch/wordpress-core-installer * * @param PackageInterface $package Installed package. * * @todo refactor * * @return string * @since 0.1.0 */ public function getInstallPath(PackageInterface $package) { $prettyName = $package->getPrettyName(); DebugPrinter::log('Getting install path for `%s` package', array($prettyName)); if (isset($this->installDirCache[$prettyName])) { return $this->installDirCache[$prettyName]; } $installDir = null; if ($this->composer->getPackage()) { $rootExtra = $this->composer->getPackage()->getExtra(); if (!empty($rootExtra['opencart-install-dir'])) { $installDir = $rootExtra['opencart-install-dir']; } } if (!$installDir) { $extra = $package->getExtra(); if (!empty($extra['opencart-install-dir'])) { $installDir = $extra['opencart-install-dir']; } } if (is_array($installDir)) { if (isset($installDir[$prettyName])) { $this->installDirCache[$prettyName] = $installDir[$prettyName]; return $installDir[$prettyName]; } $this->installDirCache[$prettyName] = $this->defaultInstallDir; return $this->defaultInstallDir; } $installDir = $installDir ? $installDir : $this->defaultInstallDir; DebugPrinter::log('Computed install dir for package `%s`: `%s`', array($prettyName, $installDir)); $this->installDirCache[$prettyName] = $installDir; return $installDir; }
function it_should_locate_config_file_on_empty_composer_configuration(Filesystem $filesystem, PackageInterface $package) { $package->getExtra()->willReturn(array()); $filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true); $filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml'))->willReturn(true); $this->locate('/composer', $package)->shouldMatch($this->pathRegex('/composer/grumphp.yml')); }
/** * All descendants' constructors should call this parent constructor * * @param PackageInterface $aliasOf The package this package is an alias of * @param string $version The version the alias must report * @param string $prettyVersion The alias's non-normalized version */ public function __construct(PackageInterface $aliasOf, $version, $prettyVersion) { parent::__construct($aliasOf->getName()); $this->version = $version; $this->prettyVersion = $prettyVersion; $this->aliasOf = $aliasOf; $this->stability = VersionParser::parseStability($version); $this->dev = $this->stability === 'dev'; // replace self.version dependencies foreach (array('requires', 'devRequires') as $type) { $links = $aliasOf->{'get' . ucfirst($type)}(); foreach ($links as $index => $link) { // link is self.version, but must be replacing also the replaced version if ('self.version' === $link->getPrettyConstraint()) { $links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion); } } $this->{$type} = $links; } // duplicate self.version provides foreach (array('conflicts', 'provides', 'replaces') as $type) { $links = $aliasOf->{'get' . ucfirst($type)}(); $newLinks = array(); foreach ($links as $link) { // link is self.version, but must be replacing also the replaced version if ('self.version' === $link->getPrettyConstraint()) { $newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion); } } $this->{$type} = array_merge($links, $newLinks); } }
/** * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) { $prefix = substr($package->getPrettyName(), 0, 14); if ('zepluf/plugin-' !== $prefix) { throw new \InvalidArgumentException('Unable to install plugin ' . $package->getPrettyName() . ', ZePLUF plugin package names should always begin with "zepluf/plugin-"'); } return 'app/plugins/' . $package->getTargetDir(); }