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

Example service #126

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions services/TransactionService/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
composer.phar
vendor
17 changes: 17 additions & 0 deletions services/TransactionService/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "islandora/transaction-service",
"description": "RESTful service providing transactions in Fedora 4",
"require": {
"islandora/chullo": "^0.0.1",
"silex/silex": "^1.3"
},
"autoload": {
"psr-4": {"Islandora\\TransactionService\\": "src/"}
},
"authors": [
{
"name": "Daniel Lamb",
"email": "daniel@discoverygarden.ca"
}
]
}
79 changes: 79 additions & 0 deletions services/TransactionService/src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Islandora\TransactionService;

require_once __DIR__.'/../vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use Islandora\Chullo\Chullo;
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;

date_default_timezone_set('UTC');

$app = new Application();

$app['debug'] = true;

$app['fedora'] = function () use ($app) {
$client = new Client(['base_uri' => 'http://127.0.0.1:8080/fcrepo/rest']);
Copy link
Member

Choose a reason for hiding this comment

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

Still new to this stuff, is there a reason you didn't use the static constructor with the base_uri and get back the Chullo?
ie.

return Chullo::create('http://127.0.0.1:8080/fcrepo/rest');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason in particular. Doing it manually gives you a bit more control over the client, which in this case, is unneccessary.

return new Chullo($client);
};

$app->post(
"/islandora/transaction",
function (Application $app) {
try {
return new Response($app['fedora']->createTransaction(), 201);
}
catch (ClientException $e) {
$response = $e->getResponse();
$app->abort($response->getStatusCode(), $response->getReasonPhrase());
}
}
);

$app->post(
"/islandora/transaction/{id}/extend",
function (Application $app, $id) {
try {
$app['fedora']->extendTransaction($id);
return new Response("", 204);
}
catch (ClientException $e) {
$response = $e->getResponse();
$app->abort($response->getStatusCode(), $response->getReasonPhrase());
}
}
);

$app->post(
"/islandora/transaction/{id}/commit",
function (Application $app, $id) {
try {
$app['fedora']->commitTransaction($id);
return new Response("", 204);
}
catch (ClientException $e) {
$response = $e->getResponse();
$app->abort($response->getStatusCode(), $response->getReasonPhrase());
}
}
);

$app->post(
"/islandora/transaction/{id}/rollback",
function (Application $app, $id) {
try {
return $app['fedora']->rollbackTransaction($id);
Copy link
Member

Choose a reason for hiding this comment

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

Probably should remove this 'return'

return new Response("", 204);
}
catch (ClientException $e) {
$response = $e->getResponse();
$app->abort($response->getStatusCode(), $response->getReasonPhrase());
}
}
);

$app->run();