Class Yiisoft\YiiDevTool\App\Component\Package\Package
| Inheritance | Yiisoft\YiiDevTool\App\Component\Package\Package |
|---|
Public Methods
Method Details
| public mixed __construct ( string $id, mixed $config, string $owner, string $packagesRootDir, self|null $rootPackage ) | ||
| $id | string | |
| $config | mixed | |
| $owner | string | |
| $packagesRootDir | string | |
| $rootPackage | self|null | |
public function __construct(string $id, $config, private string $owner, string $packagesRootDir, private ?self $rootPackage)
{
if (!preg_match('|^[a-z0-9_.-]+$|i', $id)) {
throw new InvalidArgumentException('Package ID can contain only symbols [a-z0-9_.-].');
}
$this->id = $id;
if (!is_bool($config) && !is_string($config) && !is_array($config)) {
throw new InvalidArgumentException('Package config must be either a boolean, a string or an array.');
}
$enabled = false;
$isMonoRepository = false;
$repositoryUrl = null;
if (is_array($config)) {
$enabled = (bool) ($config['enabled'] ?? false);
$isMonoRepository = (bool) ($config['monorepo'] ?? false);
} elseif (is_bool($config)) {
$enabled = $config;
} elseif (is_string($config)) {
$enabled = true;
if ($config === 'https') {
$repositoryUrl = "https://github.com/$this->owner/$id.git";
} elseif (preg_match('|^[a-z0-9-]+/[a-z0-9_.-]+$|i', $config)) {
preg_match('|^([a-z0-9-]+)/[a-z0-9_.-]+$|i', $config, $ownerMatches);
$this->owner = $ownerMatches[1] ?? $owner;
$repositoryUrl = "git@github.com:$config.git";
} else {
preg_match('|^git@github.com:([a-z0-9-]+)/[a-z0-9_.-]+$|i', $config, $ownerMatches);
$this->owner = $ownerMatches[1] ?? $owner;
$repositoryUrl = $config;
}
}
if ($enabled && $repositoryUrl === null) {
$repositoryUrl = "git@github.com:$this->owner/$id.git";
}
$this->configuredRepositoryUrl = !$enabled ? null : $repositoryUrl;
$this->enabled = $enabled;
$this->isMonoRepository = $isMonoRepository;
$this->path = rtrim($packagesRootDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $id;
}
| public boolean composerConfigFileExists ( ) |
public function composerConfigFileExists(): bool
{
return file_exists($this->getComposerConfigPath());
}
| public string getComposerConfigPath ( ) |
public function getComposerConfigPath(): string
{
return "{$this->path}/composer.json";
}
| public string getConfiguredRepositoryUrl ( ) |
public function getConfiguredRepositoryUrl(): string
{
if ($this->isVirtual()) {
return $this->rootPackage->getConfiguredRepositoryUrl();
}
if ($this->configuredRepositoryUrl === null) {
throw new RuntimeException('Package does not have repository url.');
}
return $this->configuredRepositoryUrl;
}
| public \Symplify\GitWrapper\GitWorkingCopy getGitWorkingCopy ( ) |
public function getGitWorkingCopy(): GitWorkingCopy
{
if (!$this->isGitRepositoryCloned()) {
throw new RuntimeException(sprintf('Package %s does not have git working copy.', $this->path));
}
if ($this->gitWorkingCopy === null) {
$path = $this->path;
if ($this->isVirtual()) {
$path = $this->rootPackage->getPath();
}
$this->gitWorkingCopy = static::getGitWrapper()->workingCopy($path);
}
return $this->gitWorkingCopy;
}
| public string getName ( ) |
public function getName(): string
{
return "{$this->getVendor()}/{$this->getId()}";
}
| public string getPath ( ) |
public function getPath(): string
{
if ($this->isVirtual()) {
return $this->rootPackage->getPath() . DIRECTORY_SEPARATOR . $this->id;
}
return $this->path;
}
| public self|null getRootPackage ( ) |
public function getRootPackage(): ?self
{
return $this->rootPackage;
}
| public boolean isGitRepositoryCloned ( ) |
public function isGitRepositoryCloned(): bool
{
if ($this->isVirtual()) {
return $this->rootPackage->isGitRepositoryCloned();
}
return file_exists("{$this->path}/.git");
}
| public boolean isMonoRepository ( ) |
public function isMonoRepository(): bool
{
return $this->isMonoRepository;
}
| public boolean isVirtual ( ) |
public function isVirtual(): bool
{
return $this->rootPackage !== null;
}
| public void setEnabled ( boolean $value ) | ||
| $value | boolean | |
public function setEnabled(bool $value): void
{
$this->enabled = $value;
}
Signup or Login in order to comment.