| 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 |
|