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); }
protected function createStream(Node $node, $streamMode) { $memNode = $this->getInternalNode($node->path); if (!$memNode && $streamMode & Stream::WRITE) { $this->addNode($node); $memNode = $this->getInternalNode($node->path); } if (!$memNode) { return false; } if ($memNode->node->type == Node::DIR) { throw FileException::EISDIR(); } return new Stream\Memory($this, $node, $streamMode, $memNode->data); }