本文整理汇总了PHP中Composer\Package\PackageInterface::getDistReference方法的典型用法代码示例。如果您正苦于以下问题:PHP PackageInterface::getDistReference方法的具体用法?PHP PackageInterface::getDistReference怎么用?PHP PackageInterface::getDistReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Package\PackageInterface
的用法示例。
在下文中一共展示了PackageInterface::getDistReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPackageFilename
/**
* Generate a distinct filename for a particular version of a package.
*
* @param PackageInterface $package The package to get a name for
*
* @return string A filename without an extension
*/
public function getPackageFilename(PackageInterface $package)
{
$nameParts = array(preg_replace('#[^a-z0-9-_.]#i', '-', $package->getName()));
if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
$nameParts = array_merge($nameParts, array($package->getDistReference(), $package->getDistType()));
} else {
$nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference()));
}
if ($package->getSourceReference()) {
$nameParts[] = substr(sha1($package->getSourceReference()), 0, 6);
}
return implode('-', array_filter($nameParts, function ($p) {
return !empty($p);
}));
}
示例2: doUpdate
/**
* {@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());
}
}
示例3: doUpdate
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
{
$this->cleanEnv();
$path = $this->normalizePath($path);
if (!is_dir($path . '/.git')) {
throw new \RuntimeException('The .git directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information');
}
$ref = $target->getSourceReference();
$this->io->write(" Checking out " . $ref);
$command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer';
$this->process->execute('git remote -v', $output, $path);
if (preg_match('{^(?:composer|origin)\\s+https?://(.+):(.+)@([^/]+)}im', $output, $match)) {
$this->io->setAuthentication($match[3], urldecode($match[1]), urldecode($match[2]));
}
$commandCallable = function ($url) use($command) {
return sprintf($command, escapeshellarg($url));
};
$this->runCommand($commandCallable, $target->getSourceUrl(), $path);
if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) {
if ($target->getDistReference() === $target->getSourceReference()) {
$target->setDistReference($newRef);
}
$target->setSourceReference($newRef);
}
}
示例4: dump
public function dump(PackageInterface $package)
{
$keys = array('binaries' => 'bin', 'type', 'extra', 'installationSource' => 'installation-source', 'autoload', 'notificationUrl' => 'notification-url', 'includePaths' => 'include-path');
$data = array();
$data['name'] = $package->getPrettyName();
$data['version'] = $package->getPrettyVersion();
$data['version_normalized'] = $package->getVersion();
if ($package->getTargetDir()) {
$data['target-dir'] = $package->getTargetDir();
}
if ($package->getSourceType()) {
$data['source']['type'] = $package->getSourceType();
$data['source']['url'] = $package->getSourceUrl();
$data['source']['reference'] = $package->getSourceReference();
}
if ($package->getDistType()) {
$data['dist']['type'] = $package->getDistType();
$data['dist']['url'] = $package->getDistUrl();
$data['dist']['reference'] = $package->getDistReference();
$data['dist']['shasum'] = $package->getDistSha1Checksum();
}
if ($package->getArchiveExcludes()) {
$data['archive']['exclude'] = $package->getArchiveExcludes();
}
foreach (BasePackage::$supportedLinkTypes as $type => $opts) {
if ($links = $package->{'get' . ucfirst($opts['method'])}()) {
foreach ($links as $link) {
$data[$type][$link->getTarget()] = $link->getPrettyConstraint();
}
ksort($data[$type]);
}
}
if ($packages = $package->getSuggests()) {
ksort($packages);
$data['suggest'] = $packages;
}
if ($package->getReleaseDate()) {
$data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
}
$data = $this->dumpValues($package, $keys, $data);
if ($package instanceof CompletePackageInterface) {
$keys = array('scripts', 'license', 'authors', 'description', 'homepage', 'keywords', 'repositories', 'support');
$data = $this->dumpValues($package, $keys, $data);
if (isset($data['keywords']) && is_array($data['keywords'])) {
sort($data['keywords']);
}
}
if ($package instanceof RootPackageInterface) {
$minimumStability = $package->getMinimumStability();
if ($minimumStability) {
$data['minimum-stability'] = $minimumStability;
}
}
return $data;
}
示例5: processUrl
/**
* {@inheritdoc}
*/
protected function processUrl(PackageInterface $package, $url)
{
// support for legacy github archives
if ($package->getDistReference() && preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
$url = 'https://github.com/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
}
if ($package->getDistReference() && preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/archive/.+\\.(zip|tar\\.gz)$}i', $url, $match)) {
$url = 'https://github.com/' . $match[1] . '/' . $match[2] . '/archive/' . $package->getDistReference() . '.' . $match[3];
}
if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
// bypass https for github if openssl is disabled
if (preg_match('{^https?://github.com/([^/]+/[^/]+)/(zip|tar)ball/([^/]+)$}i', $url, $match)) {
$url = 'http://nodeload.github.com/' . $match[1] . '/' . $match[2] . '/' . $match[3];
} elseif (preg_match('{^https?://github.com/([^/]+/[^/]+)/archive/([^/]+)\\.(zip|tar\\.gz)$}i', $url, $match)) {
$url = 'http://nodeload.github.com/' . $match[1] . '/' . $match[3] . '/' . $match[2];
} else {
throw new \RuntimeException('You must enable the openssl extension to download files via https');
}
}
return parent::processUrl($package, $url);
}
示例6: convertPackageVersion
/**
* Convert a package version into string representation.
*
* @param PackageInterface $package The package to extract the version from.
*
* @param bool $fullReference Flag if the complete reference shall be added or an abbreviated form.
*
* @return string
*
* @throws \RuntimeException If the package is a dev package and does not have valid reference information.
*/
public static function convertPackageVersion(PackageInterface $package, $fullReference = false)
{
$version = $package->getPrettyVersion();
if ('dev' === $package->getStability()) {
if (null === ($reference = $package->getDistReference())) {
if (null === ($reference = $package->getSourceReference())) {
throw new \RuntimeException('Unable to determine reference for ' . $package->getPrettyName());
}
}
$version .= '#' . (!$fullReference ? substr($reference, 0, 8) : $reference);
}
return $version;
}
示例7: dump
public function dump(PackageInterface $package)
{
$keys = array('binaries' => 'bin', 'scripts', 'type', 'extra', 'installationSource' => 'installation-source', 'license', 'authors', 'description', 'homepage', 'keywords', 'autoload', 'repositories', 'includePaths' => 'include-path', 'support');
$data = array();
$data['name'] = $package->getPrettyName();
$data['version'] = $package->getPrettyVersion();
$data['version_normalized'] = $package->getVersion();
if ($package->getTargetDir()) {
$data['target-dir'] = $package->getTargetDir();
}
if ($package->getReleaseDate()) {
$data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
}
if ($package->getSourceType()) {
$data['source']['type'] = $package->getSourceType();
$data['source']['url'] = $package->getSourceUrl();
$data['source']['reference'] = $package->getSourceReference();
}
if ($package->getDistType()) {
$data['dist']['type'] = $package->getDistType();
$data['dist']['url'] = $package->getDistUrl();
$data['dist']['reference'] = $package->getDistReference();
$data['dist']['shasum'] = $package->getDistSha1Checksum();
}
foreach (BasePackage::$supportedLinkTypes as $type => $opts) {
if ($links = $package->{'get' . ucfirst($opts['method'])}()) {
foreach ($links as $link) {
$data[$type][$link->getTarget()] = $link->getPrettyConstraint();
}
}
}
if ($packages = $package->getSuggests()) {
$data['suggest'] = $packages;
}
foreach ($keys as $method => $key) {
if (is_numeric($method)) {
$method = $key;
}
$getter = 'get' . ucfirst($method);
$value = $package->{$getter}();
if (null !== $value && !(is_array($value) && 0 === count($value))) {
$data[$key] = $value;
}
}
return $data;
}
示例8: processUrl
/**
* {@inheritdoc}
*/
protected function processUrl(PackageInterface $package, $url)
{
if ($package->getDistReference() && strpos($url, 'github.com')) {
if (preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
// update legacy github archives to API calls with the proper reference
$url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
} elseif ($package->getDistReference() && preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/archive/.+\\.(zip|tar)(?:\\.gz)?$}i', $url, $match)) {
// update current github web archives to API calls with the proper reference
$url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
} elseif ($package->getDistReference() && preg_match('{^https?://api\\.github\\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i', $url, $match)) {
// update api archives to the proper reference
$url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
}
}
if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
throw new \RuntimeException('You must enable the openssl extension to download files via https');
}
return parent::processUrl($package, $url);
}
示例9: doUpdate
/**
* {@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');
}
$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);
}
}
示例10: getCacheKey
private function getCacheKey(PackageInterface $package)
{
if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
return $package->getName() . '/' . $package->getDistReference() . '.' . $package->getDistType();
}
return $package->getName() . '/' . $package->getVersion() . '-' . $package->getDistReference() . '.' . $package->getDistType();
}
示例11: updateInformation
private function updateInformation(Package $package, PackageInterface $data, $flags)
{
$em = $this->doctrine->getManager();
$version = new Version();
$normVersion = $data->getVersion();
$existingVersion = $package->getVersion($normVersion);
if ($existingVersion) {
$source = $existingVersion->getSource();
// update if the right flag is set, or the source reference has changed (re-tag or new commit on branch)
if ($source['reference'] !== $data->getSourceReference() || $flags & self::UPDATE_EQUAL_REFS) {
$version = $existingVersion;
} else {
// mark it updated to avoid it being pruned
$existingVersion->setUpdatedAt(new \DateTime());
return false;
}
}
$version->setName($package->getName());
$version->setVersion($data->getPrettyVersion());
$version->setNormalizedVersion($normVersion);
$version->setDevelopment($data->isDev());
$em->persist($version);
$descr = $this->sanitize($data->getDescription());
$version->setDescription($descr);
$package->setDescription($descr);
$version->setHomepage($data->getHomepage());
$version->setLicense($data->getLicense() ?: array());
$version->setPackage($package);
$version->setUpdatedAt(new \DateTime());
$version->setReleasedAt($data->getReleaseDate());
if ($data->getSourceType()) {
$source['type'] = $data->getSourceType();
$source['url'] = $data->getSourceUrl();
$source['reference'] = $data->getSourceReference();
$version->setSource($source);
} else {
$version->setSource(null);
}
if ($data->getDistType()) {
$dist['type'] = $data->getDistType();
$dist['url'] = $data->getDistUrl();
$dist['reference'] = $data->getDistReference();
$dist['shasum'] = $data->getDistSha1Checksum();
$version->setDist($dist);
} else {
$version->setDist(null);
}
if ($data->getType()) {
$type = $this->sanitize($data->getType());
$version->setType($type);
if ($type !== $package->getType()) {
$package->setType($type);
}
}
$version->setTargetDir($data->getTargetDir());
$version->setAutoload($data->getAutoload());
$version->setExtra($data->getExtra());
$version->setBinaries($data->getBinaries());
$version->setIncludePaths($data->getIncludePaths());
$version->setSupport($data->getSupport());
if ($data->getKeywords()) {
$keywords = array();
foreach ($data->getKeywords() as $keyword) {
$keywords[mb_strtolower($keyword, 'UTF-8')] = $keyword;
}
$existingTags = [];
foreach ($version->getTags() as $tag) {
$existingTags[mb_strtolower($tag->getName(), 'UTF-8')] = $tag;
}
foreach ($keywords as $tagKey => $keyword) {
if (isset($existingTags[$tagKey])) {
unset($existingTags[$tagKey]);
continue;
}
$tag = Tag::getByName($em, $keyword, true);
if (!$version->getTags()->contains($tag)) {
$version->addTag($tag);
}
}
foreach ($existingTags as $tag) {
$version->getTags()->removeElement($tag);
}
} elseif (count($version->getTags())) {
$version->getTags()->clear();
}
$authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author');
$version->getAuthors()->clear();
if ($data->getAuthors()) {
foreach ($data->getAuthors() as $authorData) {
$author = null;
foreach (array('email', 'name', 'homepage', 'role') as $field) {
if (isset($authorData[$field])) {
$authorData[$field] = trim($authorData[$field]);
if ('' === $authorData[$field]) {
$authorData[$field] = null;
}
} else {
$authorData[$field] = null;
}
}
//.........这里部分代码省略.........
示例12: getDistReference
/**
* {@inheritdoc}
*/
public function getDistReference()
{
return $this->package->getDistReference();
}
示例13: processPackage
/**
* Scans the given package and collects extensions data.
* @param PackageInterface $package
*/
public function processPackage(PackageInterface $package)
{
$extra = $package->getExtra();
$files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
if ($package->getType() !== self::PACKAGE_TYPE && is_null($files)) {
return;
}
$extension = ['name' => $package->getName(), 'version' => $package->getVersion()];
if ($package->getVersion() === '9999999-dev') {
$reference = $package->getSourceReference() ?: $package->getDistReference();
if ($reference) {
$extension['reference'] = $reference;
}
}
$this->data['extensions'][$package->getName()] = $extension;
$aliases = array_merge($this->prepareAliases($package, 'psr-0'), $this->prepareAliases($package, 'psr-4'));
$this->data['aliases'] = array_merge($this->data['aliases'], $aliases);
foreach ((array) $files as $name => $path) {
$config = $this->readExtensionConfig($package, $path);
$config['aliases'] = array_merge($aliases, isset($config['aliases']) ? (array) $config['aliases'] : []);
$this->data['aliases'] = array_merge($this->data['aliases'], $config['aliases']);
$this->data[$name] = isset($this->data[$name]) ? Helper::mergeConfig($this->data[$name], $config) : $config;
}
}
示例14: updateInformation
private function updateInformation(OutputInterface $output, RegistryInterface $doctrine, $package, PackageInterface $data)
{
$em = $doctrine->getEntityManager();
$version = new Version();
$version->setName($package->getName());
$version->setNormalizedVersion(preg_replace('{-dev$}i', '', $data->getVersion()));
// check if we have that version yet
foreach ($package->getVersions() as $existingVersion) {
if ($existingVersion->equals($version)) {
// avoid updating newer versions, in case two branches have the same version in their composer.json
if ($existingVersion->getReleasedAt() > $data->getReleaseDate()) {
return;
}
if ($existingVersion->getDevelopment()) {
$version = $existingVersion;
break;
}
return;
}
}
$version->setVersion($data->getPrettyVersion());
$version->setDevelopment(substr($data->getVersion(), -4) === '-dev');
$em->persist($version);
$version->setDescription($data->getDescription());
$package->setDescription($data->getDescription());
$version->setHomepage($data->getHomepage());
$version->setLicense($data->getLicense() ?: array());
$version->setPackage($package);
$version->setUpdatedAt(new \DateTime());
$version->setReleasedAt($data->getReleaseDate());
if ($data->getSourceType()) {
$source['type'] = $data->getSourceType();
$source['url'] = $data->getSourceUrl();
$source['reference'] = $data->getSourceReference();
$version->setSource($source);
}
if ($data->getDistType()) {
$dist['type'] = $data->getDistType();
$dist['url'] = $data->getDistUrl();
$dist['reference'] = $data->getDistReference();
$dist['shasum'] = $data->getDistSha1Checksum();
$version->setDist($dist);
}
if ($data->getType()) {
$version->setType($data->getType());
if ($data->getType() && $data->getType() !== $package->getType()) {
$package->setType($data->getType());
}
}
$version->setTargetDir($data->getTargetDir());
$version->setAutoload($data->getAutoload());
$version->setExtra($data->getExtra());
$version->setBinaries($data->getBinaries());
$version->getTags()->clear();
if ($data->getKeywords()) {
foreach ($data->getKeywords() as $keyword) {
$version->addTag(Tag::getByName($em, $keyword, true));
}
}
$version->getAuthors()->clear();
if ($data->getAuthors()) {
foreach ($data->getAuthors() as $authorData) {
$author = null;
// skip authors with no information
if (empty($authorData['email']) && empty($authorData['name'])) {
continue;
}
if (!empty($authorData['email'])) {
$author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByEmail($authorData['email']);
}
if (!$author && !empty($authorData['homepage'])) {
$author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage']));
}
if (!$author && !empty($authorData['name'])) {
$author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByNameAndPackage($authorData['name'], $package);
}
if (!$author) {
$author = new Author();
$em->persist($author);
}
foreach (array('email', 'name', 'homepage') as $field) {
if (isset($authorData[$field])) {
$author->{'set' . $field}($authorData[$field]);
}
}
$author->setUpdatedAt(new \DateTime());
if (!$version->getAuthors()->contains($author)) {
$version->addAuthor($author);
}
if (!$author->getVersions()->contains($version)) {
$author->addVersion($version);
}
}
}
foreach ($this->supportedLinkTypes as $linkType => $linkEntity) {
$links = array();
foreach ($data->{'get' . $linkType . 's'}() as $link) {
$links[$link->getTarget()] = $link->getPrettyConstraint();
}
foreach ($version->{'get' . $linkType}() as $link) {
//.........这里部分代码省略.........
示例15: getDistReference
public function getDistReference()
{
return $this->aliasOf->getDistReference();
}