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

Address https://github.com/Islandora-CLAW/CLAW/issues/302 ; Query Par… #51

Merged
merged 12 commits into from
Jul 22, 2016
40 changes: 18 additions & 22 deletions src/Chullo.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,24 @@ public function getGraph(
/**
* Creates a new resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return string Uri of newly created resource or null if failed
*/
public function createResource(
$uri = "",
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$response = $this->api->createResource(
$uri,
$content,
$headers,
$transaction,
$checksum
$transaction
);

if ($response->getStatusCode() != 201) {
Expand All @@ -188,27 +185,24 @@ public function createResource(
/**
* Saves a resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return boolean True if successful
*/
public function saveResource(
$uri,
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$response = $this->api->saveResource(
$uri,
$content,
$headers,
$transaction,
$checksum
$transaction
);

return $response->getStatusCode() == 204;
Expand All @@ -232,15 +226,17 @@ public function saveGraph(
$turtle = $graph->serialise('turtle');

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

// Save it.
return $this->saveResource(
$uri,
$turtle,
['Content-Type' => 'text/turtle'],
$transaction,
$checksum
[
'Content-Type' => 'text/turtle',
'digest' => 'sha1='.$checksum_value
],
$transaction
);
}

Expand Down
34 changes: 10 additions & 24 deletions src/FedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,18 @@ public function getResourceOptions($uri = "")
/**
* Creates a new resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return ResponseInterface
*/
public function createResource(
$uri = "",
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$options = ['http_errors' => false];

Expand All @@ -162,11 +160,6 @@ public function createResource(
// Set headers.
$options['headers'] = $headers;

// Set query string.
if (!empty($checksum)) {
$options['query'] = ['checksum' => $checksum];
}

// Ensure uri takes transaction into account.
$uri = $this->prepareUri($uri, $transaction);

Expand All @@ -180,20 +173,18 @@ public function createResource(
/**
* Saves a resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return ResponseInterface
*/
public function saveResource(
$uri,
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$options = ['http_errors' => false];

Expand All @@ -203,11 +194,6 @@ public function saveResource(
// Set headers.
$options['headers'] = $headers;

// Set query string.
if (!empty($checksum)) {
$options['query'] = ['checksum' => $checksum];
}

// Ensure uri takes transaction into account.
$uri = $this->prepareUri($uri, $transaction);

Expand Down
24 changes: 10 additions & 14 deletions src/IFedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,31 @@ public function getResourceOptions($uri = "");
/**
* Creates a new resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*/
public function createResource(
$uri = "",
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
);

/**
* Saves a resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*/
public function saveResource(
$uri,
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
);

/**
Expand Down
4 changes: 2 additions & 2 deletions test/CreateTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function testReturnsNullOtherwise()
]);

$handler = HandlerStack::create($mock);
$guzzle = new Client(['handler' => $handler]);
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']);
$api = new FedoraApi($guzzle);
$client = new Chullo($api);

//404
$result = $client->createResource();
$result = $client->createTransaction();
$this->assertNull($result);
}
}