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

Commit 6e2a3ac

Browse files
author
Thomas GASC
committed
fix minor issues
1 parent 0b6283f commit 6e2a3ac

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

examples/account-creation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Mediapart\LaPresseLibre\Operation\AccountCreation;
1212

13-
$handle(AccountCreation::class, function ($data, $is_testing) use ($public_key) {
13+
$handle(AccountCreation::class, function($data) use ($public_key) {
1414
return [
1515
'IsValid' => true,
1616
'PartenaireID' => $public_key,

examples/account-update.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Mediapart\LaPresseLibre\Operation\AccountUpdate;
1212

13-
$handle(AccountUpdate::class, function ($data, $is_testing) use ($public_key) {
13+
$handle(AccountUpdate::class, function($data) use ($public_key) {
1414
return [
1515
'IsValid' => true,
1616
'PartenaireID' => $public_key,

examples/bootstrap.php

+31-32
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

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

5-
use Zend\Diactoros\ServerRequestFactory;
6-
use Zend\Diactoros\Response;
5+
use Zend\Diactoros\ServerRequestFactory;
6+
use Zend\Diactoros\Response;
77
use Zend\Diactoros\Response\SapiEmitter;
88
use Mediapart\LaPresseLibre\Security\Identity;
99
use Mediapart\LaPresseLibre\Security\Encryption;
1010
use Mediapart\LaPresseLibre\Subscription\Type as SubscriptionType;
11-
use Mediapart\LaPresseLibre\Transaction;
12-
use Mediapart\LaPresseLibre\Endpoint;
11+
use Mediapart\LaPresseLibre\Transaction;
12+
use Mediapart\LaPresseLibre\Endpoint;
1313

1414
/*
1515
Configuration :
@@ -29,33 +29,32 @@
2929
* @param string $operation
3030
* @param callable $callback
3131
*/
32-
$handle = function($operation, $callback) use ($identity, $encryption, $public_key)
33-
{
34-
try {
35-
$request = ServerRequestFactory::fromGlobals();
36-
$transaction = new Transaction($identity, $encryption, $request);
37-
$endpoint = Endpoint::answer($operation, $callback);
38-
$result = $transaction->process($endpoint);
39-
$status = 200;
40-
} catch (\InvalidArgumentException $e) {
41-
$result = $e->getMessage();
42-
$status = 400;
43-
} catch (\UnexpectedValueException $e) {
44-
$result = $e->getMessage();
45-
$status = 401;
46-
} catch (\Exception $e) {
47-
$result = 'Internal Error';
48-
$status = 500;
49-
} finally {
50-
$response = (new Response())
51-
->withStatus($status)
52-
->withHeader('X-PART', (string) $public_key)
53-
->withHeader('X-LPL', $identity->sign($public_key))
54-
->withHeader('X-TS', (string) $identity->getDatetime()->getTimestamp())
55-
;
56-
$response->getBody()->write(200 != $status ? json_encode(['error' => $result]) : $result);
57-
}
32+
$handle = function ($operation, $callback) use ($identity, $encryption, $public_key) {
33+
try {
34+
$request = ServerRequestFactory::fromGlobals();
35+
$transaction = new Transaction($identity, $encryption, $request);
36+
$endpoint = Endpoint::answer($operation, $callback);
37+
$result = $transaction->process($endpoint);
38+
$status = 200;
39+
} catch (\InvalidArgumentException $e) {
40+
$result = $e->getMessage();
41+
$status = 400;
42+
} catch (\UnexpectedValueException $e) {
43+
$result = $e->getMessage();
44+
$status = 401;
45+
} catch (\Exception $e) {
46+
$result = 'Internal Error';
47+
$status = 500;
48+
} finally {
49+
$response = (new Response())
50+
->withStatus($status)
51+
->withHeader('X-PART', (string) $public_key)
52+
->withHeader('X-LPL', $identity->sign($public_key))
53+
->withHeader('X-TS', (string) $identity->getDatetime()->getTimestamp())
54+
;
55+
$response->getBody()->write(200 != $status ? json_encode(['error' => $result]) : $result);
56+
}
5857

59-
$emitter = new SapiEmitter();
60-
$emitter->emit($response);
58+
$emitter = new SapiEmitter();
59+
$emitter->emit($response);
6160
};

examples/verification.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
require 'bootstrap.php';
1010

11-
use Mediapart\LaPresseLibre\Operation\Verification;
11+
use Mediapart\LaPresseLibre\Operation\Verification;
12+
use Mediapart\LaPresseLibre\Subscription\Type as SubscriptionType;
1213

13-
$handle(Verification::class, function ($data, $is_testing) use ($public_key) {
14+
$handle(Verification::class, function($data) use ($public_key) {
1415
$now = new DateTime('next year');
1516

1617
return [

0 commit comments

Comments
 (0)