Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas GASC committed Sep 20, 2017
1 parent 0b6283f commit 6e2a3ac
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/account-creation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Mediapart\LaPresseLibre\Operation\AccountCreation;

$handle(AccountCreation::class, function ($data, $is_testing) use ($public_key) {
$handle(AccountCreation::class, function($data) use ($public_key) {
return [
'IsValid' => true,
'PartenaireID' => $public_key,
Expand Down
2 changes: 1 addition & 1 deletion examples/account-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Mediapart\LaPresseLibre\Operation\AccountUpdate;

$handle(AccountUpdate::class, function ($data, $is_testing) use ($public_key) {
$handle(AccountUpdate::class, function($data) use ($public_key) {
return [
'IsValid' => true,
'PartenaireID' => $public_key,
Expand Down
63 changes: 31 additions & 32 deletions examples/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

require '../vendor/autoload.php';

use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\SapiEmitter;
use Mediapart\LaPresseLibre\Security\Identity;
use Mediapart\LaPresseLibre\Security\Encryption;
use Mediapart\LaPresseLibre\Subscription\Type as SubscriptionType;
use Mediapart\LaPresseLibre\Transaction;
use Mediapart\LaPresseLibre\Endpoint;
use Mediapart\LaPresseLibre\Transaction;
use Mediapart\LaPresseLibre\Endpoint;

/*
Configuration :
Expand All @@ -29,33 +29,32 @@
* @param string $operation
* @param callable $callback
*/
$handle = function($operation, $callback) use ($identity, $encryption, $public_key)
{
try {
$request = ServerRequestFactory::fromGlobals();
$transaction = new Transaction($identity, $encryption, $request);
$endpoint = Endpoint::answer($operation, $callback);
$result = $transaction->process($endpoint);
$status = 200;
} catch (\InvalidArgumentException $e) {
$result = $e->getMessage();
$status = 400;
} catch (\UnexpectedValueException $e) {
$result = $e->getMessage();
$status = 401;
} catch (\Exception $e) {
$result = 'Internal Error';
$status = 500;
} finally {
$response = (new Response())
->withStatus($status)
->withHeader('X-PART', (string) $public_key)
->withHeader('X-LPL', $identity->sign($public_key))
->withHeader('X-TS', (string) $identity->getDatetime()->getTimestamp())
;
$response->getBody()->write(200 != $status ? json_encode(['error' => $result]) : $result);
}
$handle = function ($operation, $callback) use ($identity, $encryption, $public_key) {
try {
$request = ServerRequestFactory::fromGlobals();
$transaction = new Transaction($identity, $encryption, $request);
$endpoint = Endpoint::answer($operation, $callback);
$result = $transaction->process($endpoint);
$status = 200;
} catch (\InvalidArgumentException $e) {
$result = $e->getMessage();
$status = 400;
} catch (\UnexpectedValueException $e) {
$result = $e->getMessage();
$status = 401;
} catch (\Exception $e) {
$result = 'Internal Error';
$status = 500;
} finally {
$response = (new Response())
->withStatus($status)
->withHeader('X-PART', (string) $public_key)
->withHeader('X-LPL', $identity->sign($public_key))
->withHeader('X-TS', (string) $identity->getDatetime()->getTimestamp())
;
$response->getBody()->write(200 != $status ? json_encode(['error' => $result]) : $result);
}

$emitter = new SapiEmitter();
$emitter->emit($response);
$emitter = new SapiEmitter();
$emitter->emit($response);
};
5 changes: 3 additions & 2 deletions examples/verification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

require 'bootstrap.php';

use Mediapart\LaPresseLibre\Operation\Verification;
use Mediapart\LaPresseLibre\Operation\Verification;
use Mediapart\LaPresseLibre\Subscription\Type as SubscriptionType;

$handle(Verification::class, function ($data, $is_testing) use ($public_key) {
$handle(Verification::class, function($data) use ($public_key) {
$now = new DateTime('next year');

return [
Expand Down

0 comments on commit 6e2a3ac

Please sign in to comment.