@@ -19,14 +19,16 @@ class CachetoolTask extends TaskBase
1919 /**
2020 * @var string[]
2121 *
22+ * CacheTool 9.x/10.x works with PHP >=8.1
2223 * CacheTool 8.x works with PHP >=8.0
2324 * CacheTool 7.x works with PHP >=7.3
2425 * CacheTool 6.x works with PHP >=7.3
2526 * CacheTool 5.x works with PHP >=7.2
2627 * CacheTool 4.x works with PHP >=7.1
2728 */
2829 private $versionBinaryMapping = [
29- 8 => 'https://github.com/gordalina/cachetool/releases/download/8.4.0/cachetool.phar',
30+ 10 => 'https://github.com/gordalina/cachetool/releases/download/10.0.0/cachetool.phar',
31+ 8 => 'https://github.com/gordalina/cachetool/releases/download/8.6.1/cachetool.phar',
3032 7 => 'https://github.com/gordalina/cachetool/releases/download/7.1.0/cachetool.phar',
3133 6 => 'https://github.com/gordalina/cachetool/releases/download/6.6.0/cachetool.phar',
3234 5 => 'https://github.com/gordalina/cachetool/releases/download/5.1.3/cachetool.phar',
@@ -35,7 +37,6 @@ class CachetoolTask extends TaskBase
3537
3638 public function register(): void
3739 {
38- after('deploy:symlink', 'cachetool:clear:opcache');
3940 after('cachetool:clear:opcache', 'cachetool:cleanup');
4041 }
4142
@@ -52,10 +53,10 @@ public function configure(Configuration $config): void
5253 $cachetoolBinary = get('cachetool_binary');
5354
5455 within('{{release_path}}', function () {
55- run('curl -L -o cachetool.phar ' . $this->getCachetoolUrl() );
56+ $phpVersion = $this->getPhpVersion( );
5657 $cachetoolBinary = '{{release_path}}/cachetool.phar';
57-
58- writeln(sprintf("Downloaded cachetool %s for PHP %f ", $cachetoolBinary, $this->getPhpVersion() ));
58+ run('curl -L -o cachetool.phar ' . $this->getCachetoolUrl($phpVersion));
59+ writeln(sprintf("Downloaded cachetool %s for PHP %s ", $cachetoolBinary, $phpVersion ));
5960 return $cachetoolBinary;
6061 });
6162 return $cachetoolBinary;
@@ -103,30 +104,36 @@ public function configure(Configuration $config): void
103104 });
104105 }
105106
106- protected function getPhpVersion(): float
107+ protected function getPhpVersion(): string
107108 {
108- return (float) run('{{bin/php}} -r "echo PHP_VERSION . \" - \" . PHP_VERSION_ID ;"');
109+ return run('{{bin/php}} -r "echo PHP_VERSION;"');
109110 }
110111
111- public function getCachetoolUrl(): string
112+ public function getCachetoolUrl(?string $phpVersion = null ): string
112113 {
113- $phpVersion = $this->getPhpVersion();
114- if ($phpVersion >= 8.0) {
114+ $phpVersion = $phpVersion ?? $this->getPhpVersion();
115+
116+ if (version_compare($phpVersion, '8.1.0', '>=')) {
117+ return $this->versionBinaryMapping[10];
118+ }
119+
120+ if (version_compare($phpVersion, '8.0.0', '>=')) {
115121 return $this->versionBinaryMapping[8];
116122 }
117123
118- if ($phpVersion >= 7.3) {
124+ if (version_compare( $phpVersion, ' 7.3.0', '>=') ) {
119125 return $this->versionBinaryMapping[7];
120126 }
121127
122- if ($phpVersion >= 7.2) {
128+ if (version_compare( $phpVersion, ' 7.2.0', '>=') ) {
123129 return $this->versionBinaryMapping[5];
124130 }
125131
126- if ($phpVersion >= 7.1) {
132+ if (version_compare( $phpVersion, ' 7.1.0', '>=') ) {
127133 return $this->versionBinaryMapping[4];
128134 }
129135
130- return $this->versionBinaryMapping[8];
136+ // Default to latest for unknown/newer PHP versions
137+ return $this->versionBinaryMapping[10];
131138 }
132139}
0 commit comments