Update the user session management into discrete interfaces.
This commit is contained in:
parent
1003f2ddd3
commit
a3035c8900
24
app/composer.lock
generated
24
app/composer.lock
generated
@ -4169,16 +4169,16 @@
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v3.17.1",
|
||||
"version": "v3.18.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71"
|
||||
"reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71",
|
||||
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50",
|
||||
"reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -4233,7 +4233,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/twigphp/Twig/issues",
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.17.1"
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.18.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -4245,7 +4245,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-12-12T09:58:10+00:00"
|
||||
"time": "2024-12-29T10:51:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
@ -4510,16 +4510,16 @@
|
||||
},
|
||||
{
|
||||
"name": "nikic/php-parser",
|
||||
"version": "v5.3.1",
|
||||
"version": "v5.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nikic/PHP-Parser.git",
|
||||
"reference": "8eea230464783aa9671db8eea6f8c6ac5285794b"
|
||||
"reference": "447a020a1f875a434d62f2a401f53b82a396e494"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b",
|
||||
"reference": "8eea230464783aa9671db8eea6f8c6ac5285794b",
|
||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494",
|
||||
"reference": "447a020a1f875a434d62f2a401f53b82a396e494",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -4562,9 +4562,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
||||
"source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1"
|
||||
"source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0"
|
||||
},
|
||||
"time": "2024-10-08T18:51:32+00:00"
|
||||
"time": "2024-12-30T11:07:19+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
|
@ -42,6 +42,8 @@ use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||
use Slovocast\Infrastructure\Database\DatabaseHandler;
|
||||
use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface;
|
||||
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
||||
use Slovocast\Infrastructrue\Api\User\UserSessionManagerInterface;
|
||||
use Slovocast\Infrastructure\User\UserSessionManager;
|
||||
|
||||
|
||||
/**
|
||||
@ -139,6 +141,10 @@ class Bootstrap
|
||||
);
|
||||
},
|
||||
|
||||
UserSessionManagerInterface::class => function (ContainerInterface $container) {
|
||||
return new UserSessionManager($container->get(SessionInterface::class));
|
||||
},
|
||||
|
||||
/**
|
||||
* Application DI
|
||||
*/
|
||||
|
@ -7,6 +7,9 @@ use ReturnTypeWillChange;
|
||||
interface DatabaseHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Typically, this method would return the PDO object that represents the
|
||||
* active connection to a database.
|
||||
*
|
||||
* @return mixed The return must be an active connection to a database.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Infrastructure\Api\User;
|
||||
|
||||
use Slovocast\Domain\Entity\User;
|
||||
|
||||
interface UserSessionManagerInterface
|
||||
{
|
||||
public function setUserAuthenticatedState(User $user): void;
|
||||
public function clearUserAuthenticatedState(): void;
|
||||
}
|
@ -40,7 +40,9 @@ class DatabaseHandler implements DatabaseHandlerInterface
|
||||
|
||||
public function getConnectionString(): string
|
||||
{
|
||||
return "mysql:dbname={$this->database};host={$this->host};port={$this->port}";
|
||||
return "mysql:dbname={$this->database};"
|
||||
. "host={$this->host};"
|
||||
. "port={$this->port}";
|
||||
}
|
||||
|
||||
public function getHost(): string
|
||||
|
26
app/src/Infrastructure/User/UserSessionManager.php
Normal file
26
app/src/Infrastructure/User/UserSessionManager.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Infrastructure\User;
|
||||
|
||||
use Odan\Session\SessionInterface;
|
||||
use Slovocast\Domain\Entity\User;
|
||||
use Slovocast\Infrastructure\Api\User\UserSessionManagerInterface;
|
||||
|
||||
class UserSessionManager implements UserSessionManagerInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected SessionInterface $session
|
||||
) { }
|
||||
|
||||
public function setUserAuthenticatedState(User $user): void
|
||||
{
|
||||
$this->session->set('authenticated', true);
|
||||
$this->session->set('user', $user->toArray());
|
||||
}
|
||||
|
||||
public function clearUserAuthenticatedState(): void
|
||||
{
|
||||
$this->session->delete('authenticated');
|
||||
$this->session->delete('user');
|
||||
}
|
||||
}
|
@ -16,6 +16,9 @@ use Twig\Error\LoaderError;
|
||||
class Middlewares
|
||||
{
|
||||
/**
|
||||
* Set up all the application middleware. This is where the application
|
||||
* should determine the environment the code is running in as well.
|
||||
*
|
||||
* @param App $app The Slim application
|
||||
* @return void
|
||||
* @throws NotFoundExceptionInterface
|
||||
@ -43,8 +46,10 @@ class Middlewares
|
||||
]);
|
||||
|
||||
// Add the global variables
|
||||
$twig->getEnvironment()->addGlobal('site_name', $config->get('site.name'));
|
||||
$twig->getEnvironment()->addGlobal('site_description', $config->get('site.description'));
|
||||
$twig->getEnvironment()
|
||||
->addGlobal('site_name', $config->get('site.name'));
|
||||
$twig->getEnvironment()
|
||||
->addGlobal('site_description', $config->get('site.description'));
|
||||
|
||||
/** @var SessionInterface $session */
|
||||
$session = $container->get(SessionInterface::class);
|
||||
|
Loading…
Reference in New Issue
Block a user