Skip to content

Commit d0c2f61

Browse files
committed
feat: add parameters configuration file creation to ScriptHandler
1 parent 0c80945 commit d0c2f61

2 files changed

Lines changed: 23 additions & 27 deletions

File tree

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
"PhpList\\Core\\Composer\\ScriptHandler::createBundleConfiguration",
130130
"PhpList\\Core\\Composer\\ScriptHandler::createRoutesConfiguration",
131131
"PhpList\\Core\\Composer\\ScriptHandler::createDotenvConfiguration",
132-
"PhpList\\Core\\Composer\\ScriptHandler::createParametersConfiguration",
133132
"php bin/console cache:clear",
134133
"php bin/console cache:warmup"
135134
],

src/Composer/ScriptHandler.php

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ class ScriptHandler
3333
*/
3434
const ROUTES_CONFIGURATION_FILE = '/config/routing_modules.yml';
3535

36-
/**
37-
* @var string
38-
*/
39-
const PARAMETERS_CONFIGURATION_FILE = '/config/parameters.yml';
40-
4136
/**
4237
* @var string
4338
*/
@@ -46,17 +41,17 @@ class ScriptHandler
4641
/**
4742
* @var string
4843
*/
49-
const PARAMETERS_TEMPLATE_FILE = '/config/parameters.yml.dist';
44+
const DOTENV_FILE = '/.env';
5045

5146
/**
5247
* @var string
5348
*/
54-
const DOTENV_FILE = '/.env';
49+
const DOTENV_TEMPLATE_FILE = '/.env.dist';
5550

5651
/**
5752
* @var string
5853
*/
59-
const DOTENV_TEMPLATE_FILE = '/.env.dist';
54+
const PARAMETERS_CONFIGURATION_FILE = '/config/parameters.yml';
6055

6156
/**
6257
* @return string absolute application root directory without the trailing slash
@@ -275,43 +270,45 @@ public static function clearAllCaches():void
275270
}
276271

277272
/**
278-
* Creates config/parameters.yml (the parameters configuration file).
273+
* Creates the .env file (the environment variables consumed by the parameters configuration)
274+
* by copying it from .env.dist, generating a fresh app secret in the process.
279275
*
280276
* @return void
281277
*/
282-
public static function createParametersConfiguration(): void
278+
public static function createDotenvConfiguration(): void
283279
{
284-
$configurationFilePath = self::getApplicationRoot() . self::PARAMETERS_CONFIGURATION_FILE;
285-
if (file_exists($configurationFilePath)) {
280+
$appDotenvFilePath = self::getApplicationRoot() . self::DOTENV_FILE;
281+
$templateFilePath = __DIR__ . '/../..' . static::DOTENV_TEMPLATE_FILE;
282+
283+
if (file_exists($appDotenvFilePath)) {
286284
return;
287285
}
288286

289-
$templateFilePath = __DIR__ . '/../..' . static::PARAMETERS_TEMPLATE_FILE;
290-
$configuration = file_get_contents($templateFilePath);
287+
$template = file_get_contents($templateFilePath);
291288

292-
self::createAndWriteFile($configurationFilePath, $configuration);
289+
$secret = bin2hex(random_bytes(20));
290+
$configuration = sprintf($template, $secret);
291+
292+
self::createAndWriteFile($appDotenvFilePath, $configuration);
293293
}
294294

295+
295296
/**
296-
* Creates the .env file (the environment variables consumed by the parameters configuration)
297-
* by copying it from .env.dist, generating a fresh app secret in the process.
297+
* Creates config/parameters.yml (the parameters configuration file).
298298
*
299299
* @return void
300300
*/
301-
public static function createDotenvConfiguration(): void
301+
public static function createParametersConfiguration(): void
302302
{
303-
$dotenvFilePath = self::getApplicationRoot() . self::DOTENV_FILE;
304-
if (file_exists($dotenvFilePath)) {
303+
$configurationFilePath = self::getApplicationRoot() . self::PARAMETERS_CONFIGURATION_FILE;
304+
if (file_exists($configurationFilePath)) {
305305
return;
306306
}
307307

308-
$templateFilePath = __DIR__ . '/../..' . static::DOTENV_TEMPLATE_FILE;
309-
$template = file_get_contents($templateFilePath);
310-
311-
$secret = bin2hex(random_bytes(20));
312-
$configuration = sprintf($template, $secret);
308+
$templateFilePath = __DIR__ . '/../..' . static::PARAMETERS_CONFIGURATION_FILE;
309+
$configuration = file_get_contents($templateFilePath);
313310

314-
self::createAndWriteFile($dotenvFilePath, $configuration);
311+
self::createAndWriteFile($configurationFilePath, $configuration);
315312
}
316313

317314
/**

0 commit comments

Comments
 (0)