CakePHPInstaller.php in Zircon Profile 8
File
vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php
View source
<?php
namespace Composer\Installers;
use Composer\DependencyResolver\Pool;
use Composer\Package\PackageInterface;
use Composer\Package\LinkConstraint\MultiConstraint;
use Composer\Package\LinkConstraint\VersionConstraint;
class CakePHPInstaller extends BaseInstaller {
protected $locations = array(
'plugin' => 'Plugin/{$name}/',
);
public function inflectPackageVars($vars) {
if ($this
->matchesCakeVersion('>=', '3.0.0')) {
return $vars;
}
$nameParts = explode('/', $vars['name']);
foreach ($nameParts as &$value) {
$value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value));
$value = str_replace(array(
'-',
'_',
), ' ', $value);
$value = str_replace(' ', '', ucwords($value));
}
$vars['name'] = implode('/', $nameParts);
return $vars;
}
public function getLocations() {
if ($this
->matchesCakeVersion('>=', '3.0.0')) {
$this->locations['plugin'] = $this->composer
->getConfig()
->get('vendor-dir') . '/{$vendor}/{$name}/';
}
return $this->locations;
}
protected function matchesCakeVersion($matcher, $version) {
$repositoryManager = $this->composer
->getRepositoryManager();
if ($repositoryManager) {
$repos = $repositoryManager
->getLocalRepository();
if (!$repos) {
return false;
}
$cake3 = new MultiConstraint(array(
new VersionConstraint($matcher, $version),
new VersionConstraint('!=', '9999999-dev'),
));
$pool = new Pool('dev');
$pool
->addRepository($repos);
$packages = $pool
->whatProvides('cakephp/cakephp');
foreach ($packages as $package) {
$installed = new VersionConstraint('=', $package
->getVersion());
if ($cake3
->matches($installed)) {
return true;
break;
}
}
}
return false;
}
}