Пример #1
0
 public function testFnmatch()
 {
     $pattern = 'test.jpg';
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'test.jpg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test1.jpg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test.gif'));
     $pattern = 'test*.jpg';
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'test.jpg'));
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'test10.jpg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test.gif'));
     $pattern = 'test?.jpg';
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test.jpg'));
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'test1.jpg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test10.jpg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test.gif'));
     $pattern = 't*e*s*t.j?g';
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'test.jpg'));
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'taaassdefdfgfgskjkljllt.jpg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'test1.jpg'));
     $this->assertTrue(AdvancedPathLib::fnmatch($pattern, 'test.jmg'));
     $this->assertFalse(AdvancedPathLib::fnmatch($pattern, 'tset.jpg'));
 }
Пример #2
0
 /**
  * @param string $pattern Filter pattern (same as *NIX shell)
  * @param int $flags GLOB_NORMAL | GLOB_ONLY_DIR | GLOB_DIR_IGNORE_PATTERN
  *                       | GLOB_DIR_FIRST | GLOB_FORCE_SCANDIR | GLOB_CASEINSENSITIVE
  * 					(@see class AdvancedPathLib)
  * @return array(IFile) The list of the files contained in the "file" itself if $this
  * is a directory, or the files contained in the parent directory if $this is a
  * normal file
  */
 public function listFiles($pattern = '*', $flags = AdvancedPathLib::GLOB_NORMAL)
 {
     if (is_array($pattern)) {
         Logger::getLogger('system.services.FileSystem.FTPFile')->warn('FTPFile::listFiles() does not handle array as $pattern yet, using "*" instead.');
         //FIXME --NOT IMPLEMENTED--
         $pattern = '*';
     }
     if ($this->isDirectory()) {
         $dir = $this;
     } else {
         $dir = $this->getParentFile();
     }
     if ($flags & AdvancedPathLib::GLOB_CASEINSENSITIVE) {
         $pattern = mb_sql_regcase($pattern);
     }
     $res = $this->getConnection();
     try {
         //first let's try with -A option (LIST "ALL"), but some servers may fail
         $rawList = @ftp_rawlist($res, '-a ' . $dir->getPathFromRoot());
         if ($rawList === false) {
             //then let's try with the classical LIST command alone
             $rawList = @ftp_rawlist($res, $dir->getPathFromRoot());
             if ($rawList === false) {
                 throw new EyeIOException('Unable to list files in directory ' . AdvancedPathLib::getURLForDisplay($this->path) . '.');
             }
         }
     } catch (EyeErrorException $e) {
         throw new EyeIOException('Unable to list files in directory ' . AdvancedPathLib::getURLForDisplay($this->path) . '.', 0, $e);
     }
     $parsedList = self::parseRawList($rawList, false);
     $filesObjects = array();
     foreach ($parsedList as $fileInfo) {
         if ($flags & AdvancedPathLib::GLOB_ONLY_DIR && $fileInfo['type'] != 'd') {
             continue;
         }
         if (AdvancedPathLib::fnmatch($pattern, $fileInfo['name']) !== false || $flags & AdvancedPathLib::GLOB_DIR_IGNORE_PATTERN && $fileInfo['type'] == 'd') {
             $linkTarget = false;
             if ($fileInfo['type'] == 'l') {
                 $parsedLinkName = self::parseLinkName($this, $fileInfo['name']);
                 if (is_array($parsedLinkName)) {
                     $fileInfo['name'] = $parsedLinkName[0];
                     $linkTarget = $parsedLinkName[1];
                 }
             }
             $fileParams = array('isDirectory' => $fileInfo['type'] == 'd' ? true : false, 'isFile' => $fileInfo['type'] == 'd' || $fileInfo['type'] == 'l' ? false : true, 'isLink' => $fileInfo['type'] == 'l' ? true : false, 'permissions' => $fileInfo['type'] . $fileInfo['perms'], 'size' => $fileInfo['size'], 'linkTarget' => $linkTarget);
             $newFileUrlParts = $dir->getURLComponents();
             $newFileUrlParts['path'] = AdvancedPathLib::unifyPath($newFileUrlParts['path'] . '/' . $fileInfo['name']);
             $thisClass = get_class($this);
             $newFile = new $thisClass(AdvancedPathLib::buildURL($newFileUrlParts), $fileParams);
             $filesObjects[] = $newFile;
         }
     }
     if ($flags & AdvancedPathLib::GLOB_DIR_FIRST) {
         $filesObjectsOrdered = array();
         //looking for directories
         foreach ($filesObjects as $i => $fileObject) {
             if ($fileObject->isDirectory()) {
                 $filesObjectsOrdered[] = $fileObject;
             }
         }
         //looking for files and links
         foreach ($filesObjects as $i => $fileObject) {
             if ($fileObject->isFile() || $fileObject->isLink()) {
                 $filesObjectsOrdered[] = $fileObject;
             }
         }
         $filesObjects = $filesObjectsOrdered;
     }
     return $filesObjects;
 }