示例#1
0
 /**
  * Rotates the files.
  */
 protected function rotate()
 {
     // update filename
     $this->url = $this->getTimedFilename();
     $this->nextRotation = new \DateTime('tomorrow');
     // skip GC of old logs if files are unlimited
     if (0 === $this->maxFiles) {
         return;
     }
     $fileInfo = pathinfo($this->filename);
     $glob = $fileInfo['dirname'] . '/' . $fileInfo['filename'] . '-*';
     if (!empty($fileInfo['extension'])) {
         $glob .= '.' . $fileInfo['extension'];
     }
     $iterator = new \GlobIterator($glob);
     $count = $iterator->count();
     if ($this->maxFiles >= $count) {
         // no files to remove
         return;
     }
     // Sorting the files by name to remove the older ones
     $array = iterator_to_array($iterator);
     usort($array, function ($a, $b) {
         return strcmp($b->getFilename(), $a->getFilename());
     });
     foreach (array_slice($array, $this->maxFiles) as $file) {
         if ($file->isWritable()) {
             unlink($file->getRealPath());
         }
     }
 }
示例#2
0
 public function generateListing()
 {
     $path = __DIR__ . '/tracks';
     $iterator = new GlobIterator($path . '/*.mp3');
     $iterator->setFlags(FilesystemIterator::KEY_AS_FILENAME);
     foreach ($iterator as $key => $fileinfo) {
         $tracks[] = 'tracks/' . $key;
     }
     return array_values(array_map("strval", $tracks));
 }
 /**
  * 
  * @param unknown $path
  * @throws \Exception
  * @return \GlobIterator
  */
 protected function getFileSystemIterator($path)
 {
     $fs = new Filesystem();
     if (!$fs->exists($path)) {
         throw new \Exception("No repository found at [{$path}]");
     }
     $directory = 'pack';
     if (!$fs->exists("{$path}/{$directory}")) {
         throw new \Exception("No '{$directory}' directory found at [{$path}]");
     }
     $iterator = new \GlobIterator("{$path}/{$directory}/*.json");
     if (!$iterator->count()) {
         throw new \Exception("No json file found at [{$path}/set]");
     }
     return $iterator;
 }
示例#4
0
<?php

$iterator = new GlobIterator('*.php');
printf("Matched %d item(s)\r\n", $iterator->count());
示例#5
0
<?php

$iter = new GlobIterator(__DIR__ . "/../../sample_dir/*");
var_dump($iter->count());
var_dump($iter->getPath());
var_dump($iter->getPathname());
var_dump($iter->getFilename());
foreach ($iter as $file) {
    echo "{$file}\n";
}
function _package_edition_package_contents_entry($contents, $type, $wildcard, $base, $is_cdn)
{
    $iterator = new GlobIterator($wildcard, FilesystemIterator::KEY_AS_PATHNAME);
    $entry = array();
    $total_size = 0;
    foreach ($iterator as $item) {
        $file = $iterator->key();
        $zip = array();
        $zip['archive'] = basename($file);
        $zip['timestamp'] = file_exists($file) ? filemtime($file) : null;
        $size = file_exists($file) ? filesize($file) : 0;
        $zip['size'] = $size;
        $total_size += $size;
        $zip['url'] = substr($file, strlen($base));
        array_push($entry, $zip);
    }
    $contents[$type . '_size'] = $total_size;
    $contents[$type . '_is_cdn'] = $is_cdn;
    $contents[$type] = $entry;
    return $contents;
}
示例#7
0
 public function createGlobIterator($flags)
 {
     if (isset($flags)) {
         $iterator = new \GlobIterator($this->getRealPath(), $flags);
     } else {
         $iterator = new \GlobIterator($this->getRealPath());
     }
     $iterator->setFileClass('Stalxed\\FileSystem\\FileObject');
     $iterator->setInfoClass('Stalxed\\FileSystem\\FileInfo');
     return $iterator;
 }