Skip to content

Commit 27d34f2

Browse files
committed
HERDOC PHP 7.2 compat
1 parent 4139013 commit 27d34f2

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

components/Blueprints/Runner.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,20 @@
5252
use WordPress\Filesystem\LocalFilesystem;
5353
use WordPress\HttpClient\ByteStream\RequestReadStream;
5454
use WordPress\HttpClient\Client;
55-
use WordPress\HttpClient\Request;
5655
use WordPress\Zip\ZipFilesystem;
5756

5857
use function WordPress\Encoding\utf8_is_valid_byte_stream;
5958
use function WordPress\Filesystem\wp_unix_sys_get_temp_dir;
6059
use function WordPress\Zip\is_zip_file_stream;
6160

6261
class Runner {
62+
const EXECUTION_MODE_CREATE_NEW_SITE = 'create-new-site';
63+
const EXECUTION_MODE_APPLY_TO_EXISTING_SITE = 'apply-to-existing-site';
64+
const EXECUTION_MODES = [
65+
self::EXECUTION_MODE_CREATE_NEW_SITE,
66+
self::EXECUTION_MODE_APPLY_TO_EXISTING_SITE,
67+
];
68+
6369
/**
6470
* @var RunnerConfiguration
6571
*/
@@ -135,17 +141,17 @@ private function validateConfiguration( RunnerConfiguration $config ): void {
135141

136142
// Validate execution mode
137143
$mode = $config->getExecutionMode();
138-
if ( ! in_array( $mode, [ 'create-new-site', 'apply-to-existing-site' ], true ) ) {
139-
throw new BlueprintExecutionException( "Execution mode must be either 'create-new-site' or 'apply-to-existing-site'." );
144+
if ( ! in_array( $mode, self::EXECUTION_MODES, true ) ) {
145+
throw new BlueprintExecutionException( "Execution mode must be one of: " . implode( ', ', self::EXECUTION_MODES ) );
140146
}
141147

142148
// Validate site URL
143149
// Note: $options is not defined in this context, so we skip this block.
144150
// If you want to validate the site URL, you should use $config->getTargetSiteUrl().
145151
$siteUrl = $config->getTargetSiteUrl();
146-
if ( $mode === 'create-new-site' ) {
152+
if ( $mode === self::EXECUTION_MODE_CREATE_NEW_SITE ) {
147153
if ( empty( $siteUrl ) ) {
148-
throw new BlueprintExecutionException( "Site URL is required when the execution mode is 'create-new-site'." );
154+
throw new BlueprintExecutionException( sprintf( "Site URL is required when the execution mode is '%s'.", self::EXECUTION_MODE_CREATE_NEW_SITE ) );
149155
}
150156
}
151157
if ( ! empty( $siteUrl ) && ! filter_var( $siteUrl, FILTER_VALIDATE_URL ) ) {
@@ -253,7 +259,7 @@ public function run(): void {
253259
], $progress['wpCli'] );
254260

255261
$progress['targetResolution']->setCaption( 'Resolving target site' );
256-
if ( $this->configuration->getExecutionMode() === 'apply-to-existing-site' ) {
262+
if ( $this->configuration->getExecutionMode() === self::EXECUTION_MODE_APPLY_TO_EXISTING_SITE ) {
257263
ExistingSiteResolver::resolve( $this->runtime, $progress['targetResolution'], $this->wpVersionConstraint );
258264
} else {
259265
NewSiteResolver::resolve( $this->runtime, $progress['targetResolution'], $this->wpVersionConstraint, $this->recommendedWpVersion );

components/Blueprints/RunnerConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RunnerConfiguration {
2323
/**
2424
* @var string
2525
*/
26-
private $mode = 'create-new-site'; // or apply-to-existing-site
26+
private $mode = Runner::EXECUTION_MODE_CREATE_NEW_SITE;
2727
/**
2828
* @var string
2929
*/

components/Blueprints/SiteResolver/NewSiteResolver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ static public function resolve( Runtime $runtime, Tracker $progress, ?VersionCon
6767

6868
// If SQLite integration zip provided, unzip into appropriate folder
6969
if ( $runtime->getConfiguration()->getDatabaseEngine() === 'sqlite' ) {
70+
/*
71+
* @TODO: Ensure DB_NAME gets defined in wp-config.php before installing the SQLite plugin.
72+
*/
73+
7074
$progress['resolve_assets']->setCaption( 'Downloading SQLite integration plugin' );
7175
$resolved = $runtime->resolve( $assets['sqlite-integration'] );
7276
if ( ! $resolved instanceof File ) {
@@ -115,7 +119,7 @@ static public function resolve( Runtime $runtime, Tracker $progress, ?VersionCon
115119
$wp_cli_path,
116120
'core',
117121
'install',
118-
'--path=' . getenv('DOCROOT'),
122+
'--path=' . $runtime->getConfiguration()->getTargetSiteRoot(),
119123

120124
// For Docker compatibility. If we got this far, Blueprint runner was already
121125
// allowed to run as root.
@@ -149,7 +153,8 @@ static private function isWordPressInstalled( Runtime $runtime, Tracker $progres
149153
require $wp_load;
150154
151155
append_output( function_exists('is_blog_installed') && is_blog_installed() ? '1' : '0' );
152-
PHP,
156+
PHP
157+
,
153158
[
154159
'DOCROOT' => getenv('DOCROOT'),
155160
],

components/Blueprints/Steps/WPCLIStep.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function run( Runtime $runtime, Tracker $tracker ) {
4343
// For Docker compatibility. If we got this far, the Blueprint runner was already
4444
// allowed to run as root.
4545
'--allow-root',
46-
'--path=/wordpress', // . (getenv('DOCROOT') ?? '/wordpress'),
46+
'--path=' . $runtime->getConfiguration()->getTargetSiteRoot(),
4747
substr($command, 3),
4848
]);
4949
$process = $runtime->startShellCommand( $command );

components/Blueprints/bin/blueprint.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function createProgressReporter(): ProgressReporter {
256256
'site-url' => [ 'u', true, null, 'Public site URL (https://example.com)' ],
257257
'site-path' => [ null, true, null, 'Target directory with WordPress install context)' ],
258258
'execution-context' => [ 'x', true, null, 'Source directory with Blueprint context files' ],
259-
'mode' => [ 'm', true, 'create-new-site', 'Execution mode (create-new-site|apply-to-existing-site)' ],
259+
'mode' => [ 'm', true, Runner::EXECUTION_MODE_CREATE_NEW_SITE, sprintf( 'Execution mode (%s|%s)', Runner::EXECUTION_MODE_CREATE_NEW_SITE, Runner::EXECUTION_MODE_APPLY_TO_EXISTING_SITE ) ],
260260
'db-engine' => [ 'd', true, 'mysql', 'Database engine (mysql|sqlite)' ],
261261
'db-host' => [ null, true, '127.0.0.1', 'MySQL host' ],
262262
'db-user' => [ null, true, 'root', 'MySQL user' ],
@@ -280,7 +280,7 @@ function createProgressReporter(): ProgressReporter {
280280
] ),
281281
'examples' => [
282282
'php blueprint.php exec my-blueprint.json --site-url https://mysite.test --site-path /var/www/mysite.com',
283-
'php blueprint.php exec my-blueprint.json --execution-context /var/www --site-url https://mysite.test --mode apply-to-existing-site --site-path ./site',
283+
sprintf( 'php blueprint.php exec my-blueprint.json --execution-context /var/www --site-url https://mysite.test --mode %s --site-path ./site', Runner::EXECUTION_MODE_APPLY_TO_EXISTING_SITE ),
284284
'php blueprint.php exec my-blueprint.json --site-url https://mysite.test --site-path ./mysite --truncate-new-site-directory',
285285
],
286286
'aliases' => [ 'run' ],
@@ -350,7 +350,7 @@ function handleExecCommand( array $positionalArgs, array $options, array $comman
350350
$runner = new Runner( $config );
351351

352352
// Execute the Blueprint
353-
if ( $config->getExecutionMode() === 'create-new-site' ) {
353+
if ( $config->getExecutionMode() === Runner::EXECUTION_MODE_CREATE_NEW_SITE ) {
354354
$progressReporter->reportProgress(0, 'Creating a new site');
355355
} else {
356356
$progressReporter->reportProgress(0, 'Updating an existing site');
@@ -405,24 +405,23 @@ function cliArgsToRunnerConfiguration( array $positionalArgs, array $options ):
405405
}
406406

407407
if ( ! empty( $options['mode'] ) ) {
408-
// Accept 'create-new-site' or 'apply-to-existing-site' as CLI values, map to internal values
409408
$mode = $options['mode'];
410-
if ( $mode === 'create-new-site' ) {
411-
$config->setExecutionMode( 'create-new-site' );
412-
} elseif ( $mode === 'apply-to-existing-site' ) {
413-
$config->setExecutionMode( 'apply-to-existing-site' );
409+
if ( $mode === Runner::EXECUTION_MODE_CREATE_NEW_SITE ) {
410+
$config->setExecutionMode( Runner::EXECUTION_MODE_CREATE_NEW_SITE );
411+
} elseif ( $mode === Runner::EXECUTION_MODE_APPLY_TO_EXISTING_SITE ) {
412+
$config->setExecutionMode( Runner::EXECUTION_MODE_APPLY_TO_EXISTING_SITE );
414413
if(!empty($options['wp'])) {
415-
throw new InvalidArgumentException( "The --wp option cannot be used with --mode=apply-to-existing-site. The WordPress version is whatever the existing site has." );
414+
throw new InvalidArgumentException( sprintf( "The --wp option cannot be used with --mode=%s. The WordPress version is whatever the existing site has.", Runner::EXECUTION_MODE_APPLY_TO_EXISTING_SITE ) );
416415
}
417416
} else {
418-
throw new InvalidArgumentException( "Invalid execution mode: {$mode}. Supported modes are: create-new-site, apply-to-existing-site" );
417+
throw new InvalidArgumentException( sprintf( "Invalid execution mode: '{$mode}'. Supported modes are: %s", implode( ', ', Runner::EXECUTION_MODES ) ) );
419418
}
420419
}
421420

422421
$targetSiteRoot = $options['site-path'];
423422
if ( $options['truncate-new-site-directory'] ) {
424-
if ( $options['mode'] !== 'create-new-site' ) {
425-
throw new InvalidArgumentException( "--truncate-new-site-directory can only be used with --mode=create-new-site" );
423+
if ( $options['mode'] !== Runner::EXECUTION_MODE_CREATE_NEW_SITE ) {
424+
throw new InvalidArgumentException( sprintf( "--truncate-new-site-directory can only be used with --mode=%s", Runner::EXECUTION_MODE_CREATE_NEW_SITE ) );
426425
}
427426
$absoluteTargetSiteRoot = realpath( $targetSiteRoot );
428427
if ( false === $absoluteTargetSiteRoot) {

0 commit comments

Comments
 (0)