コード例 #1
0
ファイル: tree.php プロジェクト: poef/ariadne
 /**
  * Creates a NamedNode tree from an array with path => nodeValue entries.
  * @param  array               $tree The collapsed tree: [ $path => $data, ... ]
  * @return \arc\tree\NamedNode an object tree with parent/children relations
  */
 public static function expand($tree = null)
 {
     if (is_object($tree) && isset($tree->childNodes)) {
         return $tree;
         //FIXME: should we clone the tree to avoid shared state?
     }
     $root = new \arc\tree\NamedNode();
     if (!is_array($tree)) {
         return $root;
         // empty tree
     }
     $previousParent = $root;
     foreach ($tree as $path => $data) {
         $previousPath = $previousParent->getPath();
         $subPath = \arc\path::diff($previousPath, $path);
         if ($subPath) {
             // create missing parent nodes, input tree may be sparsely filled
             $node = \arc\path::reduce($subPath, function ($previous, $name) {
                 if ($name == '..') {
                     return $previous->parentNode;
                 }
                 return $previous->appendChild($name);
             }, $previousParent);
         } else {
             // means the previousParent is equal to the current path, e.g. the root
             $node = $previousParent;
         }
         $node->nodeValue = $data;
         $previousParent = $node;
     }
     return $root;
 }
コード例 #2
0
ファイル: PSQLStore.php プロジェクト: poef/arc-store
 public function exists($path = '')
 {
     $path = \arc\path::collapse($path, $this->path);
     $result = false;
     if ($this->exists($path)) {
         $query = 'select nodes.id from nodes where path=":path"';
         $result = $this->db->execute($query, [':path' => $path]);
     }
     return (bool) $result;
 }
コード例 #3
0
ファイル: hash.php プロジェクト: poef/ariadne
 /**
  * Compile a key-path like '/name/index/index2/' to a variable name like 'name[index][index2]'
  * @param $path
  * @param string $root
  * @return mixed
  */
 public static function compileName($path, $root = '')
 {
     return \arc\path::reduce($path, function ($result, $item) {
         $item = self::unescape($item);
         return !$result ? $item : $result . '[' . $item . ']';
     }, $root);
 }
コード例 #4
0
ファイル: Store.php プロジェクト: poef/ariadne
 /**
  *	Part of the PathTreeInterface, this function will return a new cache store with the new path.
  *  @param string $path
  *  @return \arc\cache\Store
  */
 public function cd($path)
 {
     $path = \arc\path::collapse($path, $this->currentPath);
     return new Store($this->storage, $this->timeout, $path);
 }
コード例 #5
0
ファイル: NamedNode.php プロジェクト: poef/ariadne
 /**
  *	Returns the node with the given path, relative to this node. If the path
  *  does not exist, missing nodes will be created automatically.
  *	@param string $path The path to change to
  *	@return \arc\tree\NamedNode The target node corresponding with the given path.
  */
 public function cd($path)
 {
     if (\arc\path::isAbsolute($path)) {
         $node = $this->getRootNode();
     } else {
         $node = $this;
     }
     $result = \arc\path::reduce($path, function ($node, $name) {
         switch ($name) {
             case '..':
                 return isset($node->parentNode) ? $node->parentNode : $node;
                 break;
             case '.':
             case '':
                 return $node;
                 break;
             default:
                 if (!isset($node->childNodes[$name])) {
                     return $node->appendChild($name);
                 } else {
                     return $node->childNodes[$name];
                 }
                 break;
         }
     }, $node);
     return $result;
 }
コード例 #6
0
ファイル: filesystem.php プロジェクト: poef/ariadne
 public function compile($path, $name)
 {
     global $AR;
     $arpath = path::collapse($path);
     if (strpos($arpath, $this->path, 0) !== 0) {
         return ar('error')->raiseError('invalide path for loading template', 500);
     }
     $realpath = $this->config['path'] . substr($arpath, strlen($this->path));
     $realpath = realpath($realpath) . '/';
     $template = file_get_contents($realpath . $name);
     require_once AriadneBasePath . "/modules/mod_pinp.phtml";
     $pinp = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_");
     // FIXME error checking
     $compiled = $pinp->compile(strtr($template, "\r", ""));
     $compiled = sprintf($AR->PINPtemplate, $compiled);
     return $compiled;
 }
コード例 #7
0
ファイル: pathPerformance.php プロジェクト: poef/ariadne
$starttime = microtime(true);
for ($i = 0; $i < $max; $i++) {
    $outputPath = \arc\path::collapse($inputPath);
}
$endtime = microtime(true);
echo $outputPath . "<br>\n";
echo $endtime - $starttime . "<br>\n";
echo "<br>\n";
// 100 times a 1000 random paths - 1.5 - 1.9 naive implementation - 0.14 with cache
$max2 = 1000;
$paths = array();
$filenames = array('a', 'some', '..', 'filenames', '..', 'pick', '.', 'from', '');
for ($i = 0; $i < $max2; $i++) {
    $path = '';
    if ($i & 1) {
        $path .= '/';
    }
    for ($ii = 0; $ii < 5; $ii++) {
        $path .= $filenames[array_rand($filenames, 1)] . '/';
    }
    $paths[] = $path;
}
$starttime = microtime(true);
for ($ii = 0; $ii < 100; $ii++) {
    for ($i = 0; $i < $max2; $i++) {
        $outputPath = \arc\path::collapse($paths[$i]);
    }
}
$endtime = microtime(true);
echo $outputPath;
echo $endtime - $starttime;
コード例 #8
0
ファイル: path.php プロジェクト: poef/ariadne
 /**
  *  Returns the difference between sourcePath and targetPath as a relative path in
  *  such a way that if you append the relative path to the source path and collapse
  *  that, the result is the targetPath.
  *  @param string $targetPath The target path to map to.
  *  @param string $sourcePath The source path to start with.
  *  @return string The relative path from source to target.
  */
 public static function diff($sourcePath, $targetPath)
 {
     $diff = '';
     $targetPath = \arc\path::collapse($targetPath);
     $sourcePath = \arc\path::collapse($sourcePath);
     $commonParent = \arc\path::search($sourcePath, function ($path) use($targetPath, &$diff) {
         if (!\arc\path::isChild($targetPath, $path)) {
             $diff .= '../';
         } else {
             return $path;
         }
     }, false);
     $diff .= substr($targetPath, strlen($commonParent));
     return $diff;
 }
コード例 #9
0
ファイル: system.list.entry.php プロジェクト: poef/ariadne
         if ($tail == '/') {
             $arResult[$key] = $this->data->{$first}->{$item};
         } else {
             $arResult[$key] = \arc\hash::get($this->data->{$first}->{$item}, $tail);
         }
     } else {
         if ($tail == '/') {
             $arResult[$key] = $this->data->{$first};
         } else {
             $arResult[$key] = \arc\hash::get($this->data->{$first}, $tail);
         }
     }
     break;
 case 'nlsdata':
     $first = \arc\path::head($tail);
     $tail = \arc\path::tail($tail);
     if ($tail == '/') {
         $arResult[$key] = $this->nlsdata;
     } else {
         $arResult[$key] = \arc\hash::get($this->nlsdata, $tail);
     }
     break;
 case 'custom':
     if ($tail == '/') {
         $arResult[$key] = $this->data->custom;
     } else {
         $arResult[$key] = \arc\hash::get($this->data->custom, $tail);
     }
     break;
 default:
     $arResult[$key] = null;
コード例 #10
0
ファイル: path.Test.php プロジェクト: poef/ariadne
 function testDiff()
 {
     $this->assertTrue(\arc\path::diff('/a/', '/a/b/') == 'b/');
     $this->assertTrue(\arc\path::diff('/a/', '/b/') == '../b/');
 }
コード例 #11
0
ファイル: store.php プロジェクト: poef/ariadne
 public function make_path($curr_dir, $path)
 {
     return \arc\path::collapse($path, $curr_dir);
 }
コード例 #12
0
ファイル: FileStore.php プロジェクト: poef/ariadne
 /**
  * Removes an entire subtree of cache images.
  * @param string $name The name of the image / subdir to remove.
  * @return bool
  */
 public function purge($name = '')
 {
     if ($name) {
         $this->remove($name);
     }
     $dirPath = $this->basePath . \arc\path::collapse($name);
     if (file_exists($dirPath) && is_dir($dirPath)) {
         $this->cleanup($dirPath);
     }
     return true;
 }