Esempio n. 1
0
 public function __construct(FileSystem $fs, Node $node, $mode, \stdClass $buffer)
 {
     parent::__construct($fs, $node, $mode);
     if (!isset($buffer->data) || !is_string($buffer->data)) {
         throw new \InvalidArgumentException("Buffer must be stdclass string in 'data'");
     }
     $this->buffer = $buffer;
 }
Esempio n. 2
0
 public function open($path, $mode)
 {
     $fullPath = $this->getFullPath($path);
     $dir = $this->getDir($fullPath);
     $node = $this->getNode($path);
     if ($node && $node->type == Node::DIR) {
         throw FileException::EISDIR();
     }
     switch ($mode) {
         case 'r':
         case 'r+':
         case 'rb':
         case 'r+b':
         case 'rb+':
             if (!$node) {
                 throw FileException::ENOENT();
             }
             break;
         case 'x':
         case 'x+':
         case 'xb':
         case 'x+b':
         case 'xb+':
             if ($node) {
                 throw FileException::ENOENT();
             } elseif (!is_dir($dir)) {
                 throw FileException::ENOENT();
             }
             break;
         case 'a':
         case 'a+':
         case 'ab':
         case 'a+b':
         case 'ab+':
         case 'c':
         case 'c+':
         case 'cb':
         case 'c+b':
         case 'cb+':
         case 'w':
         case 'w+':
         case 'wb':
         case 'w+b':
         case 'wb+':
             if (!is_dir($dir)) {
                 throw FileException::ENOENT();
             }
             break;
         default:
             throw new \InvalidArgumentException("Unknown mode {$mode}");
     }
     $h = fopen($fullPath, $mode);
     if (!$h) {
         throw new \UnexpectedValueException();
     }
     $streamMode = Stream\Base::calculateStreamMode($mode);
     return new Stream\LocalFile($path, $mode, $streamMode, $h);
 }
Esempio n. 3
0
 public function open($path, $mode)
 {
     $path = Util\Path::normalise("/{$path}");
     $streamMode = Stream\Base::calculateStreamMode($mode);
     switch ($mode) {
         case 'r':
         case 'rb':
         case 'r+':
         case 'r+b':
         case 'rb+':
             $node = $this->getNode($path);
             if (!$node) {
                 throw FileException::ENOENT();
             }
             return $this->createStream($node, $streamMode);
             break;
         case 'x':
         case 'xb':
         case 'x+':
         case 'x+b':
         case 'xb+':
             $node = $this->getNode($path);
             if ($node) {
                 throw FileException::EEXIST();
             } else {
                 $node = $this->createNode($path, Node::FILE);
                 $this->addNode($node);
             }
             return $this->createStream($node, $streamMode);
             break;
         case 'w':
         case 'wb':
         case 'w+':
         case 'w+b':
         case 'wb+':
         case 'c':
         case 'cb':
         case 'c+':
         case 'c+b':
         case 'cb+':
         case 'a':
         case 'ab':
         case 'a+':
         case 'a+b':
         case 'ab+':
             if (!$this->exists($path)) {
                 $node = $this->createNode($path, Node::FILE);
                 $this->addNode($node);
             } else {
                 $node = $this->getNode($path);
                 if ($mode[0] == 'w') {
                     $this->setMeta($path, self::M_MTIME, time());
                 }
             }
             $stream = $this->createStream($node, $streamMode);
             if ($mode[0] == 'w') {
                 $stream->resize(0);
             } elseif ($mode[0] == 'a') {
                 $stream->seek(0, SEEK_END);
             }
             return $stream;
             break;
         default:
             throw new \InvalidArgumentException("Unknown mode {$mode}");
     }
 }