@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | use Mediapart\LaPresseLibre\Operation\AccountUpdate; |
12 | 12 | |
13 | -$handle(AccountUpdate::class, function ($data, $is_testing) use ($public_key) { |
|
13 | +$handle(AccountUpdate::class, function($data, $is_testing) use ($public_key) { |
|
14 | 14 | return [ |
15 | 15 | 'IsValid' => true, |
16 | 16 | 'PartenaireID' => $public_key, |
@@ -31,31 +31,31 @@ |
||
31 | 31 | */ |
32 | 32 | $handle = function($operation, $callback) use ($identity, $encryption, $public_key) |
33 | 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 | - } |
|
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 | + } |
|
58 | 58 | |
59 | - $emitter = new SapiEmitter(); |
|
60 | - $emitter->emit($response); |
|
59 | + $emitter = new SapiEmitter(); |
|
60 | + $emitter->emit($response); |
|
61 | 61 | }; |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | use Mediapart\LaPresseLibre\Operation\Verification; |
12 | 12 | |
13 | -$handle(Verification::class, function ($data, $is_testing) use ($public_key) { |
|
13 | +$handle(Verification::class, function($data, $is_testing) use ($public_key) { |
|
14 | 14 | $now = new DateTime('next year'); |
15 | 15 | |
16 | 16 | return [ |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | use Mediapart\LaPresseLibre\Operation\AccountCreation; |
12 | 12 | |
13 | -$handle(AccountCreation::class, function ($data, $is_testing) use ($public_key) { |
|
13 | +$handle(AccountCreation::class, function($data, $is_testing) use ($public_key) { |
|
14 | 14 | return [ |
15 | 15 | 'IsValid' => true, |
16 | 16 | 'PartenaireID' => $public_key, |