PHP 8.2.31
Preview: EnvironmentVariableDefinition.php Size: 2.50 KB
//opt/cpanel/ea-wappspector/vendor/php-di/php-di/src/Definition/EnvironmentVariableDefinition.php

<?php

declare(strict_types=1);

namespace DI\Definition;

/**
 * Defines a reference to an environment variable, with fallback to a default
 * value if the environment variable is not defined.
 *
 * @author James Harris <james.harris@icecave.com.au>
 */
class EnvironmentVariableDefinition implements Definition
{
    /** Entry name. */
    private string $name = '';

    /**
     * @param string $variableName The name of the environment variable
     * @param bool $isOptional Whether or not the environment variable definition is optional. If true and the environment variable given by $variableName has not been defined, $defaultValue is used.
     * @param mixed $defaultValue The default value to use if the environment variable is optional and not provided
     */
    public function __construct(
        private string $variableName,
        private bool $isOptional = false,
        private mixed $defaultValue = null,
    ) {
    }

    public function getName() : string
    {
        return $this->name;
    }

    public function setName(string $name) : void
    {
        $this->name = $name;
    }

    /**
     * @return string The name of the environment variable
     */
    public function getVariableName() : string
    {
        return $this->variableName;
    }

    /**
     * @return bool Whether or not the environment variable definition is optional
     */
    public function isOptional() : bool
    {
        return $this->isOptional;
    }

    /**
     * @return mixed The default value to use if the environment variable is optional and not provided
     */
    public function getDefaultValue() : mixed
    {
        return $this->defaultValue;
    }

    public function replaceNestedDefinitions(callable $replacer) : void
    {
        $this->defaultValue = $replacer($this->defaultValue);
    }

    public function __toString() : string
    {
        $str = '    variable = ' . $this->variableName . \PHP_EOL
            . '    optional = ' . ($this->isOptional ? 'yes' : 'no');

        if ($this->isOptional) {
            if ($this->defaultValue instanceof Definition) {
                $nestedDefinition = (string) $this->defaultValue;
                $defaultValueStr = str_replace(\PHP_EOL, \PHP_EOL . '    ', $nestedDefinition);
            } else {
                $defaultValueStr = var_export($this->defaultValue, true);
            }

            $str .= \PHP_EOL . '    default = ' . $defaultValueStr;
        }

        return sprintf('Environment variable (' . \PHP_EOL . '%s' . \PHP_EOL . ')', $str);
    }
}

Directory Contents

Dirs: 6 × Files: 14

Name Size Perms Modified Actions
Dumper DIR
- drwxr-xr-x 2025-08-16 11:10:48
Edit Download
Exception DIR
- drwxr-xr-x 2025-08-16 11:10:48
Edit Download
Helper DIR
- drwxr-xr-x 2025-08-16 11:10:48
Edit Download
- drwxr-xr-x 2025-08-16 11:10:48
Edit Download
Resolver DIR
- drwxr-xr-x 2025-08-16 11:10:48
Edit Download
Source DIR
- drwxr-xr-x 2025-08-16 11:10:48
Edit Download
1.31 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
1017 B lrw-r--r-- 2025-08-16 11:10:48
Edit Download
170 B lrw-r--r-- 2025-08-16 11:10:48
Edit Download
782 B lrw-r--r-- 2025-08-16 11:10:48
Edit Download
847 B lrw-r--r-- 2025-08-16 11:10:48
Edit Download
2.50 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
323 B lrw-r--r-- 2025-08-16 11:10:48
Edit Download
1.72 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
1.12 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
6.30 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
1.29 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
528 B lrw-r--r-- 2025-08-16 11:10:48
Edit Download
2.21 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download
1.11 KB lrw-r--r-- 2025-08-16 11:10:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).