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