|
1
|
|
|
<?php |
|
2
|
|
|
namespace Composer\Installers; |
|
3
|
|
|
|
|
4
|
|
|
use Composer\DependencyResolver\Pool; |
|
5
|
|
|
|
|
6
|
|
|
class CakePHPInstaller extends BaseInstaller |
|
7
|
|
|
{ |
|
8
|
|
|
protected $locations = array( |
|
9
|
|
|
'plugin' => 'Plugin/{$name}/', |
|
10
|
|
|
); |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Format package name to CamelCase |
|
14
|
|
|
*/ |
|
15
|
|
|
public function inflectPackageVars($vars) |
|
16
|
|
|
{ |
|
17
|
|
|
if ($this->matchesCakeVersion('>=', '3.0.0')) { |
|
18
|
|
|
return $vars; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$nameParts = explode('/', $vars['name']); |
|
22
|
|
|
foreach ($nameParts as &$value) { |
|
23
|
|
|
$value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value)); |
|
24
|
|
|
$value = str_replace(array('-', '_'), ' ', $value); |
|
25
|
|
|
$value = str_replace(' ', '', ucwords($value)); |
|
26
|
|
|
} |
|
27
|
|
|
$vars['name'] = implode('/', $nameParts); |
|
28
|
|
|
|
|
29
|
|
|
return $vars; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Change the default plugin location when cakephp >= 3.0 |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getLocations() |
|
36
|
|
|
{ |
|
37
|
|
|
if ($this->matchesCakeVersion('>=', '3.0.0')) { |
|
38
|
|
|
$this->locations['plugin'] = $this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/'; |
|
39
|
|
|
} |
|
40
|
|
|
return $this->locations; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Check if CakePHP version matches against a version |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $matcher |
|
47
|
|
|
* @param string $version |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function matchesCakeVersion($matcher, $version) |
|
51
|
|
|
{ |
|
52
|
|
|
if (class_exists('Composer\Semver\Constraint\MultiConstraint')) { |
|
53
|
|
|
$multiClass = 'Composer\Semver\Constraint\MultiConstraint'; |
|
54
|
|
|
$constraintClass = 'Composer\Semver\Constraint\Constraint'; |
|
55
|
|
|
} else { |
|
56
|
|
|
$multiClass = 'Composer\Package\LinkConstraint\MultiConstraint'; |
|
57
|
|
|
$constraintClass = 'Composer\Package\LinkConstraint\VersionConstraint'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$repositoryManager = $this->composer->getRepositoryManager(); |
|
61
|
|
|
if ($repositoryManager) { |
|
62
|
|
|
$repos = $repositoryManager->getLocalRepository(); |
|
63
|
|
|
if (!$repos) { |
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
$cake3 = new $multiClass(array( |
|
67
|
|
|
new $constraintClass($matcher, $version), |
|
68
|
|
|
new $constraintClass('!=', '9999999-dev'), |
|
69
|
|
|
)); |
|
70
|
|
|
$pool = new Pool('dev'); |
|
71
|
|
|
$pool->addRepository($repos); |
|
72
|
|
|
$packages = $pool->whatProvides('cakephp/cakephp'); |
|
73
|
|
|
foreach ($packages as $package) { |
|
74
|
|
|
$installed = new $constraintClass('=', $package->getVersion()); |
|
75
|
|
|
if ($cake3->matches($installed)) { |
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|