示例#1
0
 public function testNormalizePath()
 {
     $this->assertSame('/foo', CM_File_Filesystem::normalizePath('/foo'));
     $this->assertSame('/foo', CM_File_Filesystem::normalizePath('/foo/'));
     $this->assertSame('/', CM_File_Filesystem::normalizePath('/'));
     $this->assertSame('/', CM_File_Filesystem::normalizePath(''));
     $this->assertSame('/', CM_File_Filesystem::normalizePath('//'));
     $this->assertSame('/foo/mega', CM_File_Filesystem::normalizePath('/foo/bar/../mega'));
     $this->assertSame('/', CM_File_Filesystem::normalizePath('/../..'));
     $this->assertSame('/foo/bar', CM_File_Filesystem::normalizePath('/foo/./bar'));
     $this->assertSame('/foo/bar', CM_File_Filesystem::normalizePath('/foo/./bar///'));
     $this->assertSame('/foo', CM_File_Filesystem::normalizePath('../foo'));
     $this->assertSame('/foo', CM_File_Filesystem::normalizePath('foo'));
 }
示例#2
0
文件: Adapter.php 项目: cargomedia/cm
 /**
  * @param string $pathAbsolute
  * @return string
  * @throws CM_Exception
  */
 protected function _getRelativePath($pathAbsolute)
 {
     $pathAbsolute = CM_File_Filesystem::normalizePath($pathAbsolute);
     if (0 !== strpos($pathAbsolute, $this->_pathPrefix)) {
         throw new CM_Exception('Path is out of filesystem directory.', null, ['path' => $pathAbsolute]);
     }
     if ($pathAbsolute === $this->_pathPrefix) {
         return '';
     }
     return ltrim(substr($pathAbsolute, strlen($this->_pathPrefix)), '/');
 }
示例#3
0
 /**
  * @param string $path
  * @return static
  */
 public function joinPath($path)
 {
     $path = implode('/', func_get_args());
     $pathNew = CM_File_Filesystem::normalizePath($this->getPath() . '/' . $path);
     return new static($pathNew, $this->_filesystem);
 }
示例#4
0
文件: Local.php 项目: cargomedia/cm
 /**
  * @param string   $pathPrefix
  * @param string[] $fileList
  * @param string[] $dirList
  * @param boolean  $recursive
  * @throws CM_Exception
  */
 private function _listByPrefix($pathPrefix, array &$fileList, array &$dirList, $recursive)
 {
     if ($this->_isLink($pathPrefix)) {
         return;
     }
     $pathPrefix = CM_File_Filesystem::normalizePath($pathPrefix);
     $pathPrefixAbsolute = $this->_getAbsolutePath($pathPrefix);
     $filenameList = @scandir($pathPrefixAbsolute);
     if (false === $filenameList) {
         throw new CM_Exception('Cannot scan directory', null, ['path' => $pathPrefixAbsolute]);
     }
     $filenameList = array_diff($filenameList, array('.', '..'));
     $fileListLocal = array();
     foreach ($filenameList as $filename) {
         $path = ltrim($pathPrefix . '/' . $filename, '/');
         $pathAbsolute = $pathPrefixAbsolute . '/' . $filename;
         if (is_dir($pathAbsolute)) {
             if ($recursive) {
                 $this->_listByPrefix($path, $fileList, $dirList, true);
             }
             $dirList[] = $path;
         } else {
             $fileListLocal[] = $path;
         }
     }
     foreach ($fileListLocal as $filePath) {
         $fileList[] = $filePath;
     }
 }