diff --git a/.travis.yml b/.travis.yml index 3c9cf40..cf225c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 3a43ed1..649d272 100644 --- a/README.md +++ b/README.md @@ -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/) @@ -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 @@ -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 = << - - <> 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 diff --git a/composer.json b/composer.json index 52f180c..0fa4caa 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Chullo.php b/src/Chullo.php index 4ec73a1..f013275 100644 --- a/src/Chullo.php +++ b/src/Chullo.php @@ -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; - } } diff --git a/src/FedoraApi.php b/src/FedoraApi.php index 11fbd25..ca4020c 100644 --- a/src/FedoraApi.php +++ b/src/FedoraApi.php @@ -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, '/'); - } } diff --git a/src/IFedoraApi.php b/src/IFedoraApi.php index fb7f958..2d0ff12 100644 --- a/src/IFedoraApi.php +++ b/src/IFedoraApi.php @@ -117,54 +117,4 @@ public function deleteResource( $uri, $transaction = "" ); - /** - * Issues a COPY request to Fedora. - * - * @param string $uri Resource URI - * @param array $destination Destination URI - * @param string $transaction Transaction id - */ - public function copyResource( - $uri, - $destination, - $transaction = "" - ); - /** - * Issues a MOVE request to Fedora. - * - * @param string $uri Resource URI - * @param array $destination Destination URI - * @param string $transaction Transaction id - */ - public function moveResource( - $uri, - $destination, - $transaction = "" - ); - - /** - * Creates a new transaction. - */ - public function createTransaction(); - - /** - * Extends a transaction. - * - * @param string $id Transaction id - */ - public function extendTransaction($id); - - /** - * Commits a transaction. - * - * @param string $id Transaction id - */ - public function commitTransaction($id); - - /** - * Rolls back a transaction. - * - * @param string $id Transaction id - */ - public function rollbackTransaction($id); } diff --git a/src/Uuid/IUuidGenerator.php b/src/Uuid/IUuidGenerator.php deleted file mode 100644 index d0fde43..0000000 --- a/src/Uuid/IUuidGenerator.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT - * @link http://www.islandora.ca - */ - -namespace Islandora\Chullo\Uuid; - -/** - * Interface for generating UUIDs. - */ -interface IUuidGenerator -{ - - /** - * Generates a v4 UUID. - * - * @return String Valid v4 UUID. - */ - public function generateV4(); - - /** - * Generates a v5 UUID. - * - * @return String Valid v5 UUID. - */ - public function generateV5($name, $namespace = null); -} diff --git a/src/Uuid/UuidGenerator.php b/src/Uuid/UuidGenerator.php deleted file mode 100644 index 67442ac..0000000 --- a/src/Uuid/UuidGenerator.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT - * @link http://www.islandora.ca - */ - -namespace Islandora\Chullo\Uuid; - -use Ramsey\Uuid\Uuid; - -/** - * Generator for v4 & v5 UUIDs. - */ -class UuidGenerator implements IUuidGenerator -{ - /** - * @var string $namespace - * The UUID for this namespace. - */ - protected $namespace; - - /** - * @param string $namespace - * The initial namespace for the Uuid Generator. - * - * @codeCoverageIgnore - */ - public function __construct($namespace = null) - { - // Give sensible default namespace if none is provided. - if (empty($namespace)) { - $namespace = "islandora.ca"; - } - - // If we are passed a namespace UUID don't generate it. - if (Uuid::isValid($namespace)) { - $this->namespace = $namespace; - } // Otherwise generate a namespace UUID from the passed in namespace. - else { - $this->namespace = Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace); - } - } - - /** - * Generates a v4 UUID. - * - * @return String Valid v4 UUID. - */ - public function generateV4() - { - return Uuid::uuid4()->toString(); - } - - /** - * Generates a v5 UUID. - * - * @param string $str - * The word to generate the UUID with. - * @param string $namespace - * A namespace - * @return String Valid v5 UUID. - */ - public function generateV5($str, $namespace = null) - { - // Use default namespace if none is provided. - if (!empty($namespace)) { - // Is this a UUID already? - if (Uuid::isValid($namespace)) { - return Uuid::uuid5($namespace, $str)->toString(); - } else { - return Uuid::uuid5(Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace), $str)->toString(); - } - } else { - return Uuid::uuid5($this->namespace, $str)->toString(); - } - } -} diff --git a/test/CommitTransactionTest.php b/test/CommitTransactionTest.php deleted file mode 100644 index e1a4215..0000000 --- a/test/CommitTransactionTest.php +++ /dev/null @@ -1,54 +0,0 @@ - $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->commitTransaction("tx:abc-123"); - $this->assertTrue($result); - } - - /** - * @covers Islandora\Chullo\Chullo::commitTransaction - * @covers Islandora\Chullo\FedoraApi::commitTransaction - * @uses GuzzleHttp\Client - */ - public function testReturnsFalseOtherwise() - { - $mock = new MockHandler([ - new Response(410), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->commitTransaction("tx:abc-123"); - $this->assertFalse($result); - } -} diff --git a/test/CopyResourceTest.php b/test/CopyResourceTest.php deleted file mode 100644 index 38647ac..0000000 --- a/test/CopyResourceTest.php +++ /dev/null @@ -1,65 +0,0 @@ - "http://localhost:8080/fcrepo/rest/SOME_URI"]), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->copyResource("", ""); - $this->assertSame($result, "http://localhost:8080/fcrepo/rest/SOME_URI"); - } - - /** - * @covers Islandora\Chullo\Chullo::copyResource - * @covers Islandora\Chullo\FedoraApi::copyResource - * @uses GuzzleHttp\Client - */ - public function testReturnsNullOtherwise() - { - $mock = new MockHandler([ - new Response(404), - new Response(409), - new Response(502), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - //404 - $result = $client->copyResource("", ""); - $this->assertNull($result); - - //409 - $result = $client->copyResource("", ""); - $this->assertNull($result); - - //502 - $result = $client->copyResource("", ""); - $this->assertNull($result); - } -} diff --git a/test/CreateTransactionTest.php b/test/CreateTransactionTest.php deleted file mode 100644 index fb53681..0000000 --- a/test/CreateTransactionTest.php +++ /dev/null @@ -1,66 +0,0 @@ - "http://localhost:8080/fcrepo/rest/tx:abc-123"]), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $this->assertEquals($client->getBaseUri(), 'http://localhost:8080/fcrepo/rest'); - - $result = $client->createTransaction(); - $this->assertSame($result, "tx:abc-123"); - } - /** - * @covers Islandora\Chullo\Chullo::createTransaction - * @covers Islandora\Chullo\Chullo::getBaseUri - * @covers Islandora\Chullo\FedoraApi::createTransaction - * @covers Islandora\Chullo\FedoraApi::prepareUri - * @covers Islandora\Chullo\FedoraApi::getBaseUri - * @covers Islandora\Chullo\FedoraApi::createTransaction - * @covers Islandora\Chullo\FedoraApi::generateTransactionUri - * @uses GuzzleHttp\Client - */ - public function testReturnsNullOtherwise() - { - $mock = new MockHandler([ - new Response(404), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - //404 - $result = $client->createTransaction(); - $this->assertNull($result); - } -} diff --git a/test/ExtendTransactionTest.php b/test/ExtendTransactionTest.php deleted file mode 100644 index 7cda5e2..0000000 --- a/test/ExtendTransactionTest.php +++ /dev/null @@ -1,54 +0,0 @@ - $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->extendTransaction("tx:abc-123"); - $this->assertTrue($result); - } - - /** - * @covers Islandora\Chullo\Chullo::extendTransaction - * @covers Islandora\Chullo\FedoraApi::extendTransaction - * @uses GuzzleHttp\Client - */ - public function testReturnsFalseOtherwise() - { - $mock = new MockHandler([ - new Response(410), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->extendTransaction("tx:abc-123"); - $this->assertFalse($result); - } -} diff --git a/test/MoveResourceTest.php b/test/MoveResourceTest.php deleted file mode 100644 index 91886a8..0000000 --- a/test/MoveResourceTest.php +++ /dev/null @@ -1,65 +0,0 @@ - "http://localhost:8080/fcrepo/rest/SOME_URI"]), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->moveResource("", ""); - $this->assertSame($result, "http://localhost:8080/fcrepo/rest/SOME_URI"); - } - - /** - * @covers Islandora\Chullo\Chullo::moveResource - * @covers Islandora\Chullo\FedoraApi::moveResource - * @uses GuzzleHttp\Client - */ - public function testReturnsNullOtherwise() - { - $mock = new MockHandler([ - new Response(404), - new Response(409), - new Response(502), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - //404 - $result = $client->moveResource("", ""); - $this->assertNull($result); - - //409 - $result = $client->moveResource("", ""); - $this->assertNull($result); - - //502 - $result = $client->moveResource("", ""); - $this->assertNull($result); - } -} diff --git a/test/RollbackTransactionTest.php b/test/RollbackTransactionTest.php deleted file mode 100644 index e1476b8..0000000 --- a/test/RollbackTransactionTest.php +++ /dev/null @@ -1,54 +0,0 @@ - $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->rollbackTransaction("tx:abc-123"); - $this->assertTrue($result); - } - - /** - * @covers Islandora\Chullo\Chullo::rollbackTransaction - * @covers Islandora\Chullo\FedoraApi::rollbackTransaction - * @uses GuzzleHttp\Client - */ - public function testReturnsFalseOtherwise() - { - $mock = new MockHandler([ - new Response(410), - ]); - - $handler = HandlerStack::create($mock); - $guzzle = new Client(['handler' => $handler]); - $api = new FedoraApi($guzzle); - $client = new Chullo($api); - - $result = $client->rollbackTransaction("tx:abc-123"); - $this->assertFalse($result); - } -} diff --git a/test/UuidGenerator/UuidTest.php b/test/UuidGenerator/UuidTest.php deleted file mode 100644 index 2bad417..0000000 --- a/test/UuidGenerator/UuidTest.php +++ /dev/null @@ -1,47 +0,0 @@ -generateV4(); - $this->assertEquals(1, preg_match($version4_regex, $uuid), "Did not build a correct Uuid V4."); - } - - /** - * @covers Islandora\Chullo\Uuid\UuidGenerator::generateV5 - */ - public function testGenerateV5() - { - $namespace = 'islandora.ca'; - $object_name = 'test_object'; - - $namespace_uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace); - $test_uuid = Uuid::uuid5($namespace_uuid->toString(), $object_name); - - $generator = new UuidGenerator($namespace); - $uuid5 = $generator->generateV5($object_name); - $this->assertEquals($test_uuid->toString(), $uuid5, "Did not build the correct UUID v5."); - - $generator2 = new UuidGenerator(); - $uuid5_2 = $generator2->generateV5($object_name, $namespace); - $this->assertEquals($test_uuid->toString(), $uuid5_2, "Did not build the correct UUID v5"); - - $generator_3 = new UuidGenerator($namespace); - $uuid5_3 = $generator2->generateV5($object_name, $namespace_uuid); - $this->assertEquals($test_uuid->toString(), $uuid5_3, "Did not build the correct UUID v5"); - } -}