Completed
Push — master ( b97427...e235cc )
by Raffael
30:35 queued 26:08
created

Tokens::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Wopi\Api\v2;
13
14
use Balloon\App\Wopi\SessionManager;
15
use Balloon\Filesystem;
16
use Balloon\Server;
17
use Micro\Http\Response;
18
19
class Tokens
20
{
21
    /**
22
     * Session manager.
23
     *
24
     * @var SessionManager
25
     */
26
    protected $manager;
27
28
    /**
29
     * Filesystem.
30
     *
31
     * @var Filesystem
32
     */
33
    protected $fs;
34
35
    /**
36
     * Constructor.
37
     */
38
    public function __construct(Server $server, SessionManager $manager)
39
    {
40
        $this->fs = $server->getFilesystem();
41
        $this->manager = $manager;
42
    }
43
44
    /**
45
     * Create session.
46
     */
47
    public function post(string $id): Response
48
    {
49
        $node = $this->fs->getNode($id);
50
        $session = $this->manager->create($node, $this->fs->getUser());
51
52
        return (new Response())->setCode(201)->setBody([
53
            'node' => (string) $node->getId(),
54
            'access_token' => $session->getAccessToken(),
55
            'ttl' => $session->getAccessTokenTTL(),
56
        ]);
57
    }
58
}
59