HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/public_html/src/core/Directus/Config/Schema/Value.php
<?php

namespace Directus\Config\Schema;

use Directus\Config\Schema\Types;
use Directus\Config\Schema\Exception\OmitException;

/**
 * Value node
 */
class Value extends Base implements Node
{
    /**
     * Value type
     */
    private $_type = 'string';

    /**
     * Default value
     */
    private $_default = null;

    /**
     * Construct
     */
    public function __construct($name, $type, $default = null)
    {
        parent::__construct($name, []);
        $this->_type = $type;
        $this->_default = $default;
    }

    /**
     * Gets a value from leaf node
     */
    public function value($context)
    {
        $context = $this->normalize($context);

        if (!isset($context) || !isset($context[$this->key()])) {
            if ($this->optional()) {
                throw new OmitException();
            } else {
                return $this->_default;
            }
        }

        $value = $context[$this->key()];

        switch ($this->_type) {
            case Types::INTEGER:
                return intval($value);
            case Types::BOOLEAN:
                $value = strtolower($value);
                return $value === "true" || $value ===  "1" || $value === "on" || $value === "yes" || boolval($value);
            case Types::FLOAT:
                return floatval($value);
            case Types::ARRAY:
                if (!is_array($value)) {
                    return $this->_default;
                }
            case Types::STRING:
            default:
                return $value;
        }
    }
}