Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4ce7b57
[#.x] - folder rename
niden Nov 29, 2025
c1e7f6b
[#.x] - refactoring fixtures; added new fixtures
niden Nov 29, 2025
d151172
[#.x] - referencing di services by class name
niden Nov 29, 2025
c1685ed
[#.x] - referencing di services by class name; phpcs
niden Nov 29, 2025
fac4d8d
[#.x] - added allowEmpty for validators
niden Nov 29, 2025
dd2affd
[#.x] - added getErrorMessage to the manager
niden Nov 29, 2025
a4881e6
[#.x] - refactoring folders
niden Nov 29, 2025
f50e2f2
[#.x] - new command bus and handler locator and tests
niden Nov 29, 2025
07e8313
[#.x] - refactored folders
niden Nov 29, 2025
b9722bc
[#.x] - refactored validators to use commands
niden Nov 29, 2025
bc0e7f7
[#.x] - added auth command objects
niden Nov 29, 2025
497e0b2
[#.x] - added user command objects and factory
niden Nov 29, 2025
fc10c44
[#.x] - refactored services
niden Nov 29, 2025
deda103
[#.x] - added auth command factory
niden Nov 29, 2025
25e0742
[#.x] - refactored container definitions
niden Nov 29, 2025
fce538e
[#.x] - refactored facades to use the bus
niden Nov 29, 2025
faba40e
[#.x] - added auth handlers
niden Nov 29, 2025
c0cca08
[#.x] - added user handlers
niden Nov 29, 2025
e2343a4
[#.x] - adjusted test
niden Nov 29, 2025
c8f99e3
[#.x] - added abstract user service
niden Nov 29, 2025
80bf780
[#.x] - added more tests
niden Nov 29, 2025
33dff53
[#.x] - changed sanitizing to strip_tags and adjusted tests
niden Nov 29, 2025
16924b6
[#.x] - adjusting tests; phpcs; docblocks; minor corrections
niden Nov 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Domain/ADR/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
final class Payload extends PhalconPayload
{
/**
* @param string $status
* @param TPayloadDataInput $data
* @param string $status
* @param TPayloadDataInput $data
* @param TPayloadDataInput $errors
*/
private function __construct(
Expand Down Expand Up @@ -121,7 +121,7 @@ public static function unauthorized(array $errors): self
{
return new self(
status: DomainStatus::UNAUTHORIZED,
errors:[
errors: [
'code' => HttpCodesEnum::Unauthorized->value,
'message' => HttpCodesEnum::Unauthorized->text(),
'data' => [],
Expand All @@ -140,7 +140,7 @@ public static function updated(array $data): self
return new self(
DomainStatus::UPDATED,
[
'data' => $data
'data' => $data,
]
);
}
Expand All @@ -152,7 +152,7 @@ public static function updated(array $data): self
*
* @param TPayloadDataInput $existing
* @param TPayloadDataInput $element
* @param string $key
* @param string $key
*
* @return TPayloadDataInput
*/
Expand Down
88 changes: 88 additions & 0 deletions src/Domain/Application/Auth/Command/AuthCommandFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Command;

use Phalcon\Api\Domain\ADR\InputTypes;
use Phalcon\Api\Domain\Infrastructure\DataSource\Auth\DTO\AuthInput;
use Phalcon\Api\Domain\Infrastructure\DataSource\Interface\SanitizerInterface;

/**
* @phpstan-import-type TAuthLoginInput from InputTypes
* @phpstan-import-type TAuthLogoutInput from InputTypes
* @phpstan-import-type TAuthRefreshInput from InputTypes
*/
final readonly class AuthCommandFactory implements AuthCommandFactoryInterface
{
/**
* @param SanitizerInterface $sanitizer
*/
public function __construct(
private SanitizerInterface $sanitizer,
) {
}

/**
* @param TAuthLoginInput $input
*
* @return AuthLoginPostCommand
*/
public function authenticate(array $input): AuthLoginPostCommand
{
/**
* Sanitize the input
*/
$dto = AuthInput::new($this->sanitizer, $input);

/**
* Return the command back
*/
return new AuthLoginPostCommand($dto->email, $dto->password);
}

/**
* @param TAuthLogoutInput $input
*
* @return AuthLogoutPostCommand
*/
public function logout(array $input): AuthLogoutPostCommand
{
/**
* Sanitize the input
*/
$dto = AuthInput::new($this->sanitizer, $input);

/**
* Return the command back
*/
return new AuthLogoutPostCommand($dto->token);
}

/**
* @param TAuthRefreshInput $input
*
* @return AuthRefreshPostCommand
*/
public function refresh(array $input): AuthRefreshPostCommand
{
/**
* Sanitize the input
*/
$dto = AuthInput::new($this->sanitizer, $input);

/**
* Return the command back
*/
return new AuthRefreshPostCommand($dto->token);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Command;

use Phalcon\Api\Domain\ADR\InputTypes;

/**
* @phpstan-import-type TAuthLoginInput from InputTypes
* @phpstan-import-type TAuthLogoutInput from InputTypes
* @phpstan-import-type TAuthRefreshInput from InputTypes
*/
interface AuthCommandFactoryInterface
{
/**
* @param TAuthLoginInput $input
*
* @return AuthLoginPostCommand
*/
public function authenticate(array $input): AuthLoginPostCommand;

/**
* @param TAuthLogoutInput $input
*
* @return AuthLogoutPostCommand
*/
public function logout(array $input): AuthLogoutPostCommand;

/**
* @param TAuthRefreshInput $input
*
* @return AuthRefreshPostCommand
*/
public function refresh(array $input): AuthRefreshPostCommand;
}
29 changes: 29 additions & 0 deletions src/Domain/Application/Auth/Command/AuthLoginPostCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Command;

use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;

final readonly class AuthLoginPostCommand implements CommandInterface
{
/**
* @param string|null $email
* @param string|null $password
*/
public function __construct(
public ?string $email,
public ?string $password,
) {
}
}
27 changes: 27 additions & 0 deletions src/Domain/Application/Auth/Command/AuthLogoutPostCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Command;

use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;

final readonly class AuthLogoutPostCommand implements CommandInterface
{
/**
* @param string|null $token
*/
public function __construct(
public ?string $token
) {
}
}
27 changes: 27 additions & 0 deletions src/Domain/Application/Auth/Command/AuthRefreshPostCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Command;

use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;

final readonly class AuthRefreshPostCommand implements CommandInterface
{
/**
* @param string|null $token
*/
public function __construct(
public ?string $token
) {
}
}
72 changes: 72 additions & 0 deletions src/Domain/Application/Auth/Facade/AuthFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Facade;

use Phalcon\Api\Domain\ADR\InputTypes;
use Phalcon\Api\Domain\ADR\Payload;
use Phalcon\Api\Domain\Application\Auth\Command\AuthCommandFactoryInterface;
use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandBusInterface;

/**
* @phpstan-import-type TAuthLoginInput from InputTypes
* @phpstan-import-type TAuthLogoutInput from InputTypes
* @phpstan-import-type TAuthRefreshInput from InputTypes
*/
final readonly class AuthFacade
{
/**
* @param CommandBusInterface $bus
*/
public function __construct(
private CommandBusInterface $bus,
private AuthCommandFactoryInterface $factory
) {
}

/**
* Authenticates users (login)
*
* @param TAuthLoginInput $input
*
* @return Payload
*/
public function authenticate(array $input): Payload
{
return $this->bus->dispatch($this->factory->authenticate($input));
}

/**
* Logout: revoke refresh token after parsing/validation.
*
* @param TAuthLogoutInput $input
*
* @return Payload
*/
public function logout(array $input): Payload
{
return $this->bus->dispatch($this->factory->logout($input));
}

/**
* Refresh: validate refresh token, issue new tokens via TokenManager.
*
* @param TAuthLogoutInput $input
*
* @return Payload
*/
public function refresh(array $input): Payload
{
return $this->bus->dispatch($this->factory->refresh($input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This file is part of the Phalcon API.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Api\Domain\Application\Auth\Handler;

use Phalcon\Api\Domain\ADR\InputTypes;
use Phalcon\Api\Domain\Infrastructure\CommandBus\HandlerInterface;
use Phalcon\Api\Domain\Infrastructure\DataSource\Validation\ValidatorInterface;
use Phalcon\Api\Domain\Infrastructure\Encryption\TokenManagerInterface;

/**
* @phpstan-import-type TAuthLogoutInput from InputTypes
*/
abstract class AbstractAuthLogoutRefreshHandler implements HandlerInterface
{
/**
* @param TokenManagerInterface $tokenManager
* @param ValidatorInterface $validator
*/
public function __construct(
protected readonly TokenManagerInterface $tokenManager,
protected readonly ValidatorInterface $validator,
) {
}
}
Loading
Loading