Skip to content

Commit 8bf6ff9

Browse files
authored
Merge pull request #22 from niden-code/1.x
Video 11
2 parents b762a56 + 16924b6 commit 8bf6ff9

File tree

147 files changed

+5455
-1611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+5455
-1611
lines changed

src/Domain/ADR/Payload.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
final class Payload extends PhalconPayload
3131
{
3232
/**
33-
* @param string $status
34-
* @param TPayloadDataInput $data
33+
* @param string $status
34+
* @param TPayloadDataInput $data
3535
* @param TPayloadDataInput $errors
3636
*/
3737
private function __construct(
@@ -121,7 +121,7 @@ public static function unauthorized(array $errors): self
121121
{
122122
return new self(
123123
status: DomainStatus::UNAUTHORIZED,
124-
errors:[
124+
errors: [
125125
'code' => HttpCodesEnum::Unauthorized->value,
126126
'message' => HttpCodesEnum::Unauthorized->text(),
127127
'data' => [],
@@ -140,7 +140,7 @@ public static function updated(array $data): self
140140
return new self(
141141
DomainStatus::UPDATED,
142142
[
143-
'data' => $data
143+
'data' => $data,
144144
]
145145
);
146146
}
@@ -152,7 +152,7 @@ public static function updated(array $data): self
152152
*
153153
* @param TPayloadDataInput $existing
154154
* @param TPayloadDataInput $element
155-
* @param string $key
155+
* @param string $key
156156
*
157157
* @return TPayloadDataInput
158158
*/
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Command;
15+
16+
use Phalcon\Api\Domain\ADR\InputTypes;
17+
use Phalcon\Api\Domain\Infrastructure\DataSource\Auth\DTO\AuthInput;
18+
use Phalcon\Api\Domain\Infrastructure\DataSource\Interface\SanitizerInterface;
19+
20+
/**
21+
* @phpstan-import-type TAuthLoginInput from InputTypes
22+
* @phpstan-import-type TAuthLogoutInput from InputTypes
23+
* @phpstan-import-type TAuthRefreshInput from InputTypes
24+
*/
25+
final readonly class AuthCommandFactory implements AuthCommandFactoryInterface
26+
{
27+
/**
28+
* @param SanitizerInterface $sanitizer
29+
*/
30+
public function __construct(
31+
private SanitizerInterface $sanitizer,
32+
) {
33+
}
34+
35+
/**
36+
* @param TAuthLoginInput $input
37+
*
38+
* @return AuthLoginPostCommand
39+
*/
40+
public function authenticate(array $input): AuthLoginPostCommand
41+
{
42+
/**
43+
* Sanitize the input
44+
*/
45+
$dto = AuthInput::new($this->sanitizer, $input);
46+
47+
/**
48+
* Return the command back
49+
*/
50+
return new AuthLoginPostCommand($dto->email, $dto->password);
51+
}
52+
53+
/**
54+
* @param TAuthLogoutInput $input
55+
*
56+
* @return AuthLogoutPostCommand
57+
*/
58+
public function logout(array $input): AuthLogoutPostCommand
59+
{
60+
/**
61+
* Sanitize the input
62+
*/
63+
$dto = AuthInput::new($this->sanitizer, $input);
64+
65+
/**
66+
* Return the command back
67+
*/
68+
return new AuthLogoutPostCommand($dto->token);
69+
}
70+
71+
/**
72+
* @param TAuthRefreshInput $input
73+
*
74+
* @return AuthRefreshPostCommand
75+
*/
76+
public function refresh(array $input): AuthRefreshPostCommand
77+
{
78+
/**
79+
* Sanitize the input
80+
*/
81+
$dto = AuthInput::new($this->sanitizer, $input);
82+
83+
/**
84+
* Return the command back
85+
*/
86+
return new AuthRefreshPostCommand($dto->token);
87+
}
88+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Command;
15+
16+
use Phalcon\Api\Domain\ADR\InputTypes;
17+
18+
/**
19+
* @phpstan-import-type TAuthLoginInput from InputTypes
20+
* @phpstan-import-type TAuthLogoutInput from InputTypes
21+
* @phpstan-import-type TAuthRefreshInput from InputTypes
22+
*/
23+
interface AuthCommandFactoryInterface
24+
{
25+
/**
26+
* @param TAuthLoginInput $input
27+
*
28+
* @return AuthLoginPostCommand
29+
*/
30+
public function authenticate(array $input): AuthLoginPostCommand;
31+
32+
/**
33+
* @param TAuthLogoutInput $input
34+
*
35+
* @return AuthLogoutPostCommand
36+
*/
37+
public function logout(array $input): AuthLogoutPostCommand;
38+
39+
/**
40+
* @param TAuthRefreshInput $input
41+
*
42+
* @return AuthRefreshPostCommand
43+
*/
44+
public function refresh(array $input): AuthRefreshPostCommand;
45+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Command;
15+
16+
use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;
17+
18+
final readonly class AuthLoginPostCommand implements CommandInterface
19+
{
20+
/**
21+
* @param string|null $email
22+
* @param string|null $password
23+
*/
24+
public function __construct(
25+
public ?string $email,
26+
public ?string $password,
27+
) {
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Command;
15+
16+
use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;
17+
18+
final readonly class AuthLogoutPostCommand implements CommandInterface
19+
{
20+
/**
21+
* @param string|null $token
22+
*/
23+
public function __construct(
24+
public ?string $token
25+
) {
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Command;
15+
16+
use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;
17+
18+
final readonly class AuthRefreshPostCommand implements CommandInterface
19+
{
20+
/**
21+
* @param string|null $token
22+
*/
23+
public function __construct(
24+
public ?string $token
25+
) {
26+
}
27+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Facade;
15+
16+
use Phalcon\Api\Domain\ADR\InputTypes;
17+
use Phalcon\Api\Domain\ADR\Payload;
18+
use Phalcon\Api\Domain\Application\Auth\Command\AuthCommandFactoryInterface;
19+
use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandBusInterface;
20+
21+
/**
22+
* @phpstan-import-type TAuthLoginInput from InputTypes
23+
* @phpstan-import-type TAuthLogoutInput from InputTypes
24+
* @phpstan-import-type TAuthRefreshInput from InputTypes
25+
*/
26+
final readonly class AuthFacade
27+
{
28+
/**
29+
* @param CommandBusInterface $bus
30+
*/
31+
public function __construct(
32+
private CommandBusInterface $bus,
33+
private AuthCommandFactoryInterface $factory
34+
) {
35+
}
36+
37+
/**
38+
* Authenticates users (login)
39+
*
40+
* @param TAuthLoginInput $input
41+
*
42+
* @return Payload
43+
*/
44+
public function authenticate(array $input): Payload
45+
{
46+
return $this->bus->dispatch($this->factory->authenticate($input));
47+
}
48+
49+
/**
50+
* Logout: revoke refresh token after parsing/validation.
51+
*
52+
* @param TAuthLogoutInput $input
53+
*
54+
* @return Payload
55+
*/
56+
public function logout(array $input): Payload
57+
{
58+
return $this->bus->dispatch($this->factory->logout($input));
59+
}
60+
61+
/**
62+
* Refresh: validate refresh token, issue new tokens via TokenManager.
63+
*
64+
* @param TAuthLogoutInput $input
65+
*
66+
* @return Payload
67+
*/
68+
public function refresh(array $input): Payload
69+
{
70+
return $this->bus->dispatch($this->factory->refresh($input));
71+
}
72+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Application\Auth\Handler;
15+
16+
use Phalcon\Api\Domain\ADR\InputTypes;
17+
use Phalcon\Api\Domain\Infrastructure\CommandBus\HandlerInterface;
18+
use Phalcon\Api\Domain\Infrastructure\DataSource\Validation\ValidatorInterface;
19+
use Phalcon\Api\Domain\Infrastructure\Encryption\TokenManagerInterface;
20+
21+
/**
22+
* @phpstan-import-type TAuthLogoutInput from InputTypes
23+
*/
24+
abstract class AbstractAuthLogoutRefreshHandler implements HandlerInterface
25+
{
26+
/**
27+
* @param TokenManagerInterface $tokenManager
28+
* @param ValidatorInterface $validator
29+
*/
30+
public function __construct(
31+
protected readonly TokenManagerInterface $tokenManager,
32+
protected readonly ValidatorInterface $validator,
33+
) {
34+
}
35+
}

0 commit comments

Comments
 (0)