Skip to content

Commit 7168319

Browse files
authored
Merge pull request #183 from wp-cli/fix/add-composer-compat-for-2-3
2 parents f295538 + 8e8d112 commit 7168319

File tree

8 files changed

+193
-78
lines changed

8 files changed

+193
-78
lines changed

composer.json

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
{
2-
"name": "wp-cli/package-command",
3-
"type": "wp-cli-package",
4-
"description": "Lists, installs, and removes WP-CLI packages.",
5-
"homepage": "https://github.com/wp-cli/package-command",
6-
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Daniel Bachhuber",
10-
"email": "[email protected]",
11-
"homepage": "https://runcommand.io"
12-
}
13-
],
14-
"require": {
15-
"ext-json": "*",
16-
"composer/composer": "^1.10.23 || ~2.2.17",
17-
"wp-cli/wp-cli": "^2.8"
18-
},
19-
"require-dev": {
20-
"wp-cli/scaffold-command": "^1 || ^2",
21-
"wp-cli/wp-cli-tests": "^4"
22-
},
23-
"config": {
24-
"process-timeout": 7200,
25-
"sort-packages": true,
26-
"allow-plugins": {
27-
"dealerdirect/phpcodesniffer-composer-installer": true,
28-
"johnpbloch/wordpress-core-installer": true
29-
}
30-
},
31-
"extra": {
32-
"branch-alias": {
33-
"dev-main": "2.x-dev"
34-
},
35-
"bundled": true,
36-
"commands": [
37-
"package",
38-
"package browse",
39-
"package install",
40-
"package list",
41-
"package update",
42-
"package uninstall"
43-
]
44-
},
45-
"autoload": {
46-
"classmap": [
47-
"src/"
48-
],
49-
"files": [
50-
"package-command.php"
51-
]
52-
},
53-
"minimum-stability": "dev",
54-
"prefer-stable": true,
55-
"scripts": {
56-
"behat": "run-behat-tests",
57-
"behat-rerun": "rerun-behat-tests",
58-
"lint": "run-linter-tests",
59-
"phpcs": "run-phpcs-tests",
60-
"phpcbf": "run-phpcbf-cleanup",
61-
"phpunit": "run-php-unit-tests",
62-
"prepare-tests": "install-package-tests",
63-
"test": [
64-
"@lint",
65-
"@phpcs",
66-
"@phpunit",
67-
"@behat"
68-
]
69-
},
70-
"support": {
71-
"issues": "https://github.com/wp-cli/package-command/issues"
2+
"name": "wp-cli/package-command",
3+
"type": "wp-cli-package",
4+
"description": "Lists, installs, and removes WP-CLI packages.",
5+
"homepage": "https://github.com/wp-cli/package-command",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Daniel Bachhuber",
10+
"email": "[email protected]",
11+
"homepage": "https://runcommand.io"
12+
}
13+
],
14+
"require": {
15+
"ext-json": "*",
16+
"composer/composer": "^1.10.23 || ^2.2.17",
17+
"wp-cli/wp-cli": "^2.8"
18+
},
19+
"require-dev": {
20+
"wp-cli/scaffold-command": "^1 || ^2",
21+
"wp-cli/wp-cli-tests": "^4"
22+
},
23+
"config": {
24+
"process-timeout": 7200,
25+
"sort-packages": true,
26+
"allow-plugins": {
27+
"dealerdirect/phpcodesniffer-composer-installer": true,
28+
"johnpbloch/wordpress-core-installer": true
7229
}
30+
},
31+
"extra": {
32+
"branch-alias": {
33+
"dev-main": "2.x-dev"
34+
},
35+
"bundled": true,
36+
"commands": [
37+
"package",
38+
"package browse",
39+
"package install",
40+
"package list",
41+
"package update",
42+
"package uninstall"
43+
]
44+
},
45+
"autoload": {
46+
"classmap": [
47+
"src/"
48+
],
49+
"files": [
50+
"package-command.php"
51+
]
52+
},
53+
"minimum-stability": "dev",
54+
"prefer-stable": true,
55+
"scripts": {
56+
"behat": "run-behat-tests",
57+
"behat-rerun": "rerun-behat-tests",
58+
"lint": "run-linter-tests",
59+
"phpcs": "run-phpcs-tests",
60+
"phpcbf": "run-phpcbf-cleanup",
61+
"phpunit": "run-php-unit-tests",
62+
"prepare-tests": "install-package-tests",
63+
"test": [
64+
"@lint",
65+
"@phpcs",
66+
"@phpunit",
67+
"@behat"
68+
]
69+
},
70+
"support": {
71+
"issues": "https://github.com/wp-cli/package-command/issues"
72+
}
7373
}

features/package-install.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Feature: Install WP-CLI packages
145145
When I run `wp package install git@github.com:wp-cli/google-sitemap-generator-cli.git`
146146
Then STDOUT should contain:
147147
"""
148-
Installing package wp-cli/google-sitemap-generator-cli (dev-master)
148+
Installing package wp-cli/google-sitemap-generator-cli (dev-main)
149149
"""
150150
# This path is sometimes changed on Macs to prefix with /private
151151
And STDOUT should contain:

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<!-- Ignoring select files/folders.
1717
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders -->
1818
<exclude-pattern>*/src/WP_CLI/JsonManipulator\.php$</exclude-pattern>
19+
<exclude-pattern>*/src/WP_CLI/Package/Compat/Min_Composer_1_10/NullIOMethodsTrait\.php$</exclude-pattern>
20+
<exclude-pattern>*/src/WP_CLI/Package/Compat/Min_Composer_2_3/NullIOMethodsTrait\.php$</exclude-pattern>
1921
<exclude-pattern>*/tests/test-json-manipulator\.php$</exclude-pattern>
2022

2123
<!-- Show progress. -->

src/Package_Command.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44
use Composer\Config;
55
use Composer\Config\JsonConfigSource;
66
use Composer\DependencyResolver\Pool;
7-
use Composer\DependencyResolver\Request;
8-
use Composer\EventDispatcher\Event;
97
use Composer\Factory;
108
use Composer\IO\NullIO;
119
use Composer\Installer;
1210
use Composer\Json\JsonFile;
13-
use Composer\Package;
1411
use Composer\Package\BasePackage;
1512
use Composer\Package\PackageInterface;
16-
use Composer\Package\Version\VersionParser;
1713
use Composer\Package\Version\VersionSelector;
1814
use Composer\Repository;
1915
use Composer\Repository\CompositeRepository;
2016
use Composer\Repository\ComposerRepository;
21-
use Composer\Repository\RepositoryManager;
22-
use Composer\Util\Filesystem;
2317
use Composer\Util\HttpDownloader;
24-
use WP_CLI\ComposerIO;
18+
use WP_CLI\Package\ComposerIO;
2519
use WP_CLI\Extractor;
2620
use WP_CLI\Utils;
2721
use WP_CLI\JsonManipulator;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace WP_CLI\Package\Compat\Min_Composer_1_10;
4+
5+
use WP_CLI;
6+
7+
trait NullIOMethodsTrait {
8+
/**
9+
* {@inheritDoc}
10+
*/
11+
public function isVerbose() {
12+
return true;
13+
}
14+
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function write( $messages, $newline = true, $verbosity = self::NORMAL ) {
19+
self::output_clean_message( $messages );
20+
}
21+
22+
/**
23+
* {@inheritDoc}
24+
*/
25+
public function writeError( $messages, $newline = true, $verbosity = self::NORMAL ) {
26+
self::output_clean_message( $messages );
27+
}
28+
29+
private static function output_clean_message( $messages ) {
30+
$messages = (array) preg_replace( '#<(https?)([^>]+)>#', '$1$2', $messages );
31+
foreach ( $messages as $message ) {
32+
// phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
33+
WP_CLI::log( strip_tags( trim( $message ) ) );
34+
}
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace WP_CLI\Package\Compat\Min_Composer_2_3;
4+
5+
use WP_CLI;
6+
7+
trait NullIOMethodsTrait {
8+
/**
9+
* {@inheritDoc}
10+
*/
11+
public function isVerbose(): bool {
12+
return true;
13+
}
14+
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function write( $messages, bool $newline = true, int $verbosity = self::NORMAL ): void {
19+
self::output_clean_message( $messages );
20+
}
21+
22+
/**
23+
* {@inheritDoc}
24+
*/
25+
public function writeError( $messages, bool $newline = true, int $verbosity = self::NORMAL ): void {
26+
self::output_clean_message( $messages );
27+
}
28+
29+
private static function output_clean_message( $messages ) {
30+
$messages = (array) preg_replace( '#<(https?)([^>]+)>#', '$1$2', $messages );
31+
foreach ( $messages as $message ) {
32+
// phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
33+
WP_CLI::log( strip_tags( trim( $message ) ) );
34+
}
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace WP_CLI\Package\Compat;
4+
5+
use Composer\InstalledVersions;
6+
use Composer\Semver\VersionParser;
7+
8+
// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound,Generic.Classes.DuplicateClassName.Found
9+
10+
if (
11+
class_exists( InstalledVersions::class )
12+
&& InstalledVersions::satisfies( new VersionParser(), 'composer/composer', '^2.3' )
13+
) {
14+
require_once __DIR__ . '/Min_Composer_2_3/NullIOMethodsTrait.php';
15+
16+
trait NullIOMethodsTrait {
17+
18+
use Min_Composer_2_3\NullIOMethodsTrait;
19+
}
20+
21+
return;
22+
}
23+
24+
require_once __DIR__ . '/Min_Composer_1_10/NullIOMethodsTrait.php';
25+
26+
trait NullIOMethodsTrait {
27+
28+
use Min_Composer_1_10\NullIOMethodsTrait;
29+
}

src/WP_CLI/Package/ComposerIO.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* A Composer IO class so we can provide some level of interactivity from WP-CLI.
4+
*
5+
* Due to PHP 5.6 compatibility, we have two different implementations of this class.
6+
* This is implemented via traits to make static analysis easier.
7+
*
8+
* See https://github.com/wp-cli/package-command/issues/172.
9+
*/
10+
11+
namespace WP_CLI\Package;
12+
13+
use Composer\IO\NullIO;
14+
use WP_CLI\Package\Compat\NullIOMethodsTrait;
15+
16+
class ComposerIO extends NullIO {
17+
use NullIOMethodsTrait;
18+
}

0 commit comments

Comments
 (0)