forked from pact-foundation/pact-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
36 lines (26 loc) · 1.11 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
36
<?php
use MessageProvider\ExampleProvider;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require __DIR__ . '/../../../../vendor/autoload.php';
$app = AppFactory::create();
$app->addBodyParsingMiddleware();
$provider = new ExampleProvider();
$app->post('/pact-messages', function (Request $request, Response $response) use ($provider) {
$body = $request->getParsedBody();
$message = $provider->dispatchMessage($body['description'], $body['providerStates']);
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 (Request $request, Response $response) use ($provider) {
$body = $request->getParsedBody();
$provider->changeSate($body['action'], $body['state'], $body['params']);
return $response;
});
$app->run();