Exemplo n.º 1
0
 public function testParseRawList()
 {
     // Initialize
     $sPath = '/tmp/path';
     $iSize = 200;
     $oDate = new DateTime();
     $oFile = new File($sPath, $iSize, $oDate);
     // Assert
     $this->assertEquals($oDate->getTimestamp(), $oFile->getOrderField(OrderField::MODIFICATION_DATE));
     $this->assertEquals($iSize, $oFile->getOrderField(OrderField::SIZE));
     $this->assertEquals('path', $oFile->getOrderField(OrderField::BASENAME));
     $this->assertEquals('path', $oFile->getOrderField('test'));
 }
Exemplo n.º 2
0
 /**
  * Add a file to an array of files depending on extension or pattern conditions
  * @param array $aFiles Array of files
  * @param File $oFile File to be added
  * @param array $aAllowedExtensions Allowed extensions
  * @param array $aAllowedBasenamePatterns Allowed basename patterns
  */
 public static function addFile(array &$aFiles, File $oFile, array $aAllowedExtensions = [], array $aAllowedBasenamePatterns = [])
 {
     // Do not process . and ..
     if (in_array($oFile->getBasename(), ['.', '..'])) {
         return;
     }
     // Filter allowed extensions
     if ($aAllowedExtensions !== [] and !in_array($oFile->getExtension(), $aAllowedExtensions)) {
         return;
     }
     // Filter allowed patterns
     if ($aAllowedBasenamePatterns !== []) {
         // Initialize
         $bIsValid = false;
         // Loop through allowed patterns
         foreach ($aAllowedBasenamePatterns as $sAllowedPattern) {
             if (preg_match(sprintf('/%s/', $sAllowedPattern), $oFile->getBasename()) > 0) {
                 $bIsValid = true;
                 break;
             }
         }
         // Invalid
         if (!$bIsValid) {
             return;
         }
     }
     // Add file
     $aFiles[] = $oFile;
 }