From 911d369fb72e00ba1ef6784501352521d6c5467a Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 26 Jul 2026 13:05:39 +0400 Subject: [PATCH 1/6] Refactor: env --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f46ae4e..38bab7a 100755 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ }, "require": { "php": "^8.1", - "phplist/core": "dev-main", + "phplist/core": "dev-env", "symfony/twig-bundle": "^6.4", "symfony/webpack-encore-bundle": "^2.2", "symfony/security-bundle": "^6.4", @@ -96,6 +96,7 @@ "PhpList\\Core\\Composer\\ScriptHandler::createBundleConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::createRoutesConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::createParametersConfiguration", + "PhpList\\Core\\Composer\\ScriptHandler::createDotenvConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::clearAllCaches" ], "publish-phplist-texts": [ From 6e3d9c07d45f0ad1f64f21089d04a8f63a10ade8 Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 26 Jul 2026 13:20:08 +0400 Subject: [PATCH 2/6] fix test --- config/services.yml | 3 +-- phpunit.xml.dist | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/config/services.yml b/config/services.yml index 76325ac..6ef2890 100755 --- a/config/services.yml +++ b/config/services.yml @@ -1,7 +1,6 @@ # config/services.yaml parameters: - api_base_url: '%env(API_BASE_URL)%' - env(API_BASE_URL): 'http://api.phplist.local/' + api_base_url: '%app.api_base_url%' services: _defaults: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4e0d445..692cf4d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,11 +5,11 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" backupGlobals="false" colors="true" - bootstrap="vendor/autoload.php" + bootstrap="tests/bootstrap.php" > - + From 3f390027d8af214f22c1448938bc88ae2bccfd76 Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 26 Jul 2026 13:23:36 +0400 Subject: [PATCH 3/6] app.api_base_url --- config/services.yml | 5 +---- src/Controller/AnalyticsController.php | 2 +- src/Controller/BouncesController.php | 2 +- src/Controller/CampaignsController.php | 6 +++--- src/Controller/DashboardController.php | 2 +- src/Controller/ListsController.php | 4 ++-- src/Controller/PublicPagesController.php | 6 +++--- src/Controller/SettingsController.php | 2 +- src/Controller/SubscribersController.php | 2 +- src/Controller/TemplatesController.php | 6 +++--- .../Controller/AnalyticsControllerTest.php | 2 +- .../Integration/Controller/BouncesControllerTest.php | 2 +- .../Controller/DashboardControllerTest.php | 2 +- tests/Integration/Controller/ListsControllerTest.php | 2 +- tests/bootstrap.php | 11 +++++++++++ 15 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 tests/bootstrap.php diff --git a/config/services.yml b/config/services.yml index 6ef2890..9be8e4c 100755 --- a/config/services.yml +++ b/config/services.yml @@ -1,7 +1,4 @@ # config/services.yaml -parameters: - api_base_url: '%app.api_base_url%' - services: _defaults: autowire: true @@ -26,7 +23,7 @@ services: Symfony\Component\HttpFoundation\Session\SessionInterface: '@session' PhpList\RestApiClient\Client: - $baseUrl: '%api_base_url%' + $baseUrl: '%app.api_base_url%' PhpList\WebFrontend\EventListener\ApiSessionListener: tags: diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index d8486ff..fe2f53d 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -18,7 +18,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Analytics', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/BouncesController.php b/src/Controller/BouncesController.php index 14fb3f2..126b54d 100644 --- a/src/Controller/BouncesController.php +++ b/src/Controller/BouncesController.php @@ -24,7 +24,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Bounces', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), 'bounce_actions' => $bounceActions, ]); } diff --git a/src/Controller/CampaignsController.php b/src/Controller/CampaignsController.php index dbf9d6a..40860cb 100644 --- a/src/Controller/CampaignsController.php +++ b/src/Controller/CampaignsController.php @@ -18,7 +18,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Campaigns', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -28,7 +28,7 @@ public function create(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Campaign', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -38,7 +38,7 @@ public function edit(Request $request, int $campaignId): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Campaign #%d', $campaignId), 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index aea6970..ea7c6b5 100755 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -33,7 +33,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Dashboard', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), 'dashboard_stats' => $dashboardStats, 'dashboard_error' => $dashboardError, ]); diff --git a/src/Controller/ListsController.php b/src/Controller/ListsController.php index 94e63f7..cd30857 100644 --- a/src/Controller/ListsController.php +++ b/src/Controller/ListsController.php @@ -27,7 +27,7 @@ public function index(Request $request): JsonResponse|Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Lists', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } $initialData = $this->listClient->getLists(); @@ -41,7 +41,7 @@ public function view(Request $request, int $listId): JsonResponse|Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'List Subscribers', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/PublicPagesController.php b/src/Controller/PublicPagesController.php index 1a6d80c..d1f5179 100644 --- a/src/Controller/PublicPagesController.php +++ b/src/Controller/PublicPagesController.php @@ -18,7 +18,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Subscribe Pages', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -28,7 +28,7 @@ public function create(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Subscribe Page', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -38,7 +38,7 @@ public function edit(Request $request, int $pageId): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Subscribe Page #%d', $pageId), 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/SettingsController.php b/src/Controller/SettingsController.php index 02d8684..a366697 100644 --- a/src/Controller/SettingsController.php +++ b/src/Controller/SettingsController.php @@ -18,7 +18,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Settings', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/SubscribersController.php b/src/Controller/SubscribersController.php index 8d542ed..087ff86 100644 --- a/src/Controller/SubscribersController.php +++ b/src/Controller/SubscribersController.php @@ -38,7 +38,7 @@ public function index(Request $request): JsonResponse|Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Subscribers', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } diff --git a/src/Controller/TemplatesController.php b/src/Controller/TemplatesController.php index 5d0cb29..704df64 100644 --- a/src/Controller/TemplatesController.php +++ b/src/Controller/TemplatesController.php @@ -18,7 +18,7 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Templates', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -28,7 +28,7 @@ public function create(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Template', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -38,7 +38,7 @@ public function edit(Request $request, int $templateId): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Template #%d', $templateId), 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('api_base_url'), + 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/tests/Integration/Controller/AnalyticsControllerTest.php b/tests/Integration/Controller/AnalyticsControllerTest.php index 5691010..9f274ab 100644 --- a/tests/Integration/Controller/AnalyticsControllerTest.php +++ b/tests/Integration/Controller/AnalyticsControllerTest.php @@ -27,7 +27,7 @@ public function testAnalyticsPageRendersExpectedSpaPayload(): void self::bootKernel(); /** @var AnalyticsController $controller */ $controller = static::getContainer()->get(AnalyticsController::class); - $apiBaseUrl = (string) static::getContainer()->getParameter('api_base_url'); + $apiBaseUrl = (string) static::getContainer()->getParameter('app.api_base_url'); $request = Request::create('/analytics/'); $session = new Session(new MockArraySessionStorage()); diff --git a/tests/Integration/Controller/BouncesControllerTest.php b/tests/Integration/Controller/BouncesControllerTest.php index d832cc0..95e3380 100644 --- a/tests/Integration/Controller/BouncesControllerTest.php +++ b/tests/Integration/Controller/BouncesControllerTest.php @@ -27,7 +27,7 @@ public function testBouncesPageRendersExpectedSpaPayload(): void self::bootKernel(); /** @var BouncesController $controller */ $controller = static::getContainer()->get(BouncesController::class); - $apiBaseUrl = (string) static::getContainer()->getParameter('api_base_url'); + $apiBaseUrl = (string) static::getContainer()->getParameter('app.api_base_url'); $request = Request::create('/bounces/'); $session = new Session(new MockArraySessionStorage()); diff --git a/tests/Integration/Controller/DashboardControllerTest.php b/tests/Integration/Controller/DashboardControllerTest.php index a24a786..41fede8 100644 --- a/tests/Integration/Controller/DashboardControllerTest.php +++ b/tests/Integration/Controller/DashboardControllerTest.php @@ -29,7 +29,7 @@ public function testDashboardRouteIsRegistered(): void public function testDashboardRendersSpaPayloadWithStats(): void { self::bootKernel(); - $apiBaseUrl = (string) static::getContainer()->getParameter('api_base_url'); + $apiBaseUrl = (string) static::getContainer()->getParameter('app.api_base_url'); $statsClient = $this->createMock(StatisticsClient::class); $statsClient->expects(self::once()) diff --git a/tests/Integration/Controller/ListsControllerTest.php b/tests/Integration/Controller/ListsControllerTest.php index 801453c..3773eb8 100644 --- a/tests/Integration/Controller/ListsControllerTest.php +++ b/tests/Integration/Controller/ListsControllerTest.php @@ -31,7 +31,7 @@ public function testListRoutesAreRegistered(string $routeName, array $parameters public function testListsIndexRendersSpaForHtmlRequests(): void { self::bootKernel(); - $apiBaseUrl = (string) static::getContainer()->getParameter('api_base_url'); + $apiBaseUrl = (string) static::getContainer()->getParameter('app.api_base_url'); $listClient = $this->createMock(ListClient::class); $listClient->expects(self::never())->method('getLists'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..8a148f7 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,11 @@ +bootEnv(dirname(__DIR__) . '/.env'); +} From 87ac52445bc844226100ae44d65ac3d520664043 Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 26 Jul 2026 13:38:29 +0400 Subject: [PATCH 4/6] Remove api_base_url from controller render methods and add it as a global variable in twig configuration --- config/packages/twig.yaml | 2 ++ src/Controller/AnalyticsController.php | 1 - src/Controller/BouncesController.php | 1 - src/Controller/CampaignsController.php | 3 --- src/Controller/DashboardController.php | 1 - src/Controller/ListsController.php | 2 -- src/Controller/PublicPagesController.php | 3 --- src/Controller/SettingsController.php | 1 - src/Controller/SubscribersController.php | 1 - src/Controller/TemplatesController.php | 3 --- 10 files changed, 2 insertions(+), 16 deletions(-) diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 0e4fd73..070f0e2 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -3,3 +3,5 @@ twig: strict_variables: '%kernel.debug%' default_path: '%kernel.application_dir%/templates' auto_reload: true + globals: + api_base_url: '%app.api_base_url%' diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index fe2f53d..0c066e8 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -18,7 +18,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Analytics', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/BouncesController.php b/src/Controller/BouncesController.php index 126b54d..3a731c1 100644 --- a/src/Controller/BouncesController.php +++ b/src/Controller/BouncesController.php @@ -24,7 +24,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Bounces', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), 'bounce_actions' => $bounceActions, ]); } diff --git a/src/Controller/CampaignsController.php b/src/Controller/CampaignsController.php index 40860cb..2425837 100644 --- a/src/Controller/CampaignsController.php +++ b/src/Controller/CampaignsController.php @@ -18,7 +18,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Campaigns', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -28,7 +27,6 @@ public function create(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Campaign', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -38,7 +36,6 @@ public function edit(Request $request, int $campaignId): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Campaign #%d', $campaignId), 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index ea7c6b5..21afa69 100755 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -33,7 +33,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Dashboard', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), 'dashboard_stats' => $dashboardStats, 'dashboard_error' => $dashboardError, ]); diff --git a/src/Controller/ListsController.php b/src/Controller/ListsController.php index cd30857..a5eb555 100644 --- a/src/Controller/ListsController.php +++ b/src/Controller/ListsController.php @@ -27,7 +27,6 @@ public function index(Request $request): JsonResponse|Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Lists', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } $initialData = $this->listClient->getLists(); @@ -41,7 +40,6 @@ public function view(Request $request, int $listId): JsonResponse|Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'List Subscribers', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/PublicPagesController.php b/src/Controller/PublicPagesController.php index d1f5179..f6d160c 100644 --- a/src/Controller/PublicPagesController.php +++ b/src/Controller/PublicPagesController.php @@ -18,7 +18,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Subscribe Pages', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -28,7 +27,6 @@ public function create(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Subscribe Page', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -38,7 +36,6 @@ public function edit(Request $request, int $pageId): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Subscribe Page #%d', $pageId), 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/SettingsController.php b/src/Controller/SettingsController.php index a366697..3dba8ee 100644 --- a/src/Controller/SettingsController.php +++ b/src/Controller/SettingsController.php @@ -18,7 +18,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Settings', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } diff --git a/src/Controller/SubscribersController.php b/src/Controller/SubscribersController.php index 087ff86..55ddc7d 100644 --- a/src/Controller/SubscribersController.php +++ b/src/Controller/SubscribersController.php @@ -38,7 +38,6 @@ public function index(Request $request): JsonResponse|Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Subscribers', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } diff --git a/src/Controller/TemplatesController.php b/src/Controller/TemplatesController.php index 704df64..bff8fb7 100644 --- a/src/Controller/TemplatesController.php +++ b/src/Controller/TemplatesController.php @@ -18,7 +18,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Templates', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -28,7 +27,6 @@ public function create(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Template', 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } @@ -38,7 +36,6 @@ public function edit(Request $request, int $templateId): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Template #%d', $templateId), 'api_token' => $request->getSession()->get('auth_token'), - 'api_base_url' => $this->getParameter('app.api_base_url'), ]); } } From 202526784b794506079d5eab648073fa539fdedb Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 26 Jul 2026 13:48:57 +0400 Subject: [PATCH 5/6] Remove api_token from controller render methods and update spa.html.twig to use app.session for auth_token --- src/Controller/AnalyticsController.php | 1 - src/Controller/BouncesController.php | 1 - src/Controller/CampaignsController.php | 3 --- src/Controller/DashboardController.php | 1 - src/Controller/ListsController.php | 2 -- src/Controller/PublicPagesController.php | 3 --- src/Controller/SettingsController.php | 1 - src/Controller/SubscribersController.php | 1 - src/Controller/TemplatesController.php | 3 --- templates/spa.html.twig | 2 +- tests/Integration/Controller/AnalyticsControllerTest.php | 2 ++ tests/Integration/Controller/BouncesControllerTest.php | 2 ++ tests/Integration/Controller/CampaignsControllerTest.php | 2 ++ tests/Integration/Controller/DashboardControllerTest.php | 2 ++ tests/Integration/Controller/ListsControllerTest.php | 2 ++ 15 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index 0c066e8..407f256 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -17,7 +17,6 @@ public function index(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Analytics', - 'api_token' => $request->getSession()->get('auth_token'), ]); } } diff --git a/src/Controller/BouncesController.php b/src/Controller/BouncesController.php index 3a731c1..126db67 100644 --- a/src/Controller/BouncesController.php +++ b/src/Controller/BouncesController.php @@ -23,7 +23,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Bounces', - 'api_token' => $request->getSession()->get('auth_token'), 'bounce_actions' => $bounceActions, ]); } diff --git a/src/Controller/CampaignsController.php b/src/Controller/CampaignsController.php index 2425837..7d21668 100644 --- a/src/Controller/CampaignsController.php +++ b/src/Controller/CampaignsController.php @@ -17,7 +17,6 @@ public function index(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Campaigns', - 'api_token' => $request->getSession()->get('auth_token'), ]); } @@ -26,7 +25,6 @@ public function create(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Campaign', - 'api_token' => $request->getSession()->get('auth_token'), ]); } @@ -35,7 +33,6 @@ public function edit(Request $request, int $campaignId): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Campaign #%d', $campaignId), - 'api_token' => $request->getSession()->get('auth_token'), ]); } } diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index 21afa69..edfb1ef 100755 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -32,7 +32,6 @@ public function index(Request $request): Response return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Dashboard', - 'api_token' => $request->getSession()->get('auth_token'), 'dashboard_stats' => $dashboardStats, 'dashboard_error' => $dashboardError, ]); diff --git a/src/Controller/ListsController.php b/src/Controller/ListsController.php index a5eb555..3dfb1ba 100644 --- a/src/Controller/ListsController.php +++ b/src/Controller/ListsController.php @@ -26,7 +26,6 @@ public function index(Request $request): JsonResponse|Response if (! $wantsJson) { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Lists', - 'api_token' => $request->getSession()->get('auth_token'), ]); } $initialData = $this->listClient->getLists(); @@ -39,7 +38,6 @@ public function view(Request $request, int $listId): JsonResponse|Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'List Subscribers', - 'api_token' => $request->getSession()->get('auth_token'), ]); } } diff --git a/src/Controller/PublicPagesController.php b/src/Controller/PublicPagesController.php index f6d160c..06064d9 100644 --- a/src/Controller/PublicPagesController.php +++ b/src/Controller/PublicPagesController.php @@ -17,7 +17,6 @@ public function index(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Subscribe Pages', - 'api_token' => $request->getSession()->get('auth_token'), ]); } @@ -26,7 +25,6 @@ public function create(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Subscribe Page', - 'api_token' => $request->getSession()->get('auth_token'), ]); } @@ -35,7 +33,6 @@ public function edit(Request $request, int $pageId): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Subscribe Page #%d', $pageId), - 'api_token' => $request->getSession()->get('auth_token'), ]); } } diff --git a/src/Controller/SettingsController.php b/src/Controller/SettingsController.php index 3dba8ee..a41bfc1 100644 --- a/src/Controller/SettingsController.php +++ b/src/Controller/SettingsController.php @@ -17,7 +17,6 @@ public function index(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Settings', - 'api_token' => $request->getSession()->get('auth_token'), ]); } } diff --git a/src/Controller/SubscribersController.php b/src/Controller/SubscribersController.php index 55ddc7d..331da62 100644 --- a/src/Controller/SubscribersController.php +++ b/src/Controller/SubscribersController.php @@ -37,7 +37,6 @@ public function index(Request $request): JsonResponse|Response if (! $wantsJson) { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Subscribers', - 'api_token' => $request->getSession()->get('auth_token'), ]); } diff --git a/src/Controller/TemplatesController.php b/src/Controller/TemplatesController.php index bff8fb7..c9a1650 100644 --- a/src/Controller/TemplatesController.php +++ b/src/Controller/TemplatesController.php @@ -17,7 +17,6 @@ public function index(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Templates', - 'api_token' => $request->getSession()->get('auth_token'), ]); } @@ -26,7 +25,6 @@ public function create(Request $request): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => 'Create Template', - 'api_token' => $request->getSession()->get('auth_token'), ]); } @@ -35,7 +33,6 @@ public function edit(Request $request, int $templateId): Response { return $this->render('@PhpListFrontend/spa.html.twig', [ 'page' => sprintf('Edit Template #%d', $templateId), - 'api_token' => $request->getSession()->get('auth_token'), ]); } } diff --git a/templates/spa.html.twig b/templates/spa.html.twig index a0fda5a..cb1ef32 100644 --- a/templates/spa.html.twig +++ b/templates/spa.html.twig @@ -4,7 +4,7 @@ {% block body %}
set('auth_token', 'integration-token'); $request->setSession($session); + static::getContainer()->get(RequestStack::class)->push($request); $response = $controller->index($request); $content = (string) $response->getContent(); diff --git a/tests/Integration/Controller/BouncesControllerTest.php b/tests/Integration/Controller/BouncesControllerTest.php index 95e3380..05d4eb7 100644 --- a/tests/Integration/Controller/BouncesControllerTest.php +++ b/tests/Integration/Controller/BouncesControllerTest.php @@ -7,6 +7,7 @@ use PhpList\WebFrontend\Controller\BouncesController; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\RouterInterface; @@ -33,6 +34,7 @@ public function testBouncesPageRendersExpectedSpaPayload(): void $session = new Session(new MockArraySessionStorage()); $session->set('auth_token', 'integration-token'); $request->setSession($session); + static::getContainer()->get(RequestStack::class)->push($request); $response = $controller->index($request); $content = (string) $response->getContent(); diff --git a/tests/Integration/Controller/CampaignsControllerTest.php b/tests/Integration/Controller/CampaignsControllerTest.php index d05fa00..8a66684 100644 --- a/tests/Integration/Controller/CampaignsControllerTest.php +++ b/tests/Integration/Controller/CampaignsControllerTest.php @@ -7,6 +7,7 @@ use PhpList\WebFrontend\Controller\CampaignsController; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\RouterInterface; @@ -41,6 +42,7 @@ public function testCampaignPagesRenderExpectedSpaPayload( $session = new Session(new MockArraySessionStorage()); $session->set('auth_token', 'integration-token'); $request->setSession($session); + static::getContainer()->get(RequestStack::class)->push($request); $response = $controller->{$action}($request, ...$actionArguments); diff --git a/tests/Integration/Controller/DashboardControllerTest.php b/tests/Integration/Controller/DashboardControllerTest.php index 41fede8..872ef5a 100644 --- a/tests/Integration/Controller/DashboardControllerTest.php +++ b/tests/Integration/Controller/DashboardControllerTest.php @@ -11,6 +11,7 @@ use PhpList\WebFrontend\Controller\DashboardController; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\RouterInterface; @@ -43,6 +44,7 @@ public function testDashboardRendersSpaPayloadWithStats(): void $session = new Session(new MockArraySessionStorage()); $session->set('auth_token', 'integration-token'); $request->setSession($session); + static::getContainer()->get(RequestStack::class)->push($request); $response = $controller->index($request); $content = (string) $response->getContent(); diff --git a/tests/Integration/Controller/ListsControllerTest.php b/tests/Integration/Controller/ListsControllerTest.php index 3773eb8..72d997a 100644 --- a/tests/Integration/Controller/ListsControllerTest.php +++ b/tests/Integration/Controller/ListsControllerTest.php @@ -10,6 +10,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\RouterInterface; @@ -106,6 +107,7 @@ private function createRequestWithSession(string $path): Request $session = new Session(new MockArraySessionStorage()); $session->set('auth_token', 'integration-token'); $request->setSession($session); + static::getContainer()->get(RequestStack::class)->push($request); return $request; } From fb171038bc306990228812d10013549ab4d223ba Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 26 Jul 2026 14:14:21 +0400 Subject: [PATCH 6/6] Update API base URL configuration in templates and JavaScript --- assets/vue/api.js | 3 ++- templates/base.html.twig | 1 + templates/spa.html.twig | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/vue/api.js b/assets/vue/api.js index be71e85..3ac00be 100644 --- a/assets/vue/api.js +++ b/assets/vue/api.js @@ -38,7 +38,8 @@ const redirectToLogin = () => { const appElement = document.getElementById('vue-app'); const apiToken = appElement?.dataset.apiToken; -const apiBaseUrl = appElement?.dataset.apiBaseUrl; +const apiElement = document.getElementById('api-config'); +const apiBaseUrl = apiElement?.dataset.apiBaseUrl; if (!apiBaseUrl) { console.error('API Base URL is not configured.'); diff --git a/templates/base.html.twig b/templates/base.html.twig index 7274070..43f3a68 100755 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -4,6 +4,7 @@ {% block title %}phpList{% endblock %} + diff --git a/templates/spa.html.twig b/templates/spa.html.twig index cb1ef32..244a6d1 100644 --- a/templates/spa.html.twig +++ b/templates/spa.html.twig @@ -5,7 +5,6 @@ {% block body %}