PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / vendor / composer / installers / src / Composer / Installers / CakePHPInstaller.php

CakePHPInstaller.php in Code Snippets 3.10.0, 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