PluginProbe
Code Snippets / 3.0.0
Code Snippets v3.0.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.0.0, at vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php

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