Пример #1
0
 /**
  * Set temp path
  * @param string $tempPath
  */
 public function setOutputDir($tempPath)
 {
     $tempPath = Path::normalize($tempPath);
     if (!is_dir($tempPath)) {
         throw new FileNotFoundException("Temp path '{$tempPath}' does not exist.");
     }
     if (!is_writable($tempPath)) {
         throw new InvalidArgumentException("Directory '{$tempPath}' is not writeable.");
     }
     $this->outputDir = $tempPath;
 }
Пример #2
0
 public static function split($path)
 {
     $path = Path::normalize($path);
     $ret = array();
     // we cut drive letter if os == windows and put it as first element
     if ('\\' == self::SEPARATOR && preg_match('#^([a-z]:\\\\)#i', $path, $match)) {
         $ret[] = substr($match[1], 0, 2);
         $path = str_replace($match[1], '', $path);
     }
     return array_merge($ret, explode(self::SEPARATOR, $path));
 }
Пример #3
0
 /**
  * Make path absolute
  * @param $path string
  * @throws \WebLoader\FileNotFoundException
  * @return string
  */
 public function cannonicalizePath($path)
 {
     $rel = Path::normalize($this->root . "/" . $path);
     if (file_exists($rel)) {
         return $rel;
     }
     $abs = Path::normalize($path);
     if (file_exists($abs)) {
         return $abs;
     }
     throw new FileNotFoundException("File '{$path}' does not exist.");
 }
Пример #4
0
 public function rename($newPath)
 {
     $newPathNormalized = Path::normalize($newPath);
     $success = true;
     if ($this->isExists()) {
         $success = rename($this->getPhysicalPath(), Path::convertLogicalToPhysical($newPathNormalized));
     }
     if ($success) {
         $this->originalPath = $newPath;
         $this->path = $newPathNormalized;
         $this->pathPhysical = null;
     }
     return $success;
 }
Пример #5
0
 public static function nettoyer_chemin($chemin, $est_un_motif = false)
 {
     // SÉCURITÉ : $chemin nettoyé
     //   * Ne contient pas '\0'
     //   * Ne contient pas '../'
     //   * Ne contient pas de double occurence de '/'
     //   * Ne se termine pas par '/'
     //   * Ne commence pas par '/'
     //   * Est découpé en segments
     //   * Chaque segment est nettoyé avec nettoyer_segment().
     $chemin = preg_replace("/\\0/", '', $chemin);
     // TODO : vérifier si c'est bien ça ! (supprime _toutes_ les occurences ???)
     $chemin = Path::normalize($chemin);
     $chemin = preg_replace("/^\\/*/", '', $chemin);
     $chemin = preg_replace("/\\/*\$/", '', $chemin);
     $segments = qw($chemin, '/');
     if ($est_un_motif) {
         $segments = array_map(array("self", "nettoyer_segment_motif"), $segments);
     } else {
         $segments = array_map(array("self", "nettoyer_segment"), $segments);
     }
     return $segments;
 }
Пример #6
0
 /**
  * Relative path to public temp directory
  * @param null|string $fileName
  * @return string
  */
 public function getRelative($fileName = null)
 {
     return Path::normalize($this->relative . (empty($fileName) ? '' : '/' . $fileName));
 }
Пример #7
0
 /**
  * @dataProvider getNormalizeData
  */
 public function testNormalize($path, $expected)
 {
     $this->assertEquals($expected, Path::normalize($path));
 }