Skip to content

Commit ba273ce

Browse files
fix: array first item
1 parent 073c0d7 commit ba273ce

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/Controller/AbstractAuthController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ public function login($req, $res) {
3030
throw new HttpBadRequestException($req, "Username or password is required.");
3131

3232
/** Check User Entity */
33-
$user = errorHandler($this->_model->findBy(['username' => $username]));
33+
$user = errorHandler($this->_model->filter(['username' => $username]));
3434

3535
if (!$user)
3636
throw new HttpUnauthorizedException($req, 'Invalid user credentials');
3737

38-
$user = $user[0];
39-
4038
/** Verify User Password */
4139
$isValidPassword = $user->verifyPassword($password);
4240

src/Middleware/AbstractAuthMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct($user) {
2323
public function process(Request $req, RequestHandler $handler): ResponseInterface {
2424

2525
/** User Access Token */
26-
$token = str_replace('Bearer ', '', $req->getHeader('Authorization'))[0] ?? $req->getQueryParams()['accessToken'] ?? null;
26+
$token = str_replace('Bearer ', '', $req->getHeaderLine('Authorization')) ?? $req->getQueryParams()['accessToken'] ?? null;
2727

2828
if (!$token)
2929
throw new HttpUnauthorizedException($req, 'Unauthorized request');

src/Model/AbstractModel.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ public function findBy(array $args): array {
3131
return $this->repository->findBy($args);
3232
}
3333

34+
/** Filter Data by Conditional */
35+
public function filter(array $args): object {
36+
return $this->repository->findOneBy($args);
37+
}
38+
3439
/** Find Data by Id */
35-
public function findById($id) {
40+
public function findById($id): object {
3641
return $this->repository->find($id);
3742
}
3843

3944
/** Delete Data by Id */
4045
public function delete(array $args) {
41-
$row = $this->repository->findBy($args)[0] ?? null;
46+
$row = $this->repository->findOneBy($args) ?? null;
4247

4348
if ($row):
4449
$this->entityManager->remove($row);
@@ -50,7 +55,7 @@ public function delete(array $args) {
5055

5156
/** Update Data by Id */
5257
public function update(array $data, array $args) {
53-
$row = $this->repository->findBy($args)[0] ?? null;
58+
$row = $this->repository->findOneBy($args) ?? null;
5459

5560
if ($row):
5661
foreach ($data as $key => $value)
@@ -64,7 +69,7 @@ public function update(array $data, array $args) {
6469
}
6570

6671
/** Insert Data */
67-
public function insert(array $data) {
72+
public function insert(array $data): object {
6873
$row = new $this->entity;
6974

7075
foreach ($data as $key => $value)

0 commit comments

Comments
 (0)