class BasePackage
Base class for packages providing name storage and default match implementation
@author Nils Adermann <naderman@naderman.de>
Hierarchy
- class \Composer\Package\BasePackage implements \Composer\Package\PackageInterface
Expanded class hierarchy of BasePackage
45 files declare their use of BasePackage
- ArchiveCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ ArchiveCommand.php - ArrayDumper.php in vendor/
composer/ composer/ src/ Composer/ Package/ Dumper/ ArrayDumper.php - ArrayLoader.php in vendor/
composer/ composer/ src/ Composer/ Package/ Loader/ ArrayLoader.php - ArrayRepository.php in vendor/
composer/ composer/ src/ Composer/ Repository/ ArrayRepository.php - ArtifactRepository.php in vendor/
composer/ composer/ src/ Composer/ Repository/ ArtifactRepository.php
File
-
vendor/
composer/ composer/ src/ Composer/ Package/ BasePackage.php, line 23
Namespace
Composer\PackageView source
abstract class BasePackage implements PackageInterface {
/**
* @phpstan-var array<non-empty-string, array{description: string, method: Link::TYPE_*}>
* @internal
*/
public static $supportedLinkTypes = [
'require' => [
'description' => 'requires',
'method' => Link::TYPE_REQUIRE,
],
'conflict' => [
'description' => 'conflicts',
'method' => Link::TYPE_CONFLICT,
],
'provide' => [
'description' => 'provides',
'method' => Link::TYPE_PROVIDE,
],
'replace' => [
'description' => 'replaces',
'method' => Link::TYPE_REPLACE,
],
'require-dev' => [
'description' => 'requires (for development)',
'method' => Link::TYPE_DEV_REQUIRE,
],
];
public const STABILITY_STABLE = 0;
public const STABILITY_RC = 5;
public const STABILITY_BETA = 10;
public const STABILITY_ALPHA = 15;
public const STABILITY_DEV = 20;
public const STABILITIES = [
'stable' => self::STABILITY_STABLE,
'RC' => self::STABILITY_RC,
'beta' => self::STABILITY_BETA,
'alpha' => self::STABILITY_ALPHA,
'dev' => self::STABILITY_DEV,
];
/**
* @deprecated
* @readonly
* @var array<key-of<BasePackage::STABILITIES>, self::STABILITY_*>
* @phpstan-ignore property.readOnlyByPhpDocDefaultValue
*/
public static $stabilities = self::STABILITIES;
/**
* READ-ONLY: The package id, public for fast access in dependency solver
* @var int
* @internal
*/
public $id;
/** @var string */
protected $name;
/** @var string */
protected $prettyName;
/** @var ?RepositoryInterface */
protected $repository = null;
/**
* All descendants' constructors should call this parent constructor
*
* @param string $name The package's name
*/
public function __construct(string $name) {
$this->prettyName = $name;
$this->name = strtolower($name);
$this->id = -1;
}
/**
* @inheritDoc
*/
public function getName() : string {
return $this->name;
}
/**
* @inheritDoc
*/
public function getPrettyName() : string {
return $this->prettyName;
}
/**
* @inheritDoc
*/
public function getNames($provides = true) : array {
$names = [
$this->getName() => true,
];
if ($provides) {
foreach ($this->getProvides() as $link) {
$names[$link->getTarget()] = true;
}
}
foreach ($this->getReplaces() as $link) {
$names[$link->getTarget()] = true;
}
return array_keys($names);
}
/**
* @inheritDoc
*/
public function setId(int $id) : void {
$this->id = $id;
}
/**
* @inheritDoc
*/
public function getId() : int {
return $this->id;
}
/**
* @inheritDoc
*/
public function setRepository(RepositoryInterface $repository) : void {
if ($this->repository && $repository !== $this->repository) {
throw new \LogicException(sprintf('Package "%s" cannot be added to repository "%s" as it is already in repository "%s".', $this->getPrettyName(), $repository->getRepoName(), $this->repository
->getRepoName()));
}
$this->repository = $repository;
}
/**
* @inheritDoc
*/
public function getRepository() : ?RepositoryInterface {
return $this->repository;
}
/**
* checks if this package is a platform package
*/
public function isPlatform() : bool {
return $this->getRepository() instanceof PlatformRepository;
}
/**
* Returns package unique name, constructed from name, version and release type.
*/
public function getUniqueName() : string {
return $this->getName() . '-' . $this->getVersion();
}
public function equals(PackageInterface $package) : bool {
$self = $this;
if ($this instanceof AliasPackage) {
$self = $this->getAliasOf();
}
if ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
return $package === $self;
}
/**
* Converts the package into a readable and unique string
*/
public function __toString() : string {
return $this->getUniqueName();
}
public function getPrettyString() : string {
return $this->getPrettyName() . ' ' . $this->getPrettyVersion();
}
/**
* @inheritDoc
*/
public function getFullPrettyVersion(bool $truncate = true, int $displayMode = PackageInterface::DISPLAY_SOURCE_REF_IF_DEV) : string {
if ($displayMode === PackageInterface::DISPLAY_SOURCE_REF_IF_DEV && (!$this->isDev() || !\in_array($this->getSourceType(), [
'hg',
'git',
]))) {
return $this->getPrettyVersion();
}
switch ($displayMode) {
case PackageInterface::DISPLAY_SOURCE_REF_IF_DEV:
case PackageInterface::DISPLAY_SOURCE_REF:
$reference = $this->getSourceReference();
break;
case PackageInterface::DISPLAY_DIST_REF:
$reference = $this->getDistReference();
break;
default:
throw new \UnexpectedValueException('Display mode ' . $displayMode . ' is not supported');
}
if (null === $reference) {
return $this->getPrettyVersion();
}
// if source reference is a sha1 hash -- truncate
if ($truncate && \strlen($reference) === 40 && $this->getSourceType() !== 'svn') {
return $this->getPrettyVersion() . ' ' . substr($reference, 0, 7);
}
return $this->getPrettyVersion() . ' ' . $reference;
}
/**
* @phpstan-return self::STABILITY_*
*/
public function getStabilityPriority() : int {
return self::STABILITIES[$this->getStability()];
}
public function __clone() {
$this->repository = null;
$this->id = -1;
}
/**
* Build a regexp from a package name, expanding * globs as required
*
* @param non-empty-string $wrap Wrap the cleaned string by the given string
* @return non-empty-string
*/
public static function packageNameToRegexp(string $allowPattern, string $wrap = '{^%s$}i') : string {
$cleanedAllowPattern = str_replace('\\*', '.*', preg_quote($allowPattern));
return sprintf($wrap, $cleanedAllowPattern);
}
/**
* Build a regexp from package names, expanding * globs as required
*
* @param string[] $packageNames
* @param non-empty-string $wrap
* @return non-empty-string
*/
public static function packageNamesToRegexp(array $packageNames, string $wrap = '{^(?:%s)$}iD') : string {
$packageNames = array_map(static function ($packageName) : string {
return BasePackage::packageNameToRegexp($packageName, '%s');
}, $packageNames);
return sprintf($wrap, implode('|', $packageNames));
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
BasePackage::$id | public | property | READ-ONLY: The package id, public for fast access in dependency solver @internal |
|||
BasePackage::$name | protected | property | @var string | |||
BasePackage::$prettyName | protected | property | @var string | |||
BasePackage::$repository | protected | property | @var ?RepositoryInterface | |||
BasePackage::$stabilities | Deprecated | public static | property | @phpstan-ignore property.readOnlyByPhpDocDefaultValue | ||
BasePackage::$supportedLinkTypes | public static | property | @phpstan-var array<non-empty-string, array{description: string, method: Link::TYPE_*}> @internal |
|||
BasePackage::equals | public | function | ||||
BasePackage::getFullPrettyVersion | public | function | @inheritDoc | Overrides PackageInterface::getFullPrettyVersion | ||
BasePackage::getId | public | function | @inheritDoc | Overrides PackageInterface::getId | ||
BasePackage::getName | public | function | @inheritDoc | Overrides PackageInterface::getName | ||
BasePackage::getNames | public | function | @inheritDoc | Overrides PackageInterface::getNames | ||
BasePackage::getPrettyName | public | function | @inheritDoc | Overrides PackageInterface::getPrettyName | ||
BasePackage::getPrettyString | public | function | Converts the package into a pretty readable string | Overrides PackageInterface::getPrettyString | ||
BasePackage::getRepository | public | function | @inheritDoc | Overrides PackageInterface::getRepository | ||
BasePackage::getStabilityPriority | public | function | @phpstan-return self::STABILITY_* | |||
BasePackage::getUniqueName | public | function | Returns package unique name, constructed from name, version and release type. | Overrides PackageInterface::getUniqueName | ||
BasePackage::isPlatform | public | function | checks if this package is a platform package | |||
BasePackage::packageNamesToRegexp | public static | function | Build a regexp from package names, expanding * globs as required | |||
BasePackage::packageNameToRegexp | public static | function | Build a regexp from a package name, expanding * globs as required | |||
BasePackage::setId | public | function | @inheritDoc | Overrides PackageInterface::setId | ||
BasePackage::setRepository | public | function | @inheritDoc | Overrides PackageInterface::setRepository | ||
BasePackage::STABILITIES | public | constant | ||||
BasePackage::STABILITY_ALPHA | public | constant | ||||
BasePackage::STABILITY_BETA | public | constant | ||||
BasePackage::STABILITY_DEV | public | constant | ||||
BasePackage::STABILITY_RC | public | constant | ||||
BasePackage::STABILITY_STABLE | public | constant | ||||
BasePackage::__clone | public | function | 1 | |||
BasePackage::__construct | public | function | All descendants' constructors should call this parent constructor | 2 | ||
BasePackage::__toString | public | function | Converts the package into a readable and unique string | Overrides PackageInterface::__toString | 1 | |
PackageInterface::DISPLAY_DIST_REF | public | constant | ||||
PackageInterface::DISPLAY_SOURCE_REF | public | constant | ||||
PackageInterface::DISPLAY_SOURCE_REF_IF_DEV | public | constant | ||||
PackageInterface::getAutoload | public | function | Returns an associative array of autoloading rules | 2 | ||
PackageInterface::getBinaries | public | function | Returns the package binaries | 2 | ||
PackageInterface::getConflicts | public | function | Returns a set of links to packages which must not be installed at the same time as this package |
2 | ||
PackageInterface::getDevAutoload | public | function | Returns an associative array of dev autoloading rules | 2 | ||
PackageInterface::getDevRequires | public | function | Returns a set of links to packages which are required to develop this package. These are installed if in dev mode. |
2 | ||
PackageInterface::getDistMirrors | public | function | Returns the dist mirrors of this package | 2 | ||
PackageInterface::getDistReference | public | function | Returns the reference of the distribution archive of this version, e.g. master, 1.0.0 or a commit hash for git | 2 | ||
PackageInterface::getDistSha1Checksum | public | function | Returns the sha1 checksum for the distribution archive of this version | 2 | ||
PackageInterface::getDistType | public | function | Returns the type of the distribution archive of this version, e.g. zip, tarball | 2 | ||
PackageInterface::getDistUrl | public | function | Returns the url of the distribution archive of this version | 2 | ||
PackageInterface::getDistUrls | public | function | Returns the urls of the distribution archive of this version, including mirrors | 2 | ||
PackageInterface::getExtra | public | function | Returns the package extra data | 2 | ||
PackageInterface::getIncludePaths | public | function | Returns a list of directories which should get added to PHP's include path. |
2 | ||
PackageInterface::getInstallationSource | public | function | Returns source from which this package was installed (source/dist). | 2 | ||
PackageInterface::getNotificationUrl | public | function | Returns the package notification url | 2 | ||
PackageInterface::getPhpExt | public | function | Returns the settings for php extension packages | 2 | ||
PackageInterface::getPrettyVersion | public | function | Returns the pretty (i.e. non-normalized) version string of this package | 2 | ||
PackageInterface::getProvides | public | function | Returns a set of links to virtual packages that are provided through this package |
2 | ||
PackageInterface::getReleaseDate | public | function | Returns the release date of the package | 2 | ||
PackageInterface::getReplaces | public | function | Returns a set of links to packages which can alternatively be satisfied by installing this package |
2 | ||
PackageInterface::getRequires | public | function | Returns a set of links to packages which need to be installed before this package can be installed |
2 | ||
PackageInterface::getSourceMirrors | public | function | Returns the source mirrors of this package | 2 | ||
PackageInterface::getSourceReference | public | function | Returns the repository reference of this package, e.g. master, 1.0.0 or a commit hash for git | 2 | ||
PackageInterface::getSourceType | public | function | Returns the repository type of this package, e.g. git, svn | 2 | ||
PackageInterface::getSourceUrl | public | function | Returns the repository url of this package, e.g. git://github.com/naderman/composer.git | 2 | ||
PackageInterface::getSourceUrls | public | function | Returns the repository urls of this package including mirrors, e.g. git://github.com/naderman/composer.git | 2 | ||
PackageInterface::getStability | public | function | Returns the stability of this package: one of (dev, alpha, beta, RC, stable) | 2 | ||
PackageInterface::getSuggests | public | function | Returns a set of package names and reasons why they are useful in combination with this package. |
2 | ||
PackageInterface::getTargetDir | public | function | Returns the package targetDir property | 2 | ||
PackageInterface::getTransportOptions | public | function | Returns a list of options to download package dist files | 2 | ||
PackageInterface::getType | public | function | Returns the package type, e.g. library | 2 | ||
PackageInterface::getVersion | public | function | Returns the version of this package | 2 | ||
PackageInterface::isDefaultBranch | public | function | 2 | |||
PackageInterface::isDev | public | function | Returns whether the package is a development virtual package or a concrete one | 2 | ||
PackageInterface::setDistMirrors | public | function | 2 | |||
PackageInterface::setDistReference | public | function | 2 | |||
PackageInterface::setDistType | public | function | 2 | |||
PackageInterface::setDistUrl | public | function | 2 | |||
PackageInterface::setInstallationSource | public | function | Sets source from which this package was installed (source/dist). | 2 | ||
PackageInterface::setSourceDistReferences | public | function | Set dist and source references and update dist URL for ones that contain a reference | 2 | ||
PackageInterface::setSourceMirrors | public | function | 2 | |||
PackageInterface::setSourceReference | public | function | 2 | |||
PackageInterface::setTransportOptions | public | function | Configures the list of options to download package dist files | 2 |