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