public function getCopyAndMoveInfo(RequestInterface $request)
    {
        // Collecting the relevant HTTP headers
        if (!$request->getHeader('Destination')) {
            throw new Exception\BadRequest('The destination header was not supplied');
        }
        $destination = $this->calculateUri($request->getHeader('Destination'));
        $overwrite = $request->getHeader('Overwrite');
        if (!$overwrite) {
            $overwrite = 'T';
        }
        if ('T' == strtoupper($overwrite)) {
            $overwrite = true;
        } elseif ('F' == strtoupper($overwrite)) {
            $overwrite = false;
        }
        // We need to throw a bad request exception, if the header was invalid
        else {
            throw new Exception\BadRequest('The HTTP Overwrite header should be either T or F');
        }
        list($destinationDir) = Uri\split($destination);

        try {
            $destinationParent = $this->tree->getNodeForPath($destinationDir);
            if (!($destinationParent instanceof ICollection)) {
                throw new Exception\UnsupportedMediaType('The destination node is not a collection');
            }
        } catch (Exception\NotFound $e) {
            // If the destination parent node is not found, we throw a 409
            throw new Exception\Conflict('The destination node is not found');
        }

        try {
            $destinationNode = $this->tree->getNodeForPath($destination);

            // If this succeeded, it means the destination already exists
            // we'll need to throw precondition failed in case overwrite is false
            if (!$overwrite) {
                throw new Exception\PreconditionFailed('The destination node already exists, and the overwrite header is set to false', 'Overwrite');
            }
        } catch (Exception\NotFound $e) {
            // Destination didn't exist, we're all good
            $destinationNode = false;
        }

        $requestPath = $request->getPath();
        if ($destination === $requestPath) {
            throw new Exception\Forbidden('Source and destination uri are identical.');
        }
        if (substr($destination, 0, strlen($requestPath) + 1) === $requestPath.'/') {
            throw new Exception\Conflict('The destination may not be part of the same subtree as the source path.');
        }

        // These are the three relevant properties we need to return
        return [
            'destination' => $destination,
            'destinationExists' => (bool) $destinationNode,
            'destinationNode' => $destinationNode,
        ];
    }
public function getCopyAndMoveInfo(RequestInterface $request)
    {
        // Collecting the relevant HTTP headers
        if (!$request->getHeader('Destination')) {
            throw new Exception\BadRequest('The destination header was not supplied');
        }
        $destination = $this->calculateUri($request->getHeader('Destination'));
        $overwrite = $request->getHeader('Overwrite');
        if (!$overwrite) {
            $overwrite = 'T';
        }
        if ('T' == strtoupper($overwrite)) {
            $overwrite = true;
        } elseif ('F' == strtoupper($overwrite)) {
            $overwrite = false;
        }
        // We need to throw a bad request exception, if the header was invalid
        else {
            throw new Exception\BadRequest('The HTTP Overwrite header should be either T or F');
        }
        list($destinationDir) = Uri\split($destination);

        try {
            $destinationParent = $this->tree->getNodeForPath($destinationDir);
            if (!($destinationParent instanceof ICollection)) {
                throw new Exception\UnsupportedMediaType('The destination node is not a collection');
            }
        } catch (Exception\NotFound $e) {
            // If the destination parent node is not found, we throw a 409
            throw new Exception\Conflict('The destination node is not found');
        }

        try {
            $destinationNode = $this->tree->getNodeForPath($destination);

            // If this succeeded, it means the destination already exists
            // we'll need to throw precondition failed in case overwrite is false
            if (!$overwrite) {
                throw new Exception\PreconditionFailed('The destination node already exists, and the overwrite header is set to false', 'Overwrite');
            }
        } catch (Exception\NotFound $e) {
            // Destination didn't exist, we're all good
            $destinationNode = false;
        }

        $requestPath = $request->getPath();
        if ($destination === $requestPath) {
            throw new Exception\Forbidden('Source and destination uri are identical.');
        }
        if (substr($destination, 0, strlen($requestPath) + 1) === $requestPath.'/') {
            throw new Exception\Conflict('The destination may not be part of the same subtree as the source path.');
        }

        // These are the three relevant properties we need to return
        return [
            'destination' => $destination,
            'destinationExists' => (bool) $destinationNode,
            'destinationNode' => $destinationNode,
        ];
    }
public function getCopyAndMoveInfo ( RequestInterface $ request ) { // Collecting the relevant HTTP headers if ( ! $ request -> getHeader ( 'Destination' ) ) { throw new Exception \ BadRequest ( 'The destination header was not supplied' ) ; } $ destination = $ this -> calculateUri ( $ request -> getHeader ( 'Destination' ) ) ; $ overwrite = $ request -> getHeader ( 'Overwrite' ) ; if ( ! $ overwrite ) { $ overwrite = 'T' ; } if ( 'T' == strtoupper ( $ overwrite ) ) { $ overwrite = true ; } elseif ( 'F' == strtoupper ( $ overwrite ) ) { $ overwrite = false ; } // We need to throw a bad request exception, if the header was invalid else { throw new Exception \ BadRequest ( 'The HTTP Overwrite header should be either T or F' ) ; } list ( $ destinationDir ) = Uri \ split ( $ destination ) ; try { $ destinationParent = $ this -> tree -> getNodeForPath ( $ destinationDir ) ; if ( ! ( $ destinationParent instanceof ICollection ) ) { throw new Exception \ UnsupportedMediaType ( 'The destination node is not a collection' ) ; } } catch ( Exception \ NotFound $ e ) { // If the destination parent node is not found, we throw a 409 throw new Exception \ Conflict ( 'The destination node is not found' ) ; } try { $ destinationNode = $ this -> tree -> getNodeForPath ( $ destination ) ; // If this succeeded, it means the destination already exists // we'll need to throw precondition failed in case overwrite is false if ( ! $ overwrite ) { throw new Exception \ PreconditionFailed ( 'The destination node already exists, and the overwrite header is set to false' , 'Overwrite' ) ; } } catch ( Exception \ NotFound $ e ) { // Destination didn't exist, we're all good $ destinationNode = false ; } $ requestPath = $ request -> getPath ( ) ; if ( $ destination === $ requestPath ) { throw new Exception \ Forbidden ( 'Source and destination uri are identical.' ) ; } if ( substr ( $ destination , 0 , strlen ( $ requestPath ) + 1 ) === $ requestPath . '/' ) { throw new Exception \ Conflict ( 'The destination may not be part of the same subtree as the source path.' ) ; } // These are the three relevant properties we need to return return [ 'destination' => $ destination , 'destinationExists' => ( bool ) $ destinationNode , 'destinationNode' => $ destinationNode , ] ; }
Returns information about Copy and Move requests.

This function is created to help getting information about the source and the destination for the
WebDAV MOVE and COPY HTTP request. It also validates a lot of information and throws proper exceptions

The returned value is an array with the following keys:
* destination - Destination path
* destinationExists - Whether or not the destination is an existing url (and should therefore be overwritten)

@param RequestInterface $request

@throws Exception\BadRequest           upon missing or broken request headers
@throws Exception\UnsupportedMediaType when trying to copy into a
non-collection
@throws Exception\PreconditionFailed   if overwrite is set to false, but
the destination exists
@throws Exception\Forbidden            when source and destination paths are
identical
@throws Exception\Conflict             when trying to copy a node into its own
subtree

@return array
Returns information about Copy and Move requests .