Example #1
0
 /**
  * 
  * @return string
  */
 public function generateNewCode()
 {
     do {
         $code = Fn::randomString();
     } while ($this->findOneByCode($code));
     return $code;
 }
Example #2
0
 /**
  *
  * @param string $path
  * @param string $filename
  * @param int $cachetime time in seconds (1 year by default)
  */
 public function __construct($path, $filename = null, $cachetime = 31536000)
 {
     parent::__construct();
     if (!is_file($path)) {
         throw new FileNotFoundException($path);
     }
     $this->file = new SplFileInfo($path);
     if (empty($filename)) {
         $filename = $this->file->getBasename();
     }
     // last modified
     $lastModified = $this->file->getMTime();
     $dateLastModified = new \DateTime();
     $dateLastModified->setTimestamp($lastModified);
     $this->setLastModified($dateLastModified);
     // etag
     $etag = dechex($lastModified);
     $this->setEtag($etag);
     $this->setFileCacheTime($cachetime);
     $mimeType = Fn::fileMimeType($filename);
     // headers
     $this->setContentLength($this->file->getSize());
     $this->setContentType($mimeType);
     $this->setContentDispositionInline($filename);
 }
Example #3
0
 public function valid()
 {
     $valid = $this->iterator->valid();
     while ($valid) {
         $filename = $this->iterator->current()->getPathname();
         $ext = Fn::fileExtension($filename);
         if ($ext !== 'original-filename' && is_file($filename . '.original-filename')) {
             $this->currentFilename = $filename;
             break;
         }
         $this->iterator->next();
         $valid = $this->iterator->valid();
     }
     return $valid;
 }