-
Notifications
You must be signed in to change notification settings - Fork 49
/
IndexController.php
83 lines (67 loc) · 2.14 KB
/
IndexController.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
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
<?php
namespace eCampApi\V1\Rpc\Index;
use eCamp\Core\Entity\User;
use eCamp\Core\EntityService\UserService;
use Zend\Authentication\AuthenticationService;
use Zend\Mvc\Controller\AbstractActionController;
use ZF\Hal\Entity;
use ZF\Hal\Link\Link;
use ZF\Hal\View\HalJsonModel;
class IndexController extends AbstractActionController {
/** @var AuthenticationService */
private $authenticationService;
/** @var UserService */
private $userService;
public function __construct(
AuthenticationService $authenticationService,
UserService $userService
) {
$this->authenticationService = $authenticationService;
$this->userService = $userService;
}
public function indexAction() {
$data = [];
$data['title'] = 'eCamp V3 - API';
/** @var User $user */
$user = null;
$userId = $this->authenticationService->getIdentity();
if ($userId != null) {
$user = $this->userService->fetch($userId);
}
if ($user != null) {
$data['user'] = $user->getDisplayName();
$data['profile'] = Link::factory([
'rel' => 'profile',
'route' => [
'name' => 'e-camp-api.rest.doctrine.user',
'params' => [ 'user_id' => $userId ]
]
]);
} else {
$data['user'] = 'guest';
}
$data['auth'] = Link::factory([
'rel' => 'auth',
'route' => 'e-camp-api.rpc.auth'
]);
$data['self'] = Link::factory([
'rel' => 'self',
'route' => 'e-camp-api.rpc.index'
]);
$data['docu'] = Link::factory([
'rel' => 'docu',
'route' => 'zf-apigility/swagger'
]);
$data['admin'] = Link::factory([
'rel' => 'admin',
'route' => 'zf-apigility/ui'
]);
$data['camps'] = Link::factory([
'rel' => 'camps',
'route' => 'e-camp-api.rest.doctrine.camp'
]);
$json = new HalJsonModel();
$json->setPayload(new Entity($data));
return $json;
}
}