0 follower

Class Yiisoft\YiiDevTool\Infrastructure\CodeUsage\CodeUsage

InheritanceYiisoft\YiiDevTool\Infrastructure\CodeUsage\CodeUsage

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $identifier, string|string[] $environments )
$identifier string

Unique identifier of code usage: namespace, package name, etc.

$environments string|string[]

Environment(s) in which the code is used.

                public function __construct(private string $identifier, $environments)
{
    $environments = (array) $environments;
    foreach ($environments as $environment) {
        if (!is_string($environment)) {
            throw new InvalidArgumentException('Each environment must be a string.');
        }
    }
    $this->environments = $environments;
}

            
getEnvironments() public method

public string[] getEnvironments ( )

                public function getEnvironments(): array
{
    return $this->environments;
}

            
getIdentifier() public method

public string getIdentifier ( )

                public function getIdentifier(): string
{
    return $this->identifier;
}

            
registerUsageInEnvironment() public method

public void registerUsageInEnvironment ( string $environment )
$environment string

                public function registerUsageInEnvironment(string $environment): void
{
    if (!in_array($environment, $this->environments, true)) {
        $this->environments[] = $environment;
    }
}

            
registerUsageInEnvironments() public method

public void registerUsageInEnvironments ( string[] $environments )
$environments string[]

                public function registerUsageInEnvironments(array $environments): void
{
    foreach ($environments as $environment) {
        if (!is_string($environment)) {
            throw new InvalidArgumentException('Each environment must be a string.');
        }
        $this->registerUsageInEnvironment($environment);
    }
}

            
usedInEnvironment() public method

public boolean usedInEnvironment ( string $environment )
$environment string

                public function usedInEnvironment(string $environment): bool
{
    return in_array($environment, $this->environments, true);
}

            
usedOnlyInSpecifiedEnvironment() public method

public boolean usedOnlyInSpecifiedEnvironment ( string $environment )
$environment string

                public function usedOnlyInSpecifiedEnvironment(string $environment): bool
{
    if (count($this->environments) !== 1) {
        return false;
    }
    return in_array($environment, $this->environments, true);
}