Completed
Push — master ( 6ae6f0...a2576c )
by Matze
04:01
created

SettingsController::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace BrainExe\Core\Authentication\Controller;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Core\Annotations\Controller;
7
use BrainExe\Core\Annotations\Route;
8
use BrainExe\Core\Authentication\Settings\Settings;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * @Controller("Authentication.Controller.Settings")
13
 */
14
class SettingsController
15
{
16
    /**
17
     * @var Settings
18
     */
19
    private $settings;
20
21
    /**
22
     * @Inject("@User.Settings")
23
     * @param Settings $settings
24
     */
25
    public function __construct(Settings $settings)
26
    {
27
        $this->settings = $settings;
28
    }
29
30
    /**
31
     * @param Request $request
32
     * @return string[]
33
     * @Route("/settings/", name="settings.all", methods="GET")
34
     */
35
    public function all(Request $request)
36
    {
37
        return $this->settings->getAll($request->attributes->get('user_id'));
38
    }
39
40
    /**
41
     * @param Request $request
42
     * @param string $key
43
     * @param string $value
44
     * @return bool
45
     * @Route("/settings/{key}/{value}/", name="settings.set", methods="POST")
46
     */
47
    public function set(Request $request, $key, $value)
48
    {
49
        $userId = $request->attributes->get('user_id');
50
51
        $this->settings->set($userId, $key, $value);
52
53
        return true;
54
    }
55
}
56