Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function open(StreamMode $mode)
 {
     $fileHandle = @fopen($this->path, $mode->getMode());
     if (false === $fileHandle) {
         throw new \RuntimeException(sprintf('File "%s" cannot be opened', $this->path));
     }
     $this->mode = $mode;
     $this->fileHandle = $fileHandle;
     return true;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function open(StreamMode $mode)
 {
     $fileHandle = fopen($this->path, $mode->getMode());
     if (false === $fileHandle) {
         return false;
     }
     $this->mode = $mode;
     $this->fileHandle = $fileHandle;
     return true;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function open(StreamMode $mode)
 {
     $baseDirPath = \Gaufrette\Util\Path::dirname($this->path);
     if ($mode->allowsWrite() && !is_dir($baseDirPath)) {
         @mkdir($baseDirPath, 0755, true);
     }
     try {
         $fileHandle = @fopen($this->path, $mode->getMode());
     } catch (\Exception $e) {
         $fileHandle = false;
     }
     if (false === $fileHandle) {
         throw new \RuntimeException(sprintf('File "%s" cannot be opened', $this->path));
     }
     $this->mode = $mode;
     $this->fileHandle = $fileHandle;
     return true;
 }
Esempio n. 4
0
 /**
  * {@inheritDoc}
  */
 public function open(StreamMode $mode)
 {
     $this->mode = $mode;
     $exists = $this->adapter->exists($this->key);
     if ($exists && !$mode->allowsExistingFileOpening() || !$exists && !$mode->allowsNewFileOpening()) {
         return false;
     }
     if ($mode->impliesExistingContentDeletion()) {
         $this->adapter->write($this->key, '');
         $this->content = '';
     } else {
         $this->content = $this->adapter->read($this->key);
     }
     $this->numBytes = Util\Size::fromContent($this->content);
     $this->position = $mode->impliesPositioningCursorAtTheEnd() ? $this->numBytes : 0;
     $this->synchronized = true;
     return true;
 }