コード例 #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;
 }
 public function current()
 {
     $file = parent::current();
     if ($file instanceof SplFileInfo) {
         // Wrap into sfFilebasePluginFile to provide additional methods
         // for analyzing file-type
         $file = new sfFilebasePluginFile($file, $this->filebase);
         if ($file->isDir()) {
             $file = new sfFilebasePluginDirectory($file, $this->filebase);
         } elseif ($file->isImage()) {
             $file = new sfFilebasePluginImage($file, $this->filebase);
         }
     }
     return $file;
 }
コード例 #3
0
 /**
  * Checks if a file really belongs to this filebase.
  *
  * @param mixed sfFilebasePluginFile | string $file
  * @return boolean true if File belongs to this Filebase
  */
 public function isInFilebase($file_to_check)
 {
     $p = self::getFilebaseFile($file_to_check);
     while (true) {
         if ($p->getPathname() == $this->getPathname()) {
             return true;
         }
         //@todo check windows fs
         if ($p->getPath() == '') {
             return false;
         }
         $p = new sfFilebasePluginDirectory($p->getPath(), $this->filebase);
         // parent dir
     }
 }
コード例 #4
0
 /**
  * Returns a new (child of) sfFilebasePluginFile. It returns an instance,
  * not regarding if the file exists or not. So you can fetch an instance
  * and create the underlying file by sfFilebasePlugin-methods.
  *
  * This method checks if file is a directory, an image
  * a link ... but beware, some attributes can only
  * be calculated if the file really exists in file system.
  *
  * For example, if you want to retrieve a directory that does
  * not exists, an instance of sfFilebasePluginFile is recieved.
  *
  * This behavior is simple and logically correct, but you have to keep it in
  * mind: sfFilebasePlugin cannot forecast what files you want to create. It
  * is probably more confusing for windows users where files are mostly
  * identified by its extension.
  *
  * If the dir exists, you'll get a sfFilebasePluginDirectory.
  *
  * @example $filebase->getFilebaseFile('path/to/directory') retrieves a dir
  *          if it exists in FS, or a sfFilebaseFile if not.
  *
  * @example Creating a new file:
  *          $new_file = $filebase->getFilebaseFile('path/to/new/file.txt');
  *          $filebase->touch($new_file);
  *          In Short: $filebase->touch('path/to/new/file.txt');
  *
  * @example Short way retrieving files:
  *          foreach ($filebase AS $file) ...
  *          with ArrayAccess:
  *          $file = $filebase['/path/to/file'];
  *
  * @todo Implement (sym)link handling.
  * @param string | sfFilebasePluginFile  $filename
  * @return sfFilebasePluginFile
  */
 public function getFilebaseFile($filename)
 {
     if (is_string($filename)) {
         //$filename = sfFilebasePluginUtil::unifySlashes($filename);
         if (strlen($filename) > 0) {
             if (sfFilebasePluginUtil::isAbsolutePathname($filename)) {
                 $filename = new sfFilebasePluginFile($filename, $this->filebase);
             } else {
                 $filename = new sfFilebasePluginFile($this->getPathname() . '/' . $filename, $this->filebase);
             }
         } else {
             $filename = $this;
         }
     }
     if ($filename instanceof sfFilebasePluginFile) {
         // returns only true if file exists, so beware of that
         if ($filename->isLink()) {
             throw new sfFilebasePluginException(sprintf('Error retrieving link %s: Link handling is not yet implemented', $filename->getPathname()));
             //return new sfFilebasePluginLink($filename->getPathname());
         } elseif ($filename->isDir()) {
             $filename = new sfFilebasePluginDirectory($filename->getPathname(), $this->filebase);
         } elseif ($this->filebase->getIsSupportedImage($filename)) {
             $filename = new sfFilebasePluginImage($filename->getPathname(), $this->filebase);
         }
         return $filename;
     }
     throw new sfFilebasePluginException(sprintf('File %s must be of type [string] or instanceof FilebaseFile', $filename));
 }