Base::config PHP Method

config() public method

Configure framework according to .ini-style file settings; If optional 2nd arg is provided, template strings are interpreted
public config ( $file, $allow = FALSE ) : object
$file string
$allow bool
return object
    function config($file, $allow = FALSE)
    {
        preg_match_all('/(?<=^|\\n)(?:' . '\\[(?<section>.+?)\\]|' . '(?<lval>[^\\h\\r\\n;].*?)\\h*=\\h*' . '(?<rval>(?:\\\\\\h*\\r?\\n|.+?)*)' . ')(?=\\r?\\n|$)/', $this->read($file), $matches, PREG_SET_ORDER);
        if ($matches) {
            $sec = 'globals';
            $cmd = [];
            foreach ($matches as $match) {
                if ($match['section']) {
                    $sec = $match['section'];
                    if (preg_match('/^(?!(?:global|config|route|map|redirect)s\\b)' . '((?:\\.?\\w)+)/i', $sec, $msec) && !$this->exists($msec[0])) {
                        $this->set($msec[0], NULL);
                    }
                    preg_match('/^(config|route|map|redirect)s\\b|' . '^((?:\\.?\\w)+)\\s*\\>\\s*(.*)/i', $sec, $cmd);
                } else {
                    if ($allow) {
                        $match['lval'] = Preview::instance()->resolve($match['lval']);
                        $match['rval'] = Preview::instance()->resolve($match['rval']);
                    }
                    if (!empty($cmd)) {
                        isset($cmd[3]) ? $this->call($cmd[3], [$match['lval'], $match['rval'], $cmd[2]]) : call_user_func_array([$this, $cmd[1]], array_merge([$match['lval']], str_getcsv($match['rval'])));
                    } else {
                        $rval = preg_replace('/\\\\\\h*(\\r?\\n)/', '\\1', $match['rval']);
                        $ttl = NULL;
                        if (preg_match('/^(.+)\\|\\h*(\\d+)$/', $rval, $tmp)) {
                            array_shift($tmp);
                            list($rval, $ttl) = $tmp;
                        }
                        $args = array_map(function ($val) {
                            if (is_numeric($val)) {
                                return $val + 0;
                            }
                            $val = trim($val);
                            if (preg_match('/^\\w+$/i', $val) && defined($val)) {
                                return constant($val);
                            }
                            return preg_replace('/\\\\"/', '"', $val);
                        }, str_getcsv(preg_replace('/(?<!\\\\)(")(.*?)\\1/', "\\1\\2\\1", trim($rval))));
                        preg_match('/^(?<section>[^:]+)(?:\\:(?<func>.+))?/', $sec, $parts);
                        $func = isset($parts['func']) ? $parts['func'] : NULL;
                        $custom = strtolower($parts['section']) != 'globals';
                        if ($func) {
                            $args = [$this->call($func, $args)];
                        }
                        if (count($args) > 1) {
                            $args = [$args];
                        }
                        if (isset($ttl)) {
                            $args = array_merge($args, [$ttl]);
                        }
                        call_user_func_array([$this, 'set'], array_merge([($custom ? $parts['section'] . '.' : '') . $match['lval']], $args));
                    }
                }
            }
        }
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: Base.php プロジェクト: mamtou/wavephp
 /**
  * 清理
  */
 public function clear()
 {
     self::$frameworkPath = '';
     self::$projectPath = '';
     self::$projectName = '';
     self::$config = '';
     self::$import = '';
     self::$hostInfo = '';
     self::$pathInfo = '';
     self::$homeUrl = '';
     self::$baseUrl = '';
     self::$defaultControl = '';
 }
All Usage Examples Of Base::config