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

Align Chullo with Fedora API Spec #60

Merged
merged 1 commit into from
Mar 31, 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
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
language: php
php:
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
allow_failures:
- php: hhvm
- 7.1

before_install:
- composer install
Expand Down
30 changes: 2 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ![Chullo](https://cloud.githubusercontent.com/assets/2371345/15409650/21fd66a6-1dec-11e6-9fb3-4a1554a0fb3d.png) Chullo

Chullo is a PHP client for [Fedora 4](http://fedorarepository.org/) built using [Guzzle](http://guzzlephp.org) and [EasyRdf](http://www.easyrdf.org/).
Chullo is a PHP client for [Fedora](http://fedorarepository.org/) built using [Guzzle](http://guzzlephp.org) and [EasyRdf](http://www.easyrdf.org/).

[![Latest Stable Version](https://img.shields.io/packagist/v/Islandora/chullo.svg?style=flat-square)](https://packagist.org/packages/islandora/chullo)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.5-8892BF.svg?style=flat-square)](https://php.net/)
Expand All @@ -12,7 +12,7 @@ Chullo is a PHP client for [Fedora 4](http://fedorarepository.org/) built using

## Requirements

* PHP 5.5+
* PHP 5.6+
* [Composer](https://getcomposer.org/)

## Installation
Expand Down Expand Up @@ -60,32 +60,6 @@ $graph->set($uri, 'dc:title', 'My Sweet Title');
// Save the graph to Fedora
$chullo->saveGraph($uri, $graph);

// Open a transaction
$transaction = $chullo->createTransaction(); //tx:2b27e944-483d-4e59-a33b-f378bd42faf5

// Do a bulk upload
for ($i = 0; $i < 20; $i++) {
$rdf = <<<EOD
@prefix dc: <http://purl.org/dc/terms/>

<> dc:title "Child Resource $i"
EOD;

// Using all possible arguments in createResource() this time
$child_uri = $chullo->createResource(
$uri,
$rdf,
['Content-Type' => 'text/turtle'],
$transaction,
sha1($rdf)
);
}

// Commit it
$chullo->commitTransaction($transaction);

// Check it out:
echo $uri . "\n";
```

### Triplestore
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
"irc": "irc://irc.freenode.net/islandora"
},
"require": {
"php": ">=5.5.0",
"php": ">=5.6.0",
"guzzlehttp/guzzle": "^6.1.0",
"easyrdf/easyrdf": "^0.9.1",
"ml/json-ld": "^1.0.4",
"ramsey/uuid": "^3.1"
"ml/json-ld": "^1.0.4"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
126 changes: 0 additions & 126 deletions src/Chullo.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,130 +279,4 @@ public function deleteResource(

return $response->getStatusCode() == 204;
}

/**
* Issues a COPY request to Fedora.
*
* @param string $uri Resource URI
* @param string $destination Destination URI
* @param string $transaction Transaction id
*
* @return string Uri of newly created copy or null if failed
*/
public function copyResource(
$uri,
$destination,
$transaction = ""
) {
$response = $this->api->copyResource(
$uri,
$destination,
$transaction
);

if ($response->getStatusCode() != 201) {
return null;
}

// Return the value of the location header
$locations = $response->getHeader('Location');
return reset($locations);
}

/**
* Issues a MOVE request to Fedora.
*
* @param string $uri Resource URI
* @param string $destination Destination URI
* @param string $transaction Transaction id
*
* @return string Uri of moved resource or null if failed
*/
public function moveResource(
$uri,
$destination,
$transaction = ""
) {
$response = $this->api->moveResource(
$uri,
$destination,
$transaction
);

if ($response->getStatusCode() != 201) {
return null;
}

// Return the value of the location header
$locations = $response->getHeader('Location');
return reset($locations);
}

/**
* Creates a new transaction.
*
* @return null|string Transaction id or null if failure
*/
public function createTransaction()
{
// Create the transaction.
$uri = $this->createResource("fcr:tx");

if (empty($uri)) {
return null;
}

// Hack the tx id out of the response uri.
$trimmed = rtrim($uri, '/');
$exploded = explode('/', $trimmed);
return array_pop($exploded);
}

/**
* Extends a transaction.
*
* @param string $id Transaction id
*
* @return boolean True if successful
*/
public function extendTransaction($id)
{
$response = $this->api->extendTransaction(
$id
);

return $response->getStatusCode() == 204;
}

/**
* Commits a transaction.
*
* @param string $id Transaction id
*
* @return boolean True if successful
*/
public function commitTransaction($id)
{
$response = $this->api->commitTransaction(
$id
);

return $response->getStatusCode() == 204;
}

/**
* Rolls back a transaction.
*
* @param string $id Transaction id
*
* @return boolean True if successful
*/
public function rollbackTransaction($id)
{
$response = $this->api->rollbackTransaction(
$id
);

return $response->getStatusCode() == 204;
}
}
137 changes: 0 additions & 137 deletions src/FedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,141 +285,4 @@ protected function prepareUri($uri, $transaction = "")

return implode([$base_uri, $transaction, $relative_path], '/');
}

/**
* Issues a COPY request to Fedora.
*
* @param string $uri Resource URI
* @param string $destination Destination URI
* @param string $transaction Transaction id
*
* @return ResponseInterface
*/
public function copyResource(
$uri,
$destination,
$transaction = ""
) {
// Ensure uri takes transaction into account.
$uri = $this->prepareUri($uri, $transaction);
// Create destinsation URI
$destination_uri = $this->prepareUri($destination, $transaction);
// Create destination array
$options = [
'http_errors' => false,
'headers' => [
'Destination' => $destination_uri,
'Overwrite' => 'T'
],
];
return $this->client->request(
'COPY',
$uri,
$options
);
}

/**
* Issues a MOVE request to Fedora.
*
* @param string $uri Resource URI
* @param string $destination Destination URI
* @param string $transaction Transaction id
*
* @return ResponseInterface
*/
public function moveResource(
$uri,
$destination,
$transaction = ""
) {
// Ensure uri takes transaction into account.
$uri = $this->prepareUri($uri, $transaction);
// Create destinsation URI
$destination_uri = $this->prepareUri($destination, $transaction);
// Create destination array
$options = [
'http_errors' => false,
'headers' => [
'Destination' => $destination_uri,
'Overwrite' => 'T'
],
];
return $this->client->request(
'MOVE',
$uri,
$options
);
}

/**
* Creates a new transaction.
*
* @return ResponseInterface
*/
public function createTransaction()
{
// Create the transaction.
return $this->createResource("fcr:tx");
}

/**
* Extends a transaction.
*
* @param string $id Transaction id
*
* @return ResponseInterface
*/
public function extendTransaction($id)
{
$options = ['http_errors' => false];
$uri = $this->generateTransactionUri($id) . '/fcr:tx';
return $this->client->request(
'POST',
$uri,
$options
);
}

/**
* Commits a transaction.
*
* @param string $id Transaction id
*
* @return ResponseInterface
*/
public function commitTransaction($id)
{
$options = ['http_errors' => false];
$uri = $this->generateTransactionUri($id) . '/fcr:tx/fcr:commit';
return $this->client->request(
'POST',
$uri,
$options
);
}

/**
* Rolls back a transaction.
*
* @param string $id Transaction id
*
* @return ResponseInterface
*/
public function rollbackTransaction($id)
{
$options = ['http_errors' => false];
$uri = $this->generateTransactionUri($id) . '/fcr:tx/fcr:rollback';
return $this->client->request(
'POST',
$uri,
$options
);
}

protected function generateTransactionUri($id)
{
$base = rtrim($this->getBaseUri(), '/');
return $base . '/' . ltrim($id, '/');
}
}
Loading