Beispiel #1
0
 /**
  * Looks in $basedir for files with $extension
  * @param  string                                      $basedir
  * @param  string                                      $extension
  * @return array
  * @throws \BackBee\Exception\InvalidArgumentException Occures if $basedir is unreachable
  */
 public static function getFilesByExtension($basedir, $extension)
 {
     if (!is_readable($basedir)) {
         throw new InvalidArgumentException(sprintf('Cannot read the directory %s', $basedir));
     }
     $files = [];
     $parse_url = parse_url($basedir);
     if (false !== $parse_url && isset($parse_url['scheme'])) {
         foreach (Dir::getContent($basedir) as $file) {
             if (is_dir($file)) {
                 continue;
             }
             if ('' === $extension && false === strpos(basename($file), '.') || '' !== $extension && $extension === substr($file, -1 * strlen($extension))) {
                 $files[] = $basedir . DIRECTORY_SEPARATOR . $file;
             }
         }
     } else {
         $pattern = '';
         if (!empty($extension)) {
             foreach (str_split($extension) as $letter) {
                 $pattern .= '[' . strtolower($letter) . strtoupper($letter) . ']';
             }
             $pattern = $basedir . DIRECTORY_SEPARATOR . '*.' . $pattern;
             $files = glob($pattern);
         } else {
             $pattern = $basedir . DIRECTORY_SEPARATOR . '*';
             $allFiles = glob($pattern);
             foreach ($allFiles as $filePath) {
                 if (false === strrpos($filePath, '.')) {
                     $files[] = $filePath;
                 }
             }
             unset($allFiles);
         }
     }
     sort($files);
     return $files;
 }
Beispiel #2
0
 public function testIsArrayGetContent()
 {
     $this->assertInternalType('array', Dir::getContent($this->getFixturesFolder() . 'foo'));
 }