Esempio n. 1
0
 /**
  *	Configure framework according to .ini-style file settings;
  *	If optional 2nd arg is provided, template strings are interpreted
  *	@return object
  *	@param $file string
  *	@param $allow bool
  **/
 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';
         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);
                 }
             } else {
                 if ($allow) {
                     $match['lval'] = Preview::instance()->resolve($match['lval']);
                     $match['rval'] = Preview::instance()->resolve($match['rval']);
                 }
                 if (preg_match('/^(config|route|map|redirect)s\\b/i', $sec, $cmd)) {
                     call_user_func_array(array($this, $cmd[1]), array_merge(array($match['lval']), str_getcsv($match['rval'])));
                 } else {
                     $args = array_map(function ($val) {
                         if (is_numeric($val)) {
                             return $val + 0;
                         }
                         $val = ltrim($val);
                         if (preg_match('/^\\w+$/i', $val) && defined($val)) {
                             return constant($val);
                         }
                         return trim(preg_replace(array('/\\\\"/', '/\\\\\\h*(\\r?\\n)/'), array('"', '\\1'), $val));
                     }, str_getcsv(preg_replace('/(?<!\\\\)(")(.*?)\\1/', "\\1\\2\\1", $match['rval'])));
                     preg_match('/^(?<section>[^:]+)(?:\\:(?<func>.+))?/', $sec, $parts);
                     $func = isset($parts['func']) ? $parts['func'] : NULL;
                     $custom = strtolower($parts['section']) != 'globals';
                     if ($func) {
                         $args = array($this->call($func, count($args) > 1 ? array($args) : $args));
                     }
                     call_user_func_array(array($this, 'set'), array_merge(array(($custom ? $parts['section'] . '.' : '') . $match['lval']), count($args) > 1 ? array($args) : $args));
                 }
             }
         }
     }
     return $this;
 }
Esempio n. 2
0
 function afterRoute($f3)
 {
     $f3->set('active', 'Multilang');
     echo \Preview::instance()->render('tests.htm');
 }
Esempio n. 3
0
 /**
  *	Configure framework according to .ini-style file settings;
  *	If optional 2nd arg is provided, template strings are interpreted
  *	@return object
  *	@param $file string
  *	@param $allow bool
  **/
 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;
 }