Skip to content

Commit 0e57640

Browse files
TatevikGrtatevikg1
andauthored
Refactor: env (#91)
* Refactor: env * fix test * app.api_base_url * Remove api_base_url from controller render methods and add it as a global variable in twig configuration * Remove api_token from controller render methods and update spa.html.twig to use app.session for auth_token * Update API base URL configuration in templates and JavaScript --------- Co-authored-by: Tatevik <tatevikg1@gmail.com>
1 parent 244be0d commit 0e57640

22 files changed

Lines changed: 36 additions & 47 deletions

assets/vue/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const redirectToLogin = () => {
3838

3939
const appElement = document.getElementById('vue-app');
4040
const apiToken = appElement?.dataset.apiToken;
41-
const apiBaseUrl = appElement?.dataset.apiBaseUrl;
41+
const apiElement = document.getElementById('api-config');
42+
const apiBaseUrl = apiElement?.dataset.apiBaseUrl;
4243

4344
if (!apiBaseUrl) {
4445
console.error('API Base URL is not configured.');

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"require": {
5353
"php": "^8.1",
54-
"phplist/core": "dev-main",
54+
"phplist/core": "dev-env",
5555
"symfony/twig-bundle": "^6.4",
5656
"symfony/webpack-encore-bundle": "^2.2",
5757
"symfony/security-bundle": "^6.4",
@@ -96,6 +96,7 @@
9696
"PhpList\\Core\\Composer\\ScriptHandler::createBundleConfiguration",
9797
"PhpList\\Core\\Composer\\ScriptHandler::createRoutesConfiguration",
9898
"PhpList\\Core\\Composer\\ScriptHandler::createParametersConfiguration",
99+
"PhpList\\Core\\Composer\\ScriptHandler::createDotenvConfiguration",
99100
"PhpList\\Core\\Composer\\ScriptHandler::clearAllCaches"
100101
],
101102
"publish-phplist-texts": [

config/packages/twig.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ twig:
33
strict_variables: '%kernel.debug%'
44
default_path: '%kernel.application_dir%/templates'
55
auto_reload: true
6+
globals:
7+
api_base_url: '%app.api_base_url%'

config/services.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
# config/services.yaml
2-
parameters:
3-
api_base_url: '%env(API_BASE_URL)%'
4-
env(API_BASE_URL): 'http://api.phplist.local/'
5-
62
services:
73
_defaults:
84
autowire: true
@@ -27,7 +23,7 @@ services:
2723
Symfony\Component\HttpFoundation\Session\SessionInterface: '@session'
2824

2925
PhpList\RestApiClient\Client:
30-
$baseUrl: '%api_base_url%'
26+
$baseUrl: '%app.api_base_url%'
3127

3228
PhpList\WebFrontend\EventListener\ApiSessionListener:
3329
tags:

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
66
backupGlobals="false"
77
colors="true"
8-
bootstrap="vendor/autoload.php"
8+
bootstrap="tests/bootstrap.php"
99
>
1010
<php>
11-
<env name="API_BASE_URL" value="http://api.phplist.local/"/>
1211
<ini name="error_reporting" value="-1"/>
1312
<server name="KERNEL_CLASS" value="PhpList\Core\Core\ApplicationKernel"/>
13+
<server name="APP_ENV" value="test" force="true"/>
1414
</php>
1515
</phpunit>

src/Controller/AnalyticsController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public function index(Request $request): Response
1717
{
1818
return $this->render('@PhpListFrontend/spa.html.twig', [
1919
'page' => 'Analytics',
20-
'api_token' => $request->getSession()->get('auth_token'),
21-
'api_base_url' => $this->getParameter('api_base_url'),
2220
]);
2321
}
2422
}

src/Controller/BouncesController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public function index(Request $request): Response
2323

2424
return $this->render('@PhpListFrontend/spa.html.twig', [
2525
'page' => 'Bounces',
26-
'api_token' => $request->getSession()->get('auth_token'),
27-
'api_base_url' => $this->getParameter('api_base_url'),
2826
'bounce_actions' => $bounceActions,
2927
]);
3028
}

src/Controller/CampaignsController.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public function index(Request $request): Response
1717
{
1818
return $this->render('@PhpListFrontend/spa.html.twig', [
1919
'page' => 'Campaigns',
20-
'api_token' => $request->getSession()->get('auth_token'),
21-
'api_base_url' => $this->getParameter('api_base_url'),
2220
]);
2321
}
2422

@@ -27,8 +25,6 @@ public function create(Request $request): Response
2725
{
2826
return $this->render('@PhpListFrontend/spa.html.twig', [
2927
'page' => 'Create Campaign',
30-
'api_token' => $request->getSession()->get('auth_token'),
31-
'api_base_url' => $this->getParameter('api_base_url'),
3228
]);
3329
}
3430

@@ -37,8 +33,6 @@ public function edit(Request $request, int $campaignId): Response
3733
{
3834
return $this->render('@PhpListFrontend/spa.html.twig', [
3935
'page' => sprintf('Edit Campaign #%d', $campaignId),
40-
'api_token' => $request->getSession()->get('auth_token'),
41-
'api_base_url' => $this->getParameter('api_base_url'),
4236
]);
4337
}
4438
}

src/Controller/DashboardController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public function index(Request $request): Response
3232

3333
return $this->render('@PhpListFrontend/spa.html.twig', [
3434
'page' => 'Dashboard',
35-
'api_token' => $request->getSession()->get('auth_token'),
36-
'api_base_url' => $this->getParameter('api_base_url'),
3735
'dashboard_stats' => $dashboardStats,
3836
'dashboard_error' => $dashboardError,
3937
]);

src/Controller/ListsController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public function index(Request $request): JsonResponse|Response
2626
if (! $wantsJson) {
2727
return $this->render('@PhpListFrontend/spa.html.twig', [
2828
'page' => 'Lists',
29-
'api_token' => $request->getSession()->get('auth_token'),
30-
'api_base_url' => $this->getParameter('api_base_url'),
3129
]);
3230
}
3331
$initialData = $this->listClient->getLists();
@@ -40,8 +38,6 @@ public function view(Request $request, int $listId): JsonResponse|Response
4038
{
4139
return $this->render('@PhpListFrontend/spa.html.twig', [
4240
'page' => 'List Subscribers',
43-
'api_token' => $request->getSession()->get('auth_token'),
44-
'api_base_url' => $this->getParameter('api_base_url'),
4541
]);
4642
}
4743
}

0 commit comments

Comments
 (0)