• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AJenbo / agcms / 20972217862

13 Jan 2026 08:53PM UTC coverage: 53.678% (+0.1%) from 53.541%
20972217862

Pull #74

github

web-flow
Merge 4fdfac7ee into 498ff829e
Pull Request #74: Add PHP versions 8.4 to 8.5 to CI matrix

248 of 345 new or added lines in 40 files covered. (71.88%)

6 existing lines in 5 files now uncovered.

2780 of 5179 relevant lines covered (53.68%)

13.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.23
/application/inc/Http/Request.php
1
<?php
2

3
namespace App\Http;
4

5
use App\Exceptions\InvalidInput;
6
use App\Models\User;
7
use App\Services\DbService;
8
use App\Services\OrmService;
9
use Exception;
10
use Symfony\Component\HttpFoundation\InputBag;
11
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
12
use Symfony\Component\HttpFoundation\Session\Session;
13
use Symfony\Component\HttpFoundation\Session\SessionInterface;
14
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
15

16
class Request extends SymfonyRequest
17
{
18
    private ?User $user = null;
19

20
    /**
21
     * @param array<mixed>    $query      The GET parameters
22
     * @param array<mixed>    $request    The POST parameters
23
     * @param array<mixed>    $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
24
     * @param array<mixed>    $cookies    The COOKIE parameters
25
     * @param array<mixed>    $files      The FILES parameters
26
     * @param array<mixed>    $server     The SERVER parameters
27
     * @param resource|string $content    The raw body data
28
     */
29
    public function __construct(
30
        array $query = [],
31
        array $request = [],
32
        array $attributes = [],
33
        array $cookies = [],
34
        array $files = [],
35
        array $server = [],
36
        $content = null
37
    ) {
38
        parent::__construct($query, $request, $attributes, $cookies, $files, $server, $content);
149✔
39

40
        $methode = $this->server->get('REQUEST_METHOD', 'GET');
149✔
41

42
        /** @var string */
43
        $contentType = $this->headers->get('CONTENT_TYPE', 'text/plain');
149✔
44
        if (0 === mb_strpos($contentType, 'application/json')
149✔
45
            && is_string($methode)
149✔
46
            && in_array(mb_strtoupper($methode), ['POST', 'PUT', 'DELETE', 'PATCH'], true)
149✔
47
        ) {
48
            /** @var string */
49
            $content = $this->getContent();
30✔
50
            $data = json_decode($content, true) ?? [];
30✔
51
            $data = is_array($data) ? $data : ['json' => $data];
30✔
52
            $this->request = new InputBag($data);
30✔
53
        }
54
    }
55

56
    /**
57
     * Make sure we have a session and that it has been started.
58
     */
59
    public function startSession(): void
60
    {
61
        if (!$this->hasSession()) {
×
62
            $storage = new NativeSessionStorage([
×
63
                'cookie_httponly' => 1,
64
                'cookie_path'     => '/admin/',
65
            ]);
66
            $session = new Session($storage);
×
67
            $this->setSession($session);
×
68
        } else {
69
            $session = $this->getSession();
×
70
        }
71

72
        $session->start();
×
73
    }
74

75
    /**
76
     * Set the user making the request.
77
     */
78
    public function setUser(User $user): void
79
    {
80
        $this->user = $user;
53✔
81
    }
82

83
    /**
84
     * Get the currently authenticated user.
85
     *
86
     * @throws Exception
87
     */
88
    public function user(): ?User
89
    {
90
        if ($this->user) {
53✔
91
            return $this->user;
53✔
92
        }
93

94
        $this->startSession();
×
95
        if (!$this->session instanceof SessionInterface) {
×
96
            throw new Exception('Failed to start session.');
×
97
        }
NEW
98
        $id = valint($this->session->get('login_id'));
×
99
        $hash = $this->session->get('login_hash');
×
100
        $this->session->save();
×
101

102
        if (!$id || !$hash || !is_string($hash)) {
×
103
            return null;
×
104
        }
105

106
        $user = app(OrmService::class)->getOneByQuery(
×
107
            User::class,
108
            'SELECT * FROM `users` WHERE `id` = ' . $id . ' AND access != 0 AND password = ' . app(DbService::class)->quote($hash)
×
109
        );
110
        if ($user) {
×
111
            $user->setLastLogin(time())->save();
×
112
            $this->user = $user;
×
113
        }
114

115
        return $this->user;
×
116
    }
117

118
    /**
119
     * Remove the user data from the session.
120
     *
121
     * @throws Exception
122
     */
123
    public function logout(): void
124
    {
125
        $this->startSession();
×
126
        if (!$this->session instanceof SessionInterface) {
×
127
            throw new Exception('Failed to start session.');
×
128
        }
129

130
        $this->session->remove('login_id');
×
131
        $this->session->remove('login_hash');
×
132
        $this->session->save();
×
133
        $this->user = null;
×
134
    }
135

136
    /**
137
     * @throws Exception
138
     */
139
    public function getRequestString(string $key): ?string
140
    {
141
        $value = $this->request->get($key);
19✔
142
        if ($value === null) {
19✔
143
            return null;
4✔
144
        }
145
        if (!is_string($value)) {
17✔
146
            throw new InvalidInput(_('Invalid input.'));
×
147
        }
148

149
        return $value;
17✔
150
    }
151

152
    /**
153
     * @throws Exception
154
     */
155
    public function getRequestInt(string $key): ?int
156
    {
157
        $value = $this->request->get($key);
10✔
158
        if ($value === null) {
10✔
159
            return null;
4✔
160
        }
161
        if (!ctype_digit($value) && !is_int($value)) {
7✔
162
            throw new InvalidInput(_('Invalid input.'));
×
163
        }
164

165
        return (int)$value;
7✔
166
    }
167
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc