Baikal\Model\Config::parseConfig PHP Метод

parseConfig() защищенный Метод

protected parseConfig ( $sString )
    protected function parseConfig($sString)
    {
        $aRes = [];
        foreach (array_keys($this->aConstants) as $sConstant) {
            $aConstant = $this->aConstants[$sConstant];
            $aMatches = [];
            $sPattern = '/\\s*define\\(\\s*["|\']' . $sConstant . '["|\']\\s*\\,\\s*(.*?)\\s*\\);\\s*/ix';
            $iNbRes = preg_match_all($sPattern, $sString, $aMatches);
            if ($iNbRes === 1) {
                # Exactly one match
                # O would be not enough, and > 1, to much to handle properly
                $sValue = $aMatches[1][0];
                # first capture (.*?), first occurence (anyway, we asserted that there's only one)
                switch ($aConstant["type"]) {
                    case "string":
                        $sValue = substr($sValue, 1, -1);
                        # Strip quotes
                        break;
                    case "integer":
                        $sValue = intval($sValue);
                        # Integer
                        break;
                    case "boolean":
                        if (in_array(strtoupper(trim($sValue)), ["1", "TRUE"])) {
                            $sValue = true;
                        } else {
                            $sValue = false;
                        }
                        break;
                    case "litteral":
                        $sValue = trim($sValue);
                        break;
                    default:
                        # nothing
                        break;
                }
                $aRes[$sConstant] = $sValue;
            } elseif ($iNbRes > 1) {
                throw new \Exception("Baikal\\Model\\Config->parseConfig(): constant '" . $sConstant . "' has been found multiple times in the config file; stopping execution");
            } else {
                # $iNbRes === 0
                # We do nothing, to keep the default value (the one already set in $aData)
            }
        }
        reset($aRes);
        return $aRes;
    }