Skip to content

Commit

Permalink
Renamed JsonEncoder and Renderer folder [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Jan 18, 2024
1 parent abe4b17 commit 2e67e07
Show file tree
Hide file tree
Showing 48 changed files with 161 additions and 174 deletions.
2 changes: 1 addition & 1 deletion config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
$settings = $container->get('settings');
$rendererSettings = $settings['renderer'];

/** Global attributes are set in @see PhpViewExtensionMiddleware */
/** Global attributes are set in @see PhpRendererMiddleware */
return new PhpRenderer($rendererSettings['path']);
},

Expand Down
5 changes: 3 additions & 2 deletions config/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
$settings['root_dir'] = dirname(__DIR__, 1);

$settings['deployment'] = [
// Version `null` or string. If JsImportCacheBuster is enabled, `null` removes all query param versions from js imports
// Version string or null.
// If JsImportCacheBuster is enabled, `null` removes all query param versions from js imports
'version' => '0.4.0',
// When true, JsImportCacheBuster is enabled and goes through all js files and changes the version number from the imports
'update_js_imports_version' => true,
// Disable in prod
'assets_path' => $settings['root_dir'] . '/public/assets',
'asset_path' => $settings['root_dir'] . '/public/assets',
];

$settings['public'] = [
Expand Down
2 changes: 1 addition & 1 deletion config/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function html(?string $text = null): string
* @param mixed ...$context Optional elements that should be inserted in the string with placeholders.
* The function can be called like this:
* __('The %s contains %d monkeys and %d birds.', 'tree', 5, 3);
* With the argument unpacking operator ...$context, they are accessible within the function as an array.
* With the argument unpacking operator ...$context, the arguments are accessible within the function as an array.
*
* @return string The translated string.
*/
Expand Down
4 changes: 2 additions & 2 deletions config/middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use App\Application\Middleware\ForbiddenExceptionMiddleware;
use App\Application\Middleware\InvalidOperationExceptionMiddleware;
use App\Application\Middleware\NonFatalErrorHandlerMiddleware;
use App\Application\Middleware\PhpViewExtensionMiddleware;
use App\Application\Middleware\PhpRendererMiddleware;
use App\Application\Middleware\ValidationExceptionMiddleware;
use Odan\Session\Middleware\SessionStartMiddleware;
use Selective\BasePath\BasePathMiddleware;
Expand All @@ -21,7 +21,7 @@

// * Put everything possible before PhpViewExtensionMiddleware as if there is an error in a middleware,
// * the error page (and layout as well as everything else) needs this middleware loaded to work.
$app->add(PhpViewExtensionMiddleware::class);
$app->add(PhpRendererMiddleware::class);

// Retrieve and store ip address, user agent and user id (has to be BEFORE SessionStartMiddleware as it is using it
// but after PhpViewExtensionMiddleware as it needs the user id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Authentication\Ajax;

use App\Application\Responder\RedirectHandler;
use App\Application\Renderer\RedirectHandler;
use App\Domain\Authentication\Exception\InvalidTokenException;
use App\Domain\Authentication\Exception\UserAlreadyVerifiedException;
use App\Domain\Authentication\Service\AccountUnlockTokenVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Application\Action\Authentication\Ajax;

use App\Application\Responder\RedirectHandler;
use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\RedirectHandler;
use App\Application\Renderer\TemplateRenderer;
use App\Domain\Authentication\Exception\InvalidCredentialsException;
use App\Domain\Authentication\Exception\UnableToLoginStatusNotActiveException;
use App\Domain\Authentication\Service\LoginVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Application\Action\Authentication\Ajax;

use App\Application\Responder\RedirectHandler;
use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\RedirectHandler;
use App\Application\Renderer\TemplateRenderer;
use App\Domain\Authentication\Exception\InvalidTokenException;
use App\Domain\Authentication\Service\PasswordResetterWithToken;
use App\Domain\Validation\ValidationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Application\Action\Authentication\Ajax;

use App\Application\Responder\RedirectHandler;
use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\RedirectHandler;
use App\Application\Renderer\TemplateRenderer;
use App\Domain\Authentication\Service\PasswordRecoveryEmailSender;
use App\Domain\Exception\DomainRecordNotFoundException;
use App\Domain\Security\Exception\SecurityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Authentication\Ajax;

use App\Application\Responder\RedirectHandler;
use App\Application\Renderer\RedirectHandler;
use App\Domain\Authentication\Exception\InvalidTokenException;
use App\Domain\Authentication\Exception\UserAlreadyVerifiedException;
use App\Domain\Authentication\Service\RegisterTokenVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Application\Action\Authentication\Page;

use App\Application\Responder\RedirectHandler;
use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\RedirectHandler;
use App\Application\Renderer\TemplateRenderer;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Authentication\Page;

use App\Application\Responder\RedirectHandler;
use App\Application\Renderer\RedirectHandler;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Message\ResponseInterface as Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Authentication\Page;

use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\TemplateRenderer;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Log\LoggerInterface;
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Action/Client/Ajax/ApiClientCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Client\Ajax;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use App\Domain\Client\Service\ClientCreatorFromApi;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -13,7 +13,7 @@
final readonly class ApiClientCreateAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
private ClientCreatorFromApi $clientCreatorFromClientSubmit,
) {
}
Expand All @@ -37,10 +37,10 @@ public function __invoke(
$insertId = $this->clientCreatorFromClientSubmit->createClientFromClientSubmit($clientValues);

if (0 !== $insertId) {
return $this->jsonResponder->respondWithJson($response, ['status' => 'success', 'data' => null], 201);
return $this->jsonEncoder->encodeAndAddToResponse($response, ['status' => 'success', 'data' => null], 201);
}

$response = $this->jsonResponder->respondWithJson($response, [
$response = $this->jsonEncoder->encodeAndAddToResponse($response, [
'status' => 'warning',
'message' => 'Client not created',
]);
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Action/Client/Ajax/ClientCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace App\Application\Action\Client\Ajax;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use App\Domain\Client\Service\ClientCreator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class ClientCreateAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
private ClientCreator $clientCreator,
) {
}
Expand All @@ -35,9 +35,9 @@ public function __invoke(
$insertId = $this->clientCreator->createClient($clientValues);

if (0 !== $insertId) {
return $this->jsonResponder->respondWithJson($response, ['status' => 'success', 'data' => null], 201);
return $this->jsonEncoder->encodeAndAddToResponse($response, ['status' => 'success', 'data' => null], 201);
}
$response = $this->jsonResponder->respondWithJson($response, [
$response = $this->jsonEncoder->encodeAndAddToResponse($response, [
'status' => 'warning',
'message' => 'Client not created',
]);
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Action/Client/Ajax/ClientDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Client\Ajax;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use App\Domain\Client\Service\ClientDeleter;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -11,7 +11,7 @@
final readonly class ClientDeleteAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
private ClientDeleter $clientDeleter,
private SessionInterface $session,
) {
Expand Down Expand Up @@ -42,10 +42,10 @@ public function __invoke(
// Add flash here as user gets redirected to client list after deletion
$flash->add('success', __('Successfully deleted client.'));

return $this->jsonResponder->respondWithJson($response, ['status' => 'success', 'data' => null]);
return $this->jsonEncoder->encodeAndAddToResponse($response, ['status' => 'success', 'data' => null]);
}

$response = $this->jsonResponder->respondWithJson(
$response = $this->jsonEncoder->encodeAndAddToResponse(
$response,
['status' => 'warning', 'message' => 'Client not deleted.']
);
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Action/Client/Ajax/ClientFetchListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Client\Ajax;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use App\Domain\Client\Exception\InvalidClientFilterException;
use App\Domain\Client\Service\ClientFinderWithFilter;
use App\Test\Integration\Client\ClientListActionTest;
Expand All @@ -13,7 +13,7 @@
final readonly class ClientFetchListAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
private ClientFinderWithFilter $clientFilterFinder,
) {
}
Expand All @@ -36,9 +36,9 @@ public function __invoke(
// Retrieve clients with given filter values (or none)
$clientResultCollection = $this->clientFilterFinder->findClientsWithFilter($request->getQueryParams());

return $this->jsonResponder->respondWithJson($response, $clientResultCollection);
return $this->jsonEncoder->encodeAndAddToResponse($response, $clientResultCollection);
} catch (InvalidClientFilterException $invalidClientFilterException) {
return $this->jsonResponder->respondWithJson(
return $this->jsonEncoder->encodeAndAddToResponse(
$response,
/** @see ClientListActionTest::testClientListActionInvalidFilters() */
[
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Action/Client/Ajax/ClientUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace App\Application\Action\Client\Ajax;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use App\Domain\Client\Service\ClientUpdater;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class ClientUpdateAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
private ClientUpdater $clientUpdater,
) {
}
Expand All @@ -34,12 +34,12 @@ public function __invoke(
$updateData = $this->clientUpdater->updateClient($clientId, $clientValues);

if ($updateData['updated']) {
return $this->jsonResponder->respondWithJson(
return $this->jsonEncoder->encodeAndAddToResponse(
$response,
['status' => 'success', 'data' => $updateData['data']]
);
}
$response = $this->jsonResponder->respondWithJson($response, [
$response = $this->jsonEncoder->encodeAndAddToResponse($response, [
'status' => 'warning',
'message' => 'The client was not updated.',
'data' => $updateData['data'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Client\Ajax;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use App\Domain\Client\Exception\InvalidClientFilterException;
use App\Domain\Client\Service\ClientUtilFinder;
use Fig\Http\Message\StatusCodeInterface;
Expand All @@ -12,7 +12,7 @@
readonly class FetchDropdownOptionsForClientCreateAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
private ClientUtilFinder $clientUtilFinder,
) {
}
Expand All @@ -34,7 +34,7 @@ public function __invoke(
try {
$dropdownOptions = $this->clientUtilFinder->findClientDropdownValues();
} catch (InvalidClientFilterException $invalidClientFilterException) {
return $this->jsonResponder->respondWithJson(
return $this->jsonEncoder->encodeAndAddToResponse(
$response,
// Response format tested in PostFilterProvider.php
[
Expand All @@ -45,6 +45,6 @@ public function __invoke(
);
}

return $this->jsonResponder->respondWithJson($response, $dropdownOptions);
return $this->jsonEncoder->encodeAndAddToResponse($response, $dropdownOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Client\Page;

use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\TemplateRenderer;
use App\Domain\Authorization\Privilege;
use App\Domain\Client\Service\Authorization\ClientPermissionVerifier;
use App\Domain\Client\Service\ClientListFilter\ClientListFilterChipProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Client\Page;

use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\TemplateRenderer;
use App\Domain\Client\Service\ClientFinder;
use App\Domain\Client\Service\ClientUtilFinder;
use Psr\Http\Message\ResponseInterface;
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Action/Common/TranslateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace App\Application\Action\Common;

use App\Application\Responder\JsonResponder;
use App\Application\Renderer\JsonEncoder;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class TranslateAction
{
public function __construct(
private JsonResponder $jsonResponder,
private JsonEncoder $jsonEncoder,
) {
}

Expand All @@ -30,9 +30,9 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
$translatedStrings[$string] = __($string);
}

return $this->jsonResponder->respondWithJson($response, $translatedStrings);
return $this->jsonEncoder->encodeAndAddToResponse($response, $translatedStrings);
}

return $this->jsonResponder->respondWithJson($response, ['error' => 'Wrong request body format.'], 400);
return $this->jsonEncoder->encodeAndAddToResponse($response, ['error' => 'Wrong request body format.'], 400);
}
}
2 changes: 1 addition & 1 deletion src/Application/Action/Dashboard/DashboardPageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Application\Action\Dashboard;

use App\Application\Responder\TemplateRenderer;
use App\Application\Renderer\TemplateRenderer;
use App\Domain\Dashboard\DashboardPanelProvider;
use App\Domain\FilterSetting\FilterModule;
use App\Domain\FilterSetting\FilterSettingFinder;
Expand Down
Loading

0 comments on commit 2e67e07

Please sign in to comment.