コード例 #1
0
ファイル: Encoder.php プロジェクト: webignition/url
 public function encode(Path $path)
 {
     $parts = explode(Path::PATH_PART_SEPARATOR, $path->get());
     foreach ($parts as $partIndex => $part) {
         $parts[$partIndex] = rawurlencode($part);
     }
     return new Path(implode(Path::PATH_PART_SEPARATOR, $parts));
 }
コード例 #2
0
ファイル: Router.php プロジェクト: ndaidong/bella.php
 public static function parse()
 {
     $m = static::getRequestMethod();
     $p = Path::get();
     $maps = static::$map[$m];
     if (!!$maps && is_array($maps) && count($maps) > 0) {
         $matching = '';
         for ($i = count($p) - 1; $i >= 0; $i--) {
             if (!$p[$i]) {
                 array_splice($p, $i, 1);
             }
         }
         $uri = implode('/', $p);
         $min = 1000;
         foreach ($maps as $map) {
             $num = 0;
             $pattern = $map->pattern;
             for ($i = count($pattern) - 1; $i >= 0; $i--) {
                 if (strpos($pattern[$i], ':') === 0) {
                     $pattern[$i] = '(\\w+)';
                     $num++;
                 }
             }
             $sroute = implode('/', $pattern);
             $matcount = 0;
             $min = min(count($pattern), count($p));
             for ($j = 0; $j < $min; $j++) {
                 if ($pattern[$j] == '(\\w+)' || $p[$j] == $pattern[$j]) {
                     $matcount++;
                     continue;
                 }
             }
             if ($matcount == count($pattern)) {
                 if (preg_match_all('#^' . $sroute . '$#', $uri, $matches)) {
                     if ($num < $min) {
                         $min = $num;
                         $matching = (object) ['route' => $map, 'data' => array_slice($matches, 1)];
                     }
                 }
             }
         }
         if (!!$matching && is_object($matching)) {
             $args = [];
             $matches = property_exists($matching, 'data') ? $matching->data : [];
             foreach ($matches as $val) {
                 array_push($args, $val[0]);
             }
             $fn = $matching->route->callback;
             call_user_func_array($fn, $args);
         }
     }
     if ($m == 'HEAD') {
         ob_end_clean();
     }
     return Bella::end();
 }
コード例 #3
0
ファイル: PathTest.php プロジェクト: Jaymon/Montage
 /**
  *  a Path instance will try and create the parent folder structure before writing
  *  the contents of the file if the parent folders don't already exist   
  *
  *  @since  9-26-11
  */
 public function testFolderAutoCreationWhenWriting()
 {
     $path_str = (string) $this->getTempPath(md5(microtime(true)), md5(microtime(true)), 'test.txt');
     $set_path_txt = 'this is the string';
     $set_path = new Path($path_str);
     $set_path->set($set_path_txt);
     $get_path = new Path($path_str);
     $get_path_txt = $get_path->get();
     $this->assertSame($set_path_txt, $get_path_txt);
 }
コード例 #4
0
ファイル: Config.php プロジェクト: siwayll/deuton
 /**
  * Fait hériter le fichier de configuration d'un autre fichier.
  * Permet d'incorporer un fichier de configuration par défaut qui sera
  * surchargé par le fichier actuel.
  *
  * @param string $path Chemin vers le fichier de configuration "défaut"
  *
  * @return void
  */
 public function setExtends($path)
 {
     $iniPath = new Path($path);
     $confPath = $iniPath->get();
     if ($confPath !== false) {
         $configBase = parse_ini_file($confPath, true);
     }
     $this->config = $this->arrayMerge($configBase, $this->config);
 }
コード例 #5
0
ファイル: Bella.php プロジェクト: ndaidong/bella.php
 public static function initialize($onstart = null, $onfly = null)
 {
     Config::init();
     if (Config::get('active') === 0) {
         return Bella::shutdown();
     }
     $q = Config::get('settings');
     if (is_dir($q->requires_dir)) {
         foreach (glob($q->requires_dir . '*.php') as $file) {
             include_once $file;
         }
     }
     if (is_dir($q->utils_dir)) {
         foreach (glob($q->utils_dir . '*.php') as $file) {
             include_once $file;
         }
     }
     Session::init();
     Path::init();
     Request::init();
     if (isset($onstart) && is_callable($onstart)) {
         $onstart();
     }
     $user = Session::get('user');
     if (!$user) {
         $user = Session::get('manager');
     }
     if (!!$user) {
         Context::set('user', $user);
     }
     $c = Path::get(0);
     if (!$c) {
         Bella::loadCoordinator('index');
     } else {
         $dir = Config::get('settings')->controllers_dir;
         $f = $dir . $c . '.php';
         if (file_exists($f)) {
             Bella::loadCoordinator($c);
         } else {
             if (isset($onfly) && is_callable($onfly)) {
                 return $onfly($c);
             }
         }
     }
 }