Exemplo n.º 1
0
 private function getDir($fullPath)
 {
     $dir = Util\Path::normalise(dirname($fullPath));
     if (!$dir || !$this->isInsideBase($dir)) {
         throw new \InvalidArgumentException();
     }
     return $dir;
 }
Exemplo n.º 2
0
 public function rename($from, $to)
 {
     $from = Util\Path::normalise("/{$from}");
     $to = Util\Path::normalise("/{$to}");
     $fromInfo = pathinfo($from);
     $toInfo = pathinfo($to);
     $fromNode = $this->getInternalNode($from);
     if (!$fromNode) {
         throw FileException::ENOENT();
     }
     $fromParent = $this->getInternalNode($fromInfo['dirname']);
     $toNode = $this->getInternalNode($to);
     if ($toNode && $toNode->type == Node::DIR) {
         $toParent = $toNode;
     } else {
         $toParent = $this->getInternalNode($toInfo['dirname']);
     }
     if (!$toParent) {
         throw FileException::ENOENT();
     }
     $fromNode->node->path = $to;
     $toParent->data[$toInfo['basename']] = $fromNode;
     unset($fromParent->data[$fromInfo['basename']]);
     return true;
 }
Exemplo 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}");
     }
 }