Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Chullo and FedoraApi classes #70

Merged
merged 9 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ Then just `php composer.phar install` as usual.

## Usage

### Fedora
```php
use Islandora\Chullo\Chullo;

// Instantiated with static factory
$chullo = Chullo::create('http://localhost:8080/fcrepo/rest');
$chullo = FedoraApi::create('http://localhost:8080/fcrepo/rest');

// Create a new resource
$uri = $chullo->createResource(); // http://localhost:8080/fcrepo/rest/0b/0b/6c/68/0b0b6c68-30d8-410c-8a0e-154d0fd4ca20
Expand Down
270 changes: 0 additions & 270 deletions src/Chullo.php

This file was deleted.

75 changes: 75 additions & 0 deletions src/FedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,79 @@ public function deleteResource(
$options
);
}

/**
* Saves RDF in Fedora.
*
* @param EasyRdf_Resource $graph Graph to save
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function saveGraph(
\EasyRdf_Graph $graph,
$uri = '',
$headers = []
) {
// Serialze the rdf.
$turtle = $graph->serialise('turtle');

// Checksum it.
$checksum_value = sha1($turtle);

// Set headers.
$headers['Content-Type'] = 'text/turtle';
$headers['digest'] = 'sha1=' . $checksum_value;

// Save it.
return $this->saveResource($uri, $turtle, $headers);
}

/**
* Creates RDF in Fedora.
*
* @param EasyRdf_Resource $graph Graph to save
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function createGraph(
\EasyRdf_Graph $graph,
$uri = '',
$headers = []
) {
// Serialze the rdf.
$turtle = $graph->serialise('turtle');

// Checksum it.
$checksum_value = sha1($turtle);

// Set headers.
$headers['Content-Type'] = 'text/turtle';
$headers['digest'] = 'sha1=' . $checksum_value;

// Save it.
return $this->createResource($uri, $turtle, $headers);
}


/**
* Gets RDF in Fedora.
*
* @param ResponseInterface $request Response received
*
* @return \EasyRdf_Graph
*/
public function getGraph(ResponseInterface $response)
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannylamb you want this to be parseGraph?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe? I'll leave it to your judgement. If you think getGraph makes sense then its fine.

// Extract rdf as response body and return Easy_RDF Graph object.
$rdf = $response->getBody()->getContents();
$graph = new \EasyRdf_Graph();
if (!empty($rdf)) {
$graph->parse($rdf, 'jsonld');
}
return $graph;
}
}
13 changes: 13 additions & 0 deletions src/IFedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,17 @@ public function deleteResource(
$uri = "",
$headers = []
);

/**
* Saves RDF in Fedora.
*
* @param EasyRdf_Resource $rdf Graph to save
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*/
public function saveGraph(
\EasyRdf_Graph $graph,
$uri = "",
$headers = []
);
}
Loading