/** * WebDAV HTTP COPY method * * This method copies one uri to a different uri, and works much like the MOVE request * A lot of the actual request processing is done in getCopyMoveInfo * * @param RequestInterface $request * @param ResponseInterface $response * @return bool */ function httpCopy(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); $copyInfo = $this->server->getCopyAndMoveInfo($request); if ($copyInfo['destinationExists']) { if (!$this->server->emit('beforeUnbind', [$copyInfo['destination']])) return false; $this->server->tree->delete($copyInfo['destination']); } if (!$this->server->emit('beforeBind', [$copyInfo['destination']])) return false; $this->server->tree->copy($path, $copyInfo['destination']); $this->server->emit('afterBind', [$copyInfo['destination']]); // If a resource was overwritten we should send a 204, otherwise a 201 $response->setHeader('Content-Length', '0'); $response->setStatus($copyInfo['destinationExists'] ? 204 : 201); // Sending back false will interupt the event chain and tell the server // we've handled this method. return false; }
function testCopyMoveInfo() { $bar = new SimpleCollection('bar'); $root = new SimpleCollection('webdav', array($bar)); $server = new Server($root); $server->setBaseUri('/webdav/'); $serverVars = array('REQUEST_URI' => '/webdav/bar', 'HTTP_DESTINATION' => 'http://dev2.tribalos.com/webdav/%C3%A0fo%C3%B3', 'HTTP_OVERWRITE' => 'F'); $request = HTTP\Sapi::createFromServerArray($serverVars); $server->httpRequest = $request; $info = $server->getCopyAndMoveInfo($request); $this->assertEquals('%C3%A0fo%C3%B3', urlencode($info['destination'])); $this->assertFalse($info['destinationExists']); $this->assertFalse($info['destinationNode']); }