Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-sa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
php-ver: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
composer-ver: [ '~2.7.0', '^2' ]
composer-ver: [ '~2.9.0', '^2' ]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

I did not see in the PR description anything referencing the Composer version. In the README we state version-3 is compatible with Composer 2.7+.

Tha means in theory we should test for [ '~2.7.0', '~2.8.0', '~2.9.0' ] as we have in the other workflow.

Is this PR somehow making Composer 2.9 the minimum supported version?


steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fail-fast: false
matrix:
php-ver: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
composer-ver: [ '~2.7.0', '~2.8.0', '~2.9.0' ]
composer-ver: [ '~2.9.0' ]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

I did not see in the PR description anything referencing the Composer version. Is now Composer 2.9 the minimium supported version?


steps:
- name: Update "USE_COVERAGE" env var based on matrix
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"composer/composer": "^2.8.10",
"composer/composer": "^2.9.0",
"symfony/process": "^5.4.47 || ^6 || ^7",
"wp-cli/wp-cli": "^2.12.0",
"inpsyde/php-coding-standards": "^2.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function run(Util\SelectedStepsFactory $factory): void
if ($factory->isListMode()) {
$factory->selectAndFactory($this->locator, $this->composer);

return; // @phpstan-ignore finally.exitPoint
return;
}

if ($config[Config\Config::SKIP_DB_CHECK]->is(false)) {
Expand Down Expand Up @@ -261,7 +261,7 @@ public function run(Util\SelectedStepsFactory $factory): void
} finally {
restore_error_handler();
if ($this->mode === self::MODE_COMMAND) {
exit($exit); // @phpstan-ignore finally.exitPoint
exit($exit);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/Env/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class Filters
public const FILTER_INT_OR_BOOL = 'int|bool';
public const FILTER_STRING_OR_BOOL = 'string|bool';
public const FILTER_STRING = 'string';
public const FILTER_RAW_STRING = 'raw-string';
public const FILTER_OCTAL_MOD = 'mod';
public const FILTER_TABLE_PREFIX = 'table-prefix';

Expand Down Expand Up @@ -90,6 +91,8 @@ private function applyFilter(string $mode, $value)
return $this->filterFloat($value);
case self::FILTER_STRING:
return $this->filterString($value);
case self::FILTER_RAW_STRING:
return $this->filterRawString($value);
case self::FILTER_INT_OR_BOOL:
return $this->filterIntOrBool($value);
case self::FILTER_STRING_OR_BOOL:
Expand Down Expand Up @@ -160,6 +163,19 @@ private function filterString($value): string
return htmlspecialchars(strip_tags((string) $value), ENT_QUOTES, 'UTF-8', false);
}

/**
* @param mixed $value
* @return string
*/
private function filterRawString($value): string
{
if (!is_scalar($value)) {
throw new \Exception('Invalid scalar.');
}

return addslashes((string) $value);
}

/**
* @param mixed $value
* @return bool|int
Expand Down
26 changes: 13 additions & 13 deletions src/Env/WordPressEnvBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class WordPressEnvBridge
'ALLOW_UNFILTERED_UPLOADS' => Filters::FILTER_BOOL,
'ALTERNATE_WP_CRON' => Filters::FILTER_BOOL,
'AUTH_COOKIE' => Filters::FILTER_STRING,
'AUTH_KEY' => Filters::FILTER_STRING,
'AUTH_SALT' => Filters::FILTER_STRING,
'AUTH_KEY' => Filters::FILTER_RAW_STRING,
'AUTH_SALT' => Filters::FILTER_RAW_STRING,
'AUTOMATIC_UPDATER_DISABLED' => Filters::FILTER_BOOL,
'AUTOSAVE_INTERVAL' => Filters::FILTER_INT,

Expand All @@ -50,7 +50,7 @@ class WordPressEnvBridge
'DB_COLLATE' => Filters::FILTER_STRING,
'DB_HOST' => Filters::FILTER_STRING,
'DB_NAME' => Filters::FILTER_STRING,
'DB_PASSWORD' => Filters::FILTER_STRING,
'DB_PASSWORD' => Filters::FILTER_RAW_STRING,
'DB_USER' => Filters::FILTER_STRING,
'DIEONDBERROR' => Filters::FILTER_BOOL,
'DISABLE_WP_CRON' => Filters::FILTER_BOOL,
Expand Down Expand Up @@ -80,7 +80,7 @@ class WordPressEnvBridge
'FTP_FORCE' => Filters::FILTER_BOOL,
'FTP_HOST' => Filters::FILTER_STRING,
'FTP_LANG_DIR' => Filters::FILTER_STRING,
'FTP_PASS' => Filters::FILTER_STRING,
'FTP_PASS' => Filters::FILTER_RAW_STRING,
'FTP_PLUGIN_DIR' => Filters::FILTER_STRING,
'FTP_PRIKEY' => Filters::FILTER_STRING,
'FTP_PUBKEY' => Filters::FILTER_STRING,
Expand All @@ -97,8 +97,8 @@ class WordPressEnvBridge

'LANGDIR' => Filters::FILTER_STRING,
'LOGGED_IN_COOKIE' => Filters::FILTER_STRING,
'LOGGED_IN_KEY' => Filters::FILTER_STRING,
'LOGGED_IN_SALT' => Filters::FILTER_STRING,
'LOGGED_IN_KEY' => Filters::FILTER_RAW_STRING,
'LOGGED_IN_SALT' => Filters::FILTER_RAW_STRING,

'MEDIA_TRASH' => Filters::FILTER_BOOL,
'MULTISITE' => Filters::FILTER_BOOL,
Expand All @@ -108,8 +108,8 @@ class WordPressEnvBridge
'MYSQL_NEW_LINK' => Filters::FILTER_BOOL,

'NOBLOGREDIRECT' => Filters::FILTER_STRING,
'NONCE_KEY' => Filters::FILTER_STRING,
'NONCE_SALT' => Filters::FILTER_STRING,
'NONCE_KEY' => Filters::FILTER_RAW_STRING,
'NONCE_SALT' => Filters::FILTER_RAW_STRING,
'NO_HEADER_TEXT' => Filters::FILTER_STRING,

'PASS_COOKIE' => Filters::FILTER_STRING,
Expand All @@ -129,11 +129,11 @@ class WordPressEnvBridge

'SAVEQUERIES' => Filters::FILTER_BOOL,
'SCRIPT_DEBUG' => Filters::FILTER_BOOL,
'SECRET_KEY' => Filters::FILTER_STRING,
'SECRET_SALT' => Filters::FILTER_STRING,
'SECRET_KEY' => Filters::FILTER_RAW_STRING,
'SECRET_SALT' => Filters::FILTER_RAW_STRING,
'SECURE_AUTH_COOKIE' => Filters::FILTER_STRING,
'SECURE_AUTH_KEY' => Filters::FILTER_STRING,
'SECURE_AUTH_SALT' => Filters::FILTER_STRING,
'SECURE_AUTH_KEY' => Filters::FILTER_RAW_STRING,
'SECURE_AUTH_SALT' => Filters::FILTER_RAW_STRING,
'SHORTINIT' => Filters::FILTER_BOOL,
'SITECOOKIEPATH' => Filters::FILTER_STRING,
'SITE_ID_CURRENT_SITE' => Filters::FILTER_INT,
Expand Down Expand Up @@ -177,7 +177,7 @@ class WordPressEnvBridge
'WP_POST_REVISIONS' => Filters::FILTER_INT_OR_BOOL,
'WP_PROXY_BYPASS_HOSTS' => Filters::FILTER_STRING,
'WP_PROXY_HOST' => Filters::FILTER_STRING,
'WP_PROXY_PASSWORD' => Filters::FILTER_STRING,
'WP_PROXY_PASSWORD' => Filters::FILTER_RAW_STRING,
'WP_PROXY_PORT' => Filters::FILTER_INT,
'WP_PROXY_USERNAME' => Filters::FILTER_STRING,
'WP_SITEURL' => Filters::FILTER_STRING,
Expand Down
6 changes: 3 additions & 3 deletions src/Io/Io.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function ask(Question $question): ?string
try {
$answer = null;
$count = 0;
while (!is_string($answer) || !$question->isValidAnswer($answer)) {
while ($answer === null) {
if ($count > 4) {
usleep(250000);
throw $tooMuchTriesException;
Expand All @@ -194,8 +194,8 @@ public function ask(Question $question): ?string
$this->writeComment('Invalid answer, try again.');
usleep(250000);
}
$answer = $this->io->ask($questionText, $question->defaultAnswerKey());
$answer = is_string($answer) ? strtolower(trim($answer)) : null;
$asked = $this->io->ask($questionText, $question->defaultAnswerKey());
$answer = is_string($asked) ? $question->filterAnswer($asked) : null;
$count++;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Io/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ public function __construct(array $lines, array $answers = [], ?string $default

/**
* @param string $answer
* @return bool
* @return string|null
*/
public function isValidAnswer(string $answer): bool
public function filterAnswer(string $answer): ?string
{
return array_key_exists(strtolower(trim($answer)), $this->answers);
$answer = trim($answer);
$answer = strtolower($answer);

return array_key_exists($answer, $this->answers) ? $answer : null;
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/Step/EnvExampleStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ public function name(): string
*/
public function allowed(Config $config, Paths $paths): bool
{
/** @var string $envFile */
$envFile = $config[Config::ENV_FILE]->unwrapOrFallback('.env');
/** @var string $envFileName */
$envFileName = $config[Config::ENV_FILE]->unwrapOrFallback('.env');
/** @var string $envDir */
$envDir = $config[Config::ENV_DIR]->unwrapOrFallback($paths->root());
$envFile = $this->filesystem->normalizePath("{$envDir}/{$envFileName}");

return $config[Config::ENV_EXAMPLE]->not(false) && !is_file($paths->root($envFile));
return $config[Config::ENV_EXAMPLE]->not(false) && !is_file($envFile);
}

/**
Expand All @@ -72,7 +75,10 @@ public function allowed(Config $config, Paths $paths): bool
*/
public function targetPath(Paths $paths): string
{
return $paths->root('.env.example');
/** @var string $envDir */
$envDir = $this->config[Config::ENV_DIR]->unwrap();

return $this->filesystem->normalizePath("{$envDir}/.env.example");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Step/MuLoaderStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function name(): string
*/
public function allowed(Config $config, Paths $paths): bool
{
$this->muPlugins = $this->list->pluginsList();
$this->muPlugins = $this->list->pluginsList($config);

return (bool) $this->muPlugins;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Util/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ public function removeRealDir(string $directory): bool
}
}

/**
* @param string $path
* @return string
*/
public function normalizePath(string $path): string
{
return $this->filesystem->normalizePath($path);
}

/**
* @param string $path
* @return bool
Expand Down
6 changes: 5 additions & 1 deletion src/Util/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ public function wpConfigSectionEditor(): WpConfigSectionEditor
public function muPluginsList(): MuPluginList
{
if (!isset($this->objects[__FUNCTION__])) {
$this->objects[__FUNCTION__] = new MuPluginList($this->packageFinder(), $this->paths());
$this->objects[__FUNCTION__] = new MuPluginList(
$this->packageFinder(),
$this->paths(),
$this->composerFilesystem()
);
}
/** @var MuPluginList */
return $this->objects[__FUNCTION__];
Expand Down
Loading
Loading