public function read(CacheKey $cacheKey)
 {
     // add a creation time check here to support it for all text-based providers
     $cacheFile = $this->getCacheFile($cacheKey);
     // Consider files only valid until *modification time* is at least not older than now (TTL).
     if (file_exists($cacheFile)) {
         $file = new File();
         $creationTime = $file->open($cacheFile)->getModificationTime();
         $creationTimeStamp = $creationTime->getTimestamp();
         $ttl = $this->getExpireTime($cacheKey);
         // get combined TTL with fallback on global configuration
         $now = time();
         // evaluate with "cache forever"-safe ttl check (TTL=0)
         $difference = $now - $creationTimeStamp;
         if ($ttl === 0 || $difference <= $ttl) {
             return file_get_contents($cacheFile);
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
Exemple #2
0
 /**
  * @param Folder $folder The Folder where the copy should be stored.
  * @param string $copyName The new name of the copy (optional).
  * @param boolean $getCopy If true, this method returns the copy (optional).
  *
  * @return File The domain object for further usage.
  *
  * @author  Nicolas Pecher
  * @version Version 0.1, 01.05.2012
  */
 public function createCopy(Folder $folder, $copyName = null, $getCopy = true)
 {
     $copyPath = $folder->getPath() . '/';
     $copyPath .= $copyName !== null ? $copyName : $this->getName();
     copy($this->getPath(), $copyPath);
     $copy = new File();
     $copy->open($copyPath);
     return $getCopy === true ? $copy : $this;
 }
 /**
  * Löscht die Übergebene Datei. Wird nichts übergeben, werden alle Datein gelöscht.
  *
  * @param string $uploadname
  *
  * @author Werner Liemberger <*****@*****.**>
  * @version 1.0, 14.03.2011<br>
  * @version 1.1, 14.08.2012 (Change to new File-/Folder-class)<br>
  */
 public function deleteFile($uploadname = null)
 {
     $uploadpath = $this->getUploadPath();
     if ($uploadname === null) {
         $folder = new Folder();
         $files = $folder->open($uploadpath)->getContent();
         foreach ($files as $file) {
             if (file_exists($file)) {
                 $file->delete();
             }
         }
     } else {
         if (file_exists($uploadpath . '/' . $uploadname)) {
             $file = new File();
             $file->open($uploadpath . '/' . $uploadname)->delete();
         }
     }
     $this->deleteFileFromSession($uploadname);
 }
 /**
  * Creates a new file for each the base class and the DO class with the code for
  * the object with the given name. Will overwrite existing file!
  *
  * @param string $name The object's name.
  * @param string $baseFileName The file name the base class will be written to.
  * @param string $fileName The file name the class will be written to.
  *
  * @author Ralf Schubert
  * @version
  * Version 0.1, 15.01.2011<br />
  * Version 0.2, 24.06.2014 (ID#194: split base class and DO class into separate files to better support auto loading.)<br />
  */
 protected function createNewServiceObject($name, $baseFileName, $fileName)
 {
     $namespace = $this->getNamespaceByObjectName($name);
     $path = dirname($fileName);
     if (!file_exists($path)) {
         $folder = new Folder();
         $folder->create($path);
     }
     // create base class file
     $content = '<?php' . PHP_EOL . 'namespace ' . $namespace . ';' . PHP_EOL . PHP_EOL . $this->generateBaseObjectCode($name) . PHP_EOL;
     $baseFile = new File();
     $baseFile->create($baseFileName)->writeContent($content);
     // create class file
     $content = '<?php' . PHP_EOL . 'namespace ' . $namespace . ';' . PHP_EOL . PHP_EOL . $this->generateObjectCode($name) . PHP_EOL;
     $file = new File();
     $file->create($fileName)->writeContent($content);
 }