Example #1
0
 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;
     }
 }
Example #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);
 }
 /**
  * Updates an existing base-model from the object with the given name.
  * Will not change anything on the object itself, only the base-model is changed.
  *
  * @param string $name The object's name.
  * @param string $baseFileName The file name the base class will be written to.
  *
  * @author Ralf Schubert
  * @version
  * Version 0.1, 15.01.2011<br />
  * Version 0.2, 15.05.2013 (Update start- and end tag with class name instead of class [Tobias Lückel|Megger])<br />
  */
 protected function updateServiceObject($name, $baseFileName)
 {
     $content = file_get_contents($baseFileName);
     $newCode = $this->generateBaseObjectCode($name);
     // replace only base object area, don't change anything else!
     // <<< *IMPORTANT* There seems to be a bug in preg_replace() which
     // causes a crash when trying to use the php-code from the old file
     // as subject as shown here:
     /* $content = preg_replace(
        '%//<\*' . $class.'Base:start\*>(.)+<\*' . $class.'Base:end\*>%s',
        $newcode,
        $content
        ); */
     // *WORKAROUND* with preg_* functions not found, used some string functions instead:
     $class = $this->domainObjectsTable[$name]['Class'];
     $className = RootClassLoader::getClassName($class);
     $startTag = '//<*' . $className . 'Base:start*>';
     $endTag = '<*' . $className . 'Base:end*>';
     $start = strpos($content, $startTag);
     $length = strpos($content, $endTag, $start) + strlen($endTag) - $start;
     $content = substr_replace($content, $newCode, $start, $length);
     // If anyone has further information or a solution for this, please
     // write a post in the APF-forum. PHP-version: found at 5.3.5  >>>
     $file = new File();
     $file->open($baseFileName)->writeContent($content);
 }