-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample.Routes.php
More file actions
90 lines (85 loc) · 2.59 KB
/
Copy pathExample.Routes.php
File metadata and controls
90 lines (85 loc) · 2.59 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/* ------------------------------------------------------ *\
| ROUTES EXAMPLE |
\* ------------------------------------------------------ */
/**
* @uses \Slim\App
* for instance of $this
*/
namespace {
use PentagonalProject\ProjectSeventh\ResponseGenerator\Json;
use PentagonalProject\ProjectSeventh\ResponseGenerator\Xml;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\App;
use Slim\Http\Body;
use Slim\Http\Response;
if (!isset($this) || ! $this instanceof App) {
header('HTTP/1.1 403 Forbidden');
return;
}
$this->any(
'/helo[/[{name: [A-Za-z0-9\S]+}[/]]]',
function (
ServerRequestInterface $request,
ResponseInterface $response,
$args
) {
/**
* @var Response $response
* @var Body $body
*/
$body = $response->getBody();
$body->write(
sprintf(
'"Helo <b>%1$s</b>, You are in (%2$s)',
isset($args['name']) ? $args['name'] : 'you!',
$request->getUri()
)
);
return $response->withBody($body);
}
);
$this->any(
'/xml[/]',
function (
ServerRequestInterface $request,
ResponseInterface $response
) {
return Xml::generate($request, $response)
->setData([
'KeyData' => [
'TestDataArray' => 'Value',
'TestDataArray2' => 'Value',
'TestDataArrayValue' => [
'Value'
],
]
])
->setStatusCode(404)
->serve();
}
);
$this->any(
'/json[/]',
function (
ServerRequestInterface $request,
ResponseInterface $response
) {
return Json::generate($request, $response)
->setData([
'KeyData' => [
'TestDataArray' => 'Value',
'TestDataArray2' => 'Value',
'TestDataArrayValue' => [
'Value'
],
]
])
// add encoding option
->setEncoding(JSON_PRETTY_PRINT | JSON_FORCE_OBJECT)
->setStatusCode(404)
->serve();
}
);
}