-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathindex.php
35 lines (25 loc) · 1.08 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
use MessageProvider\ExampleProvider;
use React\Http\Message\Response;
use Psr\Http\Message\ServerRequestInterface;
require __DIR__ . '/../autoload.php';
$app = new FrameworkX\App();
$provider = new ExampleProvider();
$app->post('/pact-messages', function (ServerRequestInterface $request) use ($provider) {
$body = json_decode((string) $request->getBody(), true);
$message = $provider->dispatchMessage($body['description'], $body['providerStates']);
$response = new Response();
if ($message) {
$response->getBody()->write(\json_encode($message->getContents()));
return $response
->withHeader('Content-Type', 'application/json')
->withHeader('Pact-Message-Metadata', \base64_encode(\json_encode($message->getMetadata())));
}
return $response;
});
$app->post('/pact-change-state', function (ServerRequestInterface $request) use ($provider) {
$body = json_decode((string) $request->getBody(), true);
$provider->changeSate($body['action'], $body['state'], $body['params']);
return new Response();
});
$app->run();