0 follower

Class Yiisoft\YiiDevTool\App\Component\Package\Package

InheritanceYiisoft\YiiDevTool\App\Component\Package\Package

Method Details

Hide inherited methods

__construct() public method

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;
}

            
composerConfigFileExists() public method

public boolean composerConfigFileExists ( )

                public function composerConfigFileExists(): bool
{
    return file_exists($this->getComposerConfigPath());
}

            
disabled() public method

public boolean disabled ( )

                public function disabled(): bool
{
    return !$this->enabled;
}

            
enabled() public method

public boolean enabled ( )

                public function enabled(): bool
{
    return $this->enabled;
}

            
getComposerConfigPath() public method

public string getComposerConfigPath ( )

                public function getComposerConfigPath(): string
{
    return "{$this->path}/composer.json";
}

            
getConfiguredRepositoryUrl() public method

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;
}

            
getGitWorkingCopy() public method

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;
}

            
getId() public method

public string getId ( )

                public function getId(): string
{
    return $this->id;
}

            
getName() public method

public string getName ( )

                public function getName(): string
{
    return "{$this->getVendor()}/{$this->getId()}";
}

            
getPath() public method

public string getPath ( )

                public function getPath(): string
{
    if ($this->isVirtual()) {
        return $this->rootPackage->getPath() . DIRECTORY_SEPARATOR . $this->id;
    }
    return $this->path;
}

            
getRootPackage() public method

public self|null getRootPackage ( )

                public function getRootPackage(): ?self
{
    return $this->rootPackage;
}

            
getVendor() public method

public string getVendor ( )

                public function getVendor(): string
{
    return $this->owner;
}

            
isGitRepositoryCloned() public method

public boolean isGitRepositoryCloned ( )

                public function isGitRepositoryCloned(): bool
{
    if ($this->isVirtual()) {
        return $this->rootPackage->isGitRepositoryCloned();
    }
    return file_exists("{$this->path}/.git");
}

            
isMonoRepository() public method

public boolean isMonoRepository ( )

                public function isMonoRepository(): bool
{
    return $this->isMonoRepository;
}

            
isVirtual() public method

public boolean isVirtual ( )

                public function isVirtual(): bool
{
    return $this->rootPackage !== null;
}

            
setEnabled() public method

public void setEnabled ( boolean $value )
$value boolean

                public function setEnabled(bool $value): void
{
    $this->enabled = $value;
}