예제 #1
0
 public function testParseRawList()
 {
     // Initialize
     $sBasePath = '/tmp';
     $oDateHour = DateTime::createFromFormat('F d H:i', 'Sep 22 14:45');
     $oDateYear = DateTime::createFromFormat('F d Y', 'Sep 22 2015');
     $sRawList1 = 'drwxr-xr-x 2 zmifwezd zmifwezd 4096 Sep 22 14:45 name';
     $sRawList2 = 'drwxr-xr-x 2 zmifwezd zmifwezd 4096 Sep 22 2015 name';
     $sRawList3 = 'drwxr-xr-x 2 zmifwezd zmifwezd 4096 22 sep 14:45 name';
     // Parse
     $oFile1 = Toolbox::parseRawList($sRawList1, $sBasePath);
     $oFile2 = Toolbox::parseRawList($sRawList2, $sBasePath);
     $oFile3 = Toolbox::parseRawList($sRawList3, $sBasePath);
     // Assert
     $this->assertEquals('/tmp/name', $oFile1->getPath());
     $this->assertEquals($oDateHour->getTimestamp(), $oFile1->getModificationDate()->getTimestamp());
     $this->assertEquals('/tmp/name', $oFile2->getPath());
     $this->assertEquals($oDateYear->getTimestamp(), $oFile2->getModificationDate()->getTimestamp());
     $this->assertEquals('/tmp/name', $oFile3->getPath());
     $this->assertEquals($oDateHour->getTimestamp(), $oFile3->getModificationDate()->getTimestamp());
 }
예제 #2
0
 public function explore($sPath, $iOrderField = OrderField::NONE, $iOrderDirection = OrderDirection::ASC, array $aAllowedExtensions = [], array $aAllowedBasenamePatterns = [])
 {
     // Initialize
     $aFiles = [];
     // Get files
     $aList = $this->exec(sprintf('ls -l \'%s\'', $this->escapeSingleQuotes($sPath)));
     // Remove total
     if (isset($aList[0]) && preg_match('/^total[\\s]+[0-9]+/', $aList[0]) > 0) {
         array_shift($aList);
     }
     // Add file
     foreach ($aList as $sFile) {
         // Initialize
         $oFile = Toolbox::parseRawList($sFile, $sPath);
         // Add file
         Toolbox::addFile($aFiles, $oFile, $aAllowedExtensions, $aAllowedBasenamePatterns);
     }
     // Order
     Toolbox::sortFiles($aFiles, $iOrderField, $iOrderDirection);
     // Return
     return $aFiles;
 }
예제 #3
0
 public function explore($sPath, $iOrderField = OrderField::NONE, $iOrderDirection = OrderDirection::ASC, array $aAllowedExtensions = [], array $aAllowedBasenamePatterns = [])
 {
     // Initialize
     $aFiles = [];
     // Get CURL
     $oCurl = $this->curlInit();
     // Execute CURL
     $sResponse = $this->curlExec($oCurl, $sPath, ObjectType::DIRECTORY, 'LIST -a');
     // Get files
     $aList = explode("\n", $sResponse);
     // Add file
     foreach ($aList as $sFile) {
         if ($sFile !== '') {
             // Initialize
             $oFile = Toolbox::parseRawList($sFile, $sPath);
             // Add file
             Toolbox::addFile($aFiles, $oFile, $aAllowedExtensions, $aAllowedBasenamePatterns);
         }
     }
     // Order
     Toolbox::sortFiles($aFiles, $iOrderField, $iOrderDirection);
     // Return
     return $aFiles;
 }