PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / composer / installers / src / Composer / Installers / CakePHPInstaller.php

CakePHPInstaller.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php

68 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Composer\Installers;
4
5 use Composer\DependencyResolver\Pool;
6 use Composer\Semver\Constraint\Constraint;
7
8 class CakePHPInstaller extends BaseInstaller
9 {
10 /** @var array<string, string> */
11 protected $locations = array(
12 'plugin' => 'Plugin/{$name}/',
13 );
14
15 /**
16 * Format package name to CamelCase
17 */
18 public function inflectPackageVars(array $vars): array
19 {
20 if ($this->matchesCakeVersion('>=', '3.0.0')) {
21 return $vars;
22 }
23
24 $nameParts = explode('/', $vars['name']);
25 foreach ($nameParts as &$value) {
26 $value = strtolower($this->pregReplace('/(?<=\\w)([A-Z])/', '_\\1', $value));
27 $value = str_replace(array('-', '_'), ' ', $value);
28 $value = str_replace(' ', '', ucwords($value));
29 }
30 $vars['name'] = implode('/', $nameParts);
31
32 return $vars;
33 }
34
35 /**
36 * Change the default plugin location when cakephp >= 3.0
37 */
38 public function getLocations(string $frameworkType): array
39 {
40 if ($this->matchesCakeVersion('>=', '3.0.0')) {
41 $this->locations['plugin'] = $this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/';
42 }
43 return $this->locations;
44 }
45
46 /**
47 * Check if CakePHP version matches against a version
48 *
49 * @phpstan-param '='|'=='|'<'|'<='|'>'|'>='|'<>'|'!=' $matcher
50 */
51 protected function matchesCakeVersion(string $matcher, string $version): bool
52 {
53 $repositoryManager = $this->composer->getRepositoryManager();
54 /** @phpstan-ignore-next-line */
55 if (!$repositoryManager) {
56 return false;
57 }
58
59 $repos = $repositoryManager->getLocalRepository();
60 /** @phpstan-ignore-next-line */
61 if (!$repos) {
62 return false;
63 }
64
65 return $repos->findPackage('cakephp/cakephp', new Constraint($matcher, $version)) !== null;
66 }
67 }
68