0 follower

Final Class Yiisoft\Config\ConfigPaths

InheritanceYiisoft\Config\ConfigPaths

Store the configuration paths necessary for using the {@see Config} instance.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Config\ConfigPaths
absolute() Returns the absolute path to the configuration file. Yiisoft\Config\ConfigPaths
relative() Returns the relative path to the configuration file. Yiisoft\Config\ConfigPaths

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $rootPath, string|null $configDirectory null, string|null $vendorDirectory null )
$rootPath string

The absolute path to the project root where composer.json is located.

$configDirectory string|null

The relative path to the configuration storage location.

$vendorDirectory string|null

The relative path to the vendor directory.

                public function __construct(
    private readonly string $rootPath,
    ?string $configDirectory = null,
    ?string $vendorDirectory = null,
) {
    $configDirectory = trim($configDirectory ?? Options::DEFAULT_CONFIG_DIRECTORY, '/');
    $this->configPath = $rootPath . ($configDirectory === '' ? '' : "/$configDirectory");
    $vendorDirectory = trim($vendorDirectory ?? Options::DEFAULT_VENDOR_DIRECTORY, '/');
    $this->vendorPath = $rootPath . ($vendorDirectory === '' ? '' : "/$vendorDirectory");
}

            
absolute() public method

Returns the absolute path to the configuration file.

public string absolute ( string $file, string $package Options::ROOT_PACKAGE_NAME )
$file string

Config file.

$package string

Name of the package. {@see \Yiisoft\Config\Composer\Options::ROOT_PACKAGE_NAME} stands for the root package.

return string

The absolute path to the configuration file.

                public function absolute(string $file, string $package = Options::ROOT_PACKAGE_NAME): string
{
    if ($package === Options::ROOT_PACKAGE_NAME) {
        return "$this->configPath/$file";
    }
    if ($package === Options::VENDOR_OVERRIDE_PACKAGE_NAME) {
        return "$this->vendorPath/$file";
    }
    return "$this->vendorPath/$package/$file";
}

            
relative() public method

Returns the relative path to the configuration file.

public string relative ( string $file )
$file string

Config file.

return string

The relative path to the configuration file.

                public function relative(string $file): string
{
    return str_starts_with($file, "$this->rootPath/")
        ? substr($file, strlen("$this->rootPath/"))
        : $file;
}