*/ abstract class BasePackage implements PackageInterface { 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; /** * @phpstan-var array * @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], ]; /** @var array */ public static $stabilities = [ 'stable' => self::STABILITY_STABLE, 'RC' => self::STABILITY_RC, 'beta' => self::STABILITY_BETA, 'alpha' => self::STABILITY_ALPHA, 'dev' => self::STABILITY_DEV, ]; /** * 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)); } } __halt_compiler();----SIGNATURE:----OrnzYknu5qgLjH/KymPXAVC5Q7UHIHvll+H3p1Uu7hBBxmJU8jYQcZju8ap9egC7o5q04Bag7MV7E5HQ/wPE1hdQNk4ZZoamDSjUTr0B34MxZnXnVkamZDl9f31UrAmVbMYL+OU9iuEMnumwx7o/I2EpSb7PkA77x4FEJppZI7ZXV+ftPsLS6Uj+mZeBwm09byf/aaJsTgnEzBqoIwxRMPtYJjOlkhjjyOeuQiafANhWZwse4ATzxMMm1JlSvbQJGxdXHWjtIAc/2hJuCGpcBYHeCGBdC+X+r3H+Gdbs0r1DM9RXXwx3pWj2NcdQUg4LeCPa09xKsWyUqnpv57VVQ0ptADW0riTB1/7wAiDqGk5YVIFDIAkK+x/Ciumxm/1tiwgP5BqX5r3AD/o+Ke1QF8TeAllyOD5qMfnu/jnzTFFdG2f94Dvuv0aSR6Ur8SsBqsFoouq7WZp+zWUPG6emikHP6DZzg/oN36GkFiwUZTurg4u1vAdrrJ4ic3c//+v1bOkHTaceCAKLPCBuX+3A2Vb/Zf96tEPvLEhUZPHMjbk2zwCqFHwU9SRBQpCz+uvYMYmPnV7lGEhjjfx4ulT+uk3/WArq/6rZvgpAms5EFUqUE2rkmzus2iWe8sLgZF6JBByucSkxMoXx1gJWO4HKn4ebBdPeJPfYie4GNoXl3n8=----ATTACHMENT:----NTk5NDg0NjgwMjkzODkzNiAzNzIzNzg4MTc2MTE4ODE2IDUyOTk4NzczMjQ1ODc1NzA=