Exemple #1
0
 /**
  * Checks whether the given path ($path) is available in the hash.
  * @param $path A list of keys to traverse, seperated by '/'
  * @param $hash The hash to search
  * @return bool
  */
 public static function exists($path, $hash)
 {
     $path = \arc\path::collapse($path);
     $parent = \arc\path::parent($path);
     $filename = basename($path);
     $hash = self::get($parent, $hash);
     return is_array($hash) && array_key_exists($filename, $hash);
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 function testCollapse()
 {
     $this->assertTrue(\arc\path::collapse('/') === '/');
     $this->assertTrue(\arc\path::collapse('/test/') === '/test/');
     $this->assertTrue(\arc\path::collapse('/test//') === '/test/');
     $this->assertTrue(\arc\path::collapse('/test/../') === '/');
     $this->assertTrue(\arc\path::collapse('test') === '/test/');
     $this->assertTrue(\arc\path::collapse('../', '/test/') === '/');
     $this->assertTrue(\arc\path::collapse('..', '/test/foo/') === '/test/');
     $this->assertTrue(\arc\path::collapse('/..//../', '/test/') === '/');
     $this->assertTrue(\arc\path::collapse('', '/test/') === '/test/');
 }
Exemple #4
0
 /**
  *	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);
 }
Exemple #5
0
 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;
 }
Exemple #6
0
$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;
Exemple #7
0
 /**
  *  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;
 }
Exemple #8
0
 public function make_path($curr_dir, $path)
 {
     return \arc\path::collapse($path, $curr_dir);
 }
Exemple #9
0
 /**
  * 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;
 }