<?php
namespace Claromentis\Core\Config;

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] ?: array()) + array("_bd71c3b5c2" . "01fc11db82e" . "d14ce424de5" => base64_decode("aW5f" . "YXJy" . "YXk="), "_8a86292a184d0c143460" . "8ab006e7b8b3" => base64_decode("JG5hbWVzIG11c3QgYmUg" . "YSBzdHJpbmcgb3IgYW4g" . "YXJyYXkgb2Ygc3RyaW5n" . "cw=="), "_38f12d8b" . "8c719a8ce" . "0fc2faefc" . "225f35" => base64_decode("YXJ" . "yYX" . "lfb" . "WFw"), "_e71fc14cbadef6" . "940f5cb556511f6" . "5e8" => base64_decode("Q29uZmlndXJhdGlvbiBwcm92aWR" . "lciAn"), "_21d8d15ff5e12a" . "24e0d59a4dead98" . "4ae" => base64_decode("YXJyYXl" . "faW5zZX" . "J0X2Fmd" . "GVy"), "_58f9cd2f97dbf4d2db74ab" . "02504a90b9" => base64_decode("YXJyY" . "Xlfcm" . "V2ZXJ" . "zZQ=="), "_7aefd482de7885" . "f4293c2926df28c" . "235" => base64_decode("anNv" . "bl9l" . "bmNv" . "ZGU="), "_eb4d6202eab315" . "cdfff1693f1dcab" . "500" => base64_decode("Y3Vy" . "cmVu" . "dA=="), "_f73dab606630b3" . "88645c4f7d3fbb1" . "3bb" => base64_decode("YXJy" . "YXlf" . "bWVy" . "Z2U="), "_fd777c535802cf" . "1d47d6f7d8969b9" . "da8" => base64_decode("bm9ybWFs" . "aXplTmFt" . "ZQ=="), "_25657c2a5c7" . "a8aa175375e3" . "eee3ce1a3" => base64_decode("JGV4Y2x1ZGVQcm92aWRlcnMgbXVzdCBiZSBhIHN0cmluZyBvciBhbiBhcnJheSBvZiBzdHJpbm" . "dz"), "_7759855f238991a8acfe45f3" . "0c83b03b" => base64_decode("L0NvbWJpbmVkQ29uZmlnLn" . "BocA=="), "_7946c6875ddaaae" . "5182766479c3a6a3" . "0" => base64_decode("JyBtdXN0IG" . "ltcGxlbWVu" . "dCA="), "_ee1c4cef8785a7" . "44408faf37f4e50" . "100" => base64_decode("cHJl" . "dmlv" . "dXM="), "_5e9a99dc0dd" . "49b907abf1b3" . "5e96965f8" => base64_decode("dHJp" . "bQ=="), "_7f628626dd1d55" . "c71b1fc0932ffd1" . "d2c" => base64_decode("aXNfYXJy" . "YXk="), "_70979d287fa2c98d21aa07834c259a" . "52" => base64_decode("c3RydG9sb3dlcg" . "=="), "_d706c160e45bf7434f" . "ff82a5976f0e19" => base64_decode("YXJyY" . "Xlfa2" . "V5cw=" . "="), "_5e30c4717ced36cff9e93e19a5c" . "576cc" => base64_decode("aXNfc3Ry" . "aW5n"));
use Claromentis\Core\Config\Events\ConfigUpdateEvent;
use Claromentis\Core\Config\Exception\NotFoundException;
use Claromentis\Core\Event\EventDispatcherAwareInterface;
use Claromentis\Core\Event\EventDispatcherAwareTrait;
use Claromentis\Core\Event\NullEventDispatcher;
use InvalidArgumentException;










































final class LayeredConfig implements WritableConfig, EventDispatcherAwareInterface
{
    use EventDispatcherAwareTrait;
    
    
    
    
    
    
    private string $name;
    
    
    
    
    
    
    private array $configProviders;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    private array $readOnly;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    private array $dirty;
    
    
    
    
    
    public function __construct(string $name, array $_97f0c45eb9d3612ee7f014a5ff775f96 = [])
    {
        $this->name = $this->normalizeName($name);
        $this->dispatcher = new NullEventDispatcher();
        $this->configProviders = [];
        $this->readOnly = [];
        $this->dirty = [];
        $this->addProviders($_97f0c45eb9d3612ee7f014a5ff775f96);
    }
    
    
    
    
    
    
    public function getName() : string
    {
        return $this->name;
    }
    
    
    
    
    
    
    
    public function hasProvider(string $name) : bool
    {
        $name = $this->normalizeName($name);
        return isset($this->configProviders[$name]);
    }
    
    
    
    
    
    
    
    
    
    public function getProvider(string $name) : Config
    {
        $name = $this->normalizeName($name);
        if (!$this->hasProvider($name)) {
            throw NotFoundException::configProvider($name);
        }
        return $this->configProviders[$name];
    }
    
    
    
    
    
    
    public function getProviders() : array
    {
        return $this->configProviders;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function addProvider(string $name, Config $config) : self
    {
        $name = $this->normalizeName($name);
        if (isset($this->configProviders[$name])) {
            
            
            $this->configProviders[$name] = $config;
        } else {
            
            
            $this->configProviders = [$name => $config] + $this->configProviders;
        }
        return $this;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function addProviders(iterable $_e2c8bbadf866de2edd3f59ea2cab7f2e) : self
    {
        
        
        $_0591ee055ac1bd22162b412eb15222ed = $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_58f9cd2f97dbf4d2db74ab0250" . "4a90b9"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d706c160e45bf7434fff82a597" . "6f0e19"]($_e2c8bbadf866de2edd3f59ea2cab7f2e));
        foreach ($_0591ee055ac1bd22162b412eb15222ed as $name) {
            $_a12c8da0f19064827eae63fd854c04e5 = $_e2c8bbadf866de2edd3f59ea2cab7f2e[$name];
            if (!$_a12c8da0f19064827eae63fd854c04e5 instanceof Config) {
                throw new InvalidArgumentException($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e71fc14" . "cbadef69" . "40f5cb55" . "6511f65e" . "8"] . $name . $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_7946c6875ddaaae51" . "82766479c3a6a30"] . Config::class);
            }
            $this->addProvider($name, $_a12c8da0f19064827eae63fd854c04e5);
        }
        return $this;
    }
    
    
    
    
    
    
    
    
    
    
    public function addProviderAfter(string $name, Config $config, string $_84fd5e84fc26d375029b5792f85e3fa0)
    {
        $name = $this->normalizeName($name);
        $_84fd5e84fc26d375029b5792f85e3fa0 = $this->normalizeName($_84fd5e84fc26d375029b5792f85e3fa0);
        $this->configProviders = $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_21d8d15ff5e12a24e0d5" . "9a4dead984ae"]($this->configProviders, $_84fd5e84fc26d375029b5792f85e3fa0, [$name => $config]);
    }
    
    
    
    
    
    
    
    public function removeProvider(string $name) : self
    {
        $name = $this->normalizeName($name);
        unset($this->configProviders[$name]);
        return $this;
    }
    
    
    
    
    
    
    
    public function removeProviders($_2420ec9da53978a4e391100f2c6ab9f1) : self
    {
        if ($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_5e30c4717ced36cff9e93e19a5c5" . "76cc"]($_2420ec9da53978a4e391100f2c6ab9f1)) {
            $_2420ec9da53978a4e391100f2c6ab9f1 = [$_2420ec9da53978a4e391100f2c6ab9f1];
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_7f628626dd1d55c71b1fc0932f" . "fd1d2c"]($_2420ec9da53978a4e391100f2c6ab9f1)) {
            throw new InvalidArgumentException($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8a86292a1" . "84d0c14346" . "08ab006e7b" . "8b3"]);
        }
        foreach ($_2420ec9da53978a4e391100f2c6ab9f1 as $name) {
            $this->removeProvider($name);
        }
        return $this;
    }
    
    
    
    
    
    
    
    public function withoutProviders($_2420ec9da53978a4e391100f2c6ab9f1) : LayeredConfig
    {
        $config = clone $this;
        $config->removeProviders($_2420ec9da53978a4e391100f2c6ab9f1);
        return $config;
    }
    
    
    
    
    
    
    
    public function isReadOnlyProvider(string $name) : bool
    {
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_bd71c3b5c201fc11db8" . "2ed14ce424de5"]($name, $this->readOnly);
    }
    
    
    
    
    
    
    
    
    public function getReadOnlyProviders() : ?array
    {
        return $this->readOnly;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function setReadOnlyProviders(array $_2420ec9da53978a4e391100f2c6ab9f1) : self
    {
        $this->readOnly = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_38f12d8b8c7" . "19a8ce0fc2fa" . "efc225f35"]([$this, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_fd777c535802cf1d47d6f7d8969b9d" . "a8"]], $_2420ec9da53978a4e391100f2c6ab9f1);
        return $this;
    }
    public function has(string $key) : bool
    {
        return $this->get($key) !== null;
    }
    public function get(string $key)
    {
        foreach ($this->configProviders as $config) {
            $value = $config->get($key);
            if ($value !== null) {
                return $value;
            }
        }
        return null;
    }
    
    
    
    
    
    
    
    
    public function getWithout(string $key, $_3513b371a82b136f06d6ace7d10d4a72)
    {
        if ($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_5e30c4717ced36cf" . "f9e93e19a5c576cc"]($_3513b371a82b136f06d6ace7d10d4a72)) {
            $_3513b371a82b136f06d6ace7d10d4a72 = [$_3513b371a82b136f06d6ace7d10d4a72];
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_7f628626dd1" . "d55c71b1fc09" . "32ffd1d2c"]($_3513b371a82b136f06d6ace7d10d4a72)) {
            throw new InvalidArgumentException($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8a86292a184d0c1434608ab0" . "06e7b8b3"]);
        }
        foreach ($this->configProviders as $name => $config) {
            if ($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_bd71c3b5c2" . "01fc11db82e" . "d14ce424de5"]($name, $_3513b371a82b136f06d6ace7d10d4a72)) {
                continue;
            }
            $value = $config->get($key);
            if ($value !== null) {
                return $value;
            }
        }
        return null;
    }
    public function getAll() : array
    {
        $values = [];
        foreach ($this->configProviders as $config) {
            $_cf6d0424cc110e5798ec2ce203b5f4f9 = $config->getAll();
            if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_7f628626d" . "d1d55c71b1" . "fc0932ffd1" . "d2c"]($_cf6d0424cc110e5798ec2ce203b5f4f9)) {
                continue;
            }
            $values = $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_f73dab606630b388645" . "c4f7d3fbb13bb"]($_cf6d0424cc110e5798ec2ce203b5f4f9, $values);
        }
        return $values;
    }
    
    
    
    
    
    
    
    public function getAllWithout($_2420ec9da53978a4e391100f2c6ab9f1) : array
    {
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_5e30c4717ced36cff9e93e19a" . "5c576cc"]($_2420ec9da53978a4e391100f2c6ab9f1)) {
            $_2420ec9da53978a4e391100f2c6ab9f1 = [$_2420ec9da53978a4e391100f2c6ab9f1];
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_7f628626dd1d55" . "c71b1fc0932ffd1" . "d2c"]($_2420ec9da53978a4e391100f2c6ab9f1)) {
            throw new InvalidArgumentException($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_8a86292a184d0c1434608ab0" . "06e7b8b3"]);
        }
        $values = [];
        foreach ($this->configProviders as $name => $config) {
            if ($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bd71c3b5c201fc11db82ed14ce424d" . "e5"]($name, $_2420ec9da53978a4e391100f2c6ab9f1)) {
                continue;
            }
            $_cf6d0424cc110e5798ec2ce203b5f4f9 = $config->getAll();
            if (!$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_7f628626dd1d55" . "c71b1fc0932ffd1" . "d2c"]($_cf6d0424cc110e5798ec2ce203b5f4f9)) {
                continue;
            }
            $values = $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_f73dab606630b388645" . "c4f7d3fbb13bb"]($_cf6d0424cc110e5798ec2ce203b5f4f9, $values);
        }
        return $values;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function set(string $key, $value) : void
    {
        $_ac07ee3df72ae3ca08d635249dda1b58 = $this->get($key);
        
        
        if ($this->equals($_ac07ee3df72ae3ca08d635249dda1b58, $value)) {
            return;
        }
        
        
        
        $_e971bac06f3ef5bf18d848f0f2ad9d10 = [];
        foreach ($this->configProviders as $name => $config) {
            if (!$this->canWriteVariableToProvider($name, $key)) {
                if ($this->isWritableProvider($name)) {
                    $_e971bac06f3ef5bf18d848f0f2ad9d10[$name] = $config;
                }
                continue;
            }
            $config->set($key, $value);
            break;
        }
        
        
        foreach ($_e971bac06f3ef5bf18d848f0f2ad9d10 as $_af1411990f46fd7c47199e5120e16e9f) {
            $_af1411990f46fd7c47199e5120e16e9f->delete($key);
        }
        
        
        $_a25f18d585a77fc4813ec10ae58c0c68 = $this->get($key);
        $this->updateDirty($key, $_ac07ee3df72ae3ca08d635249dda1b58, $_a25f18d585a77fc4813ec10ae58c0c68);
    }
    public function setMany(array $values) : void
    {
        foreach ($values as $key => $value) {
            $this->set($key, $value);
        }
    }
    
    
    
    
    
    
    
    
    public function delete(string $key) : void
    {
        $_ac07ee3df72ae3ca08d635249dda1b58 = $this->get($key);
        foreach ($this->configProviders as $name => $config) {
            if (!$this->isWritableProvider($name)) {
                continue;
            }
            $config->delete($key);
        }
        $_a25f18d585a77fc4813ec10ae58c0c68 = $this->get($key);
        $this->updateDirty($key, $_ac07ee3df72ae3ca08d635249dda1b58, $_a25f18d585a77fc4813ec10ae58c0c68);
    }
    public function save() : void
    {
        foreach ($this->configProviders as $config) {
            if ($config instanceof WritableConfig) {
                $config->save();
            }
        }
        $this->dispatchUpdateEvent();
        $this->resetDirty();
    }
    public function canSet(string $key) : bool
    {
        foreach ($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_d706c160e45bf7434fff82a59" . "76f0e19"]($this->configProviders) as $name) {
            if ($this->canWriteVariableToProvider($name, $key)) {
                return true;
            }
        }
        return false;
    }
    
    
    
    
    
    
    
    
    
    
    public function whereIs(string $key) : ?string
    {
        foreach ($this->configProviders as $name => $config) {
            if ($config->has($key)) {
                return $name;
            }
        }
        return null;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function whereIsWithout(string $key, $_3513b371a82b136f06d6ace7d10d4a72) : ?string
    {
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_5e30c4717ced36cf" . "f9e93e19a5c576cc"]($_3513b371a82b136f06d6ace7d10d4a72)) {
            $_3513b371a82b136f06d6ace7d10d4a72 = [$_3513b371a82b136f06d6ace7d10d4a72];
        }
        if (!$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_7f628626dd1d55c71b1fc0932" . "ffd1d2c"]($_3513b371a82b136f06d6ace7d10d4a72)) {
            throw new InvalidArgumentException($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_25657c2a5c7a8aa175375e3eee3" . "ce1a3"]);
        }
        foreach ($this->configProviders as $name => $config) {
            if ($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_bd71c3b5c201fc11db82ed14ce424" . "de5"]($name, $_3513b371a82b136f06d6ace7d10d4a72)) {
                continue;
            }
            if ($config->has($key)) {
                return $name;
            }
        }
        return null;
    }
    public function offsetExists($_1f50e30be8c2fefa6881834e71d504a2) : bool
    {
        return $this->has($_1f50e30be8c2fefa6881834e71d504a2);
    }
    public function offsetGet($_1f50e30be8c2fefa6881834e71d504a2)
    {
        return $this->get($_1f50e30be8c2fefa6881834e71d504a2);
    }
    public function offsetSet($_1f50e30be8c2fefa6881834e71d504a2, $value) : void
    {
        $this->set($_1f50e30be8c2fefa6881834e71d504a2, $value);
    }
    public function offsetUnset($_1f50e30be8c2fefa6881834e71d504a2) : void
    {
        $this->delete($_1f50e30be8c2fefa6881834e71d504a2);
    }
    
    
    
    
    
    
    
    
    
    
    public function getDirty() : array
    {
        return $this->dirty[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_eb4d620" . "2eab315c" . "dfff1693" . "f1dcab50" . "0"]] ?? [];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    private function updateDirty(string $key, $_ac07ee3df72ae3ca08d635249dda1b58, $_a25f18d585a77fc4813ec10ae58c0c68)
    {
        if (!$this->equals($_ac07ee3df72ae3ca08d635249dda1b58, $_a25f18d585a77fc4813ec10ae58c0c68)) {
            $this->dirty[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_ee1c4cef8785a744408faf37f4e5010" . "0"]][$key] = $this->dirty[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_ee1c4cef8785a" . "744408faf37f4e" . "50100"]][$key] ?? $_ac07ee3df72ae3ca08d635249dda1b58;
            $this->dirty[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_eb4d6202eab315cdfff169" . "3f1dcab500"]][$key] = $_a25f18d585a77fc4813ec10ae58c0c68;
            
            
            
            if ($this->equals($this->dirty[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_ee1c4cef8785a744408faf37f4" . "e50100"]][$key], $this->dirty[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_eb4d6202eab315cdfff1693" . "f1dcab500"]][$key])) {
                unset($this->dirty[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_ee1c4cef8785a7" . "44408faf37f4e50" . "100"]][$key]);
                unset($this->dirty[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_eb4d6202eab315cdfff1693f1dca" . "b500"]][$key]);
            }
        }
    }
    
    
    
    
    private function resetDirty()
    {
        $this->dirty = [];
    }
    
    
    
    
    private function dispatchUpdateEvent()
    {
        $event = new ConfigUpdateEvent($this, $this->dirty[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_ee1c4cef8785a7" . "44408faf37f4e50" . "100"]] ?? [], $this->dirty[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_eb4d6202eab315c" . "dfff1693f1dcab50" . "0"]] ?? []);
        $this->dispatcher->dispatch(ConfigEvents::UPDATE, $event);
    }
    
    
    
    
    
    
    
    
    private function canWriteVariableToProvider(string $name, string $key) : bool
    {
        
        
        return $this->canWriteToProvider($name) && $this->getProvider($name)->canSet($key);
    }
    
    
    
    
    
    
    
    
    
    private function canWriteToProvider(string $name) : bool
    {
        return $this->isWritableProvider($name) && !$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_bd71c3b5c201" . "fc11db82ed14c" . "e424de5"]($name, $this->getReadOnlyProviders() ?? []);
    }
    
    
    
    
    
    
    
    private function isWritableProvider(string $name) : bool
    {
        return $this->hasProvider($name) && $this->getProvider($name) instanceof WritableConfig;
    }
    
    
    
    
    
    
    
    
    
    private function normalizeName(string $name) : string
    {
        return $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_70979d287fa2" . "c98d21aa07834" . "c259a52"]($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_5e9a99dc0dd4" . "9b907abf1b35e" . "96965f8"]($name));
    }
    
    
    
    
    
    
    
    
    
    
    private function equals($_ac07ee3df72ae3ca08d635249dda1b58, $_a25f18d585a77fc4813ec10ae58c0c68) : bool
    {
        return $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_7aefd482de7885f4293c2926df28c23" . "5"]($_ac07ee3df72ae3ca08d635249dda1b58) === $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_7aefd482de7885f4" . "293c2926df28c235"]($_a25f18d585a77fc4813ec10ae58c0c68);
    }
}


require_once __DIR__ . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7759855f238991a8acfe45f30c83b03" . "b"];