src/acdhOeaw/fedora/Fedora.php
public function createResource(Resource $metadata, $data = '',
                                   string $path = '', string $method = 'POST'): FedoraResource {
        if (!in_array($method, array('POST', 'PUT'))) {
            throw new BadMethodCallException('method must be PUT or POST');
        }
        $baseUrl = $this->txUrl ? $this->txUrl : $this->apiUrl;
        $path    = $path ? $this->sanitizeUri($path) : $baseUrl . $this->defaultCollection;
        $request = new Request($method, $path);
        $request = self::attachData($request, $data);
        try {
            $resp = $this->sendRequest($request);
        } catch (ClientException $e) {
            if (strpos($e->getMessage(), 'tombstone resource') === false) {
                throw $e;
            }
            throw new Deleted();
        }
        $uri = $resp->getHeader('Location')[0];
        $res = $this->getResourceByUri($uri);

        // merge the metadata created by Fedora (and Doorkeeper) upon resource creation
        // with the ones provided by user
        $curMetadata = $res->getMetadata()->merge($metadata, array(RC::idProp()));
        $res->setMetadata($curMetadata);
        $res->updateMetadata();

        return $res;
    }
public function createResource(Resource $metadata, $data = '',
                                   string $path = '', string $method = 'POST'): FedoraResource {
        if (!in_array($method, array('POST', 'PUT'))) {
            throw new BadMethodCallException('method must be PUT or POST');
        }
        $baseUrl = $this->txUrl ? $this->txUrl : $this->apiUrl;
        $path    = $path ? $this->sanitizeUri($path) : $baseUrl . $this->defaultCollection;
        $request = new Request($method, $path);
        $request = self::attachData($request, $data);
        try {
            $resp = $this->sendRequest($request);
        } catch (ClientException $e) {
            if (strpos($e->getMessage(), 'tombstone resource') === false) {
                throw $e;
            }
            throw new Deleted();
        }
        $uri = $resp->getHeader('Location')[0];
        $res = $this->getResourceByUri($uri);

        // merge the metadata created by Fedora (and Doorkeeper) upon resource creation
        // with the ones provided by user
        $curMetadata = $res->getMetadata()->merge($metadata, array(RC::idProp()));
        $res->setMetadata($curMetadata);
        $res->updateMetadata();

        return $res;
    }
public function createResource ( Resource $ metadata , $ data = '' , string $ path = '' , string $ method = 'POST' ) : FedoraResource { if ( ! in_array ( $ method , array ( 'POST' , 'PUT' ) ) ) { throw new BadMethodCallException ( 'method must be PUT or POST' ) ; } $ baseUrl = $ this -> txUrl ? $ this -> txUrl : $ this -> apiUrl ; $ path = $ path ? $ this -> sanitizeUri ( $ path ) : $ baseUrl . $ this -> defaultCollection ; $ request = new Request ( $ method , $ path ) ; $ request = self :: attachData ( $ request , $ data ) ; try { $ resp = $ this -> sendRequest ( $ request ) ; } catch ( ClientException $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'tombstone resource' ) === false ) { throw $ e ; } throw new Deleted ( ) ; } $ uri = $ resp -> getHeader ( 'Location' ) [ 0 ] ; $ res = $ this -> getResourceByUri ( $ uri ) ; // merge the metadata created by Fedora (and Doorkeeper) upon resource creation // with the ones provided by user $ curMetadata = $ res -> getMetadata ( ) -> merge ( $ metadata , array ( RC :: idProp ( ) ) ) ; $ res -> setMetadata ( $ curMetadata ) ; $ res -> updateMetadata ( ) ; return $ res ; }
Creates a resource in the Fedora and returns corresponding Resource object

@param EasyRdf\Resource $metadata resource metadata
@param mixed $data optional resource data as a string,
file name or an array: ['content-type' => 'foo', 'data' => 'bar']
@param string $path optional Fedora resource path (see also the `$method`
parameter)
@param string $method creation method to use - POST or PUT, by default POST
@return \acdhOeaw\rms\FedoraResource
@throws \BadMethodCallException
Creates a resource in the Fedora and returns corresponding Resource object