blob: 57fd9b90b259664be79b5846e3c6fe82d094fe34 (
plain)
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
|
<?php
namespace JsonApi\Routes\Clipboards;
use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\JsonApiController;
use JsonApi\Routes\ValidationTrait;
use Psr\Http\Message\{
ResponseInterface as Response,
ServerRequestInterface as Request
};
final class ClipboardsCreate extends JsonApiController
{
use ValidationTrait;
public function __invoke(Request $request, Response $response, $args): Response
{
$user = $this->getUser($request);
if (!Authority::canCreateClipboard($user)) {
throw new AuthorizationFailedException();
}
$json = $this->validate($request, $args);
$clipboard = \Clipboard::create([
'name' => $json['data']['attributes']['name'],
'user_id' => $user->id,
]);
return $this->getContentResponse($clipboard);
}
protected function validateResourceDocument($json, $data)
{
if (!self::arrayHas($json, 'data.attributes.name')) {
return 'No name for the clipboard defined';
}
if (!trim(self::arrayGet($json, 'data.attributes.name'))) {
return 'Name of the clipboard may not be empty';
}
return null;
}
}
|