コード例 #1
0
 /**
  * Creates the cache directory on demand
  *
  * @param sfFilebasePluginDirectory | string: The pathname of the cache directory.
  * @return sfFilebasePluginDirectory $cache_directory
  */
 public function initCacheDirectory($cache_directory)
 {
     $this->cacheDirectory = $this->filebase->getFilebaseFile($cache_directory);
     if (!$this->cacheDirectory->fileExists()) {
         $this->cacheDirectory = $this->filebase->mkDir($this->cacheDirectory);
     }
     return $this->cacheDirectory;
 }
コード例 #2
0
 /**
  * Creates a new empty file using touch().
  *
  * @param mixed sfFilebasePluginFile | string $path
  * @param integer $perms
  * @return sfFilebasePluginFile $new_file
  */
 public function touch($path, $perms = null)
 {
     // Wrap around, because isDir() returs false on non-existing files.
     $path = new sfFilebasePluginFile($this->getFilebaseFile($path), $this);
     $dest = new sfFilebasePluginDirectory($path->getPath(), $this);
     if (!$dest->fileExists()) {
         throw new sfFilebasePluginException(sprintf('Destination directory %s does not exist.', $dest->getPathname()));
     }
     if (!$dest->isWritable()) {
         throw new sfFilebasePluginException(sprintf('Destination directory %s is write protected.', $dest->getPathname()));
     }
     if (!$this->isInFilebase($dest)) {
         throw new sfFilebasePluginException(sprintf('Destination directory %s does not belong to filebase %s, access forbidden due to security issues.', $dest->getPathname(), $this->getPathname()));
     }
     if ($path->fileExists()) {
         throw new sfFilebasePluginException(sprintf('File %s already exists', $path->getPathname()));
     }
     if (!@touch($path->getPathname())) {
         throw new sfFilebasePluginException(sprintf('Error creating file %s', $path->getPathname()));
     }
     if ($perms !== null) {
         //  Chmodde file
         $path->chmod($perms);
     }
     return $path;
 }