-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Removed base RozierApp class when possible, added LogTrail …
…service for publishing message in session and logger
- Loading branch information
1 parent
acb892a
commit 539806d
Showing
33 changed files
with
500 additions
and
893 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Security; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
|
||
final readonly class LogTrail | ||
{ | ||
public function __construct(private LoggerInterface $logger) | ||
{ | ||
} | ||
|
||
/** | ||
* Publish a confirmation message in Session flash bag and | ||
* logger interface. | ||
*/ | ||
public function publishConfirmMessage(Request $request, string $msg, ?object $source = null): void | ||
{ | ||
$this->publishMessage($request, $msg, 'confirm', $source); | ||
} | ||
|
||
/** | ||
* Publish an error message in Session flash bag and | ||
* logger interface. | ||
*/ | ||
public function publishErrorMessage(Request $request, string $msg, ?object $source = null): void | ||
{ | ||
$this->publishMessage($request, $msg, 'error', $source); | ||
} | ||
|
||
/** | ||
* Publish a message in Session flash bag and | ||
* logger interface. | ||
*/ | ||
protected function publishMessage( | ||
Request $request, | ||
string $msg, | ||
string $level = 'confirm', | ||
?object $source = null, | ||
): void { | ||
$session = $this->getSession($request); | ||
if ($session instanceof Session) { | ||
$session->getFlashBag()->add($level, $msg); | ||
} | ||
|
||
switch ($level) { | ||
case 'error': | ||
case 'danger': | ||
case 'fail': | ||
$this->logger->error($msg, ['entity' => $source]); | ||
break; | ||
default: | ||
$this->logger->info($msg, ['entity' => $source]); | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the current session. | ||
*/ | ||
public function getSession(?Request $request): ?SessionInterface | ||
{ | ||
return !$request?->hasPreviousSession() ? null : $request->getSession(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.