1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHINT package. |
5
|
|
|
* |
6
|
|
|
* (c) Jitendra Adhikari <[email protected]> |
7
|
|
|
* <https://github.com/adhocore> |
8
|
|
|
* |
9
|
|
|
* Licensed under MIT license. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ahc\Phint\Util; |
13
|
|
|
|
14
|
|
|
class Composer extends Executable |
15
|
|
|
{ |
16
|
|
|
/** @var array Content of composer.json decoded */ |
17
|
|
|
protected $config = []; |
18
|
|
|
|
19
|
|
|
/** @var string The binary executable */ |
20
|
|
|
protected $binary = 'composer'; |
21
|
|
|
|
22
|
|
|
public function createProject($project, $using) |
23
|
|
|
{ |
24
|
|
|
$this->runCommand(sprintf('create-project %s %s', $using, $project)); |
25
|
|
|
|
26
|
|
|
return $this; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function install() |
30
|
|
|
{ |
31
|
|
|
$this->runCommand('install --prefer-dist --optimize-autoloader --no-suggest'); |
32
|
|
|
|
33
|
|
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function update() |
37
|
|
|
{ |
38
|
|
|
$this->runCommand('update --prefer-dist --optimize-autoloader --no-suggest'); |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function dumpAutoload() |
44
|
|
|
{ |
45
|
|
|
$this->runCommand('dump-autoload --optimize'); |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function config(string $key, $default = null) |
51
|
|
|
{ |
52
|
|
|
if (!$this->config) { |
|
|
|
|
53
|
|
|
$this->config = (new Path)->readAsJson($this->workDir . '/composer.json'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$temp = $this->config; |
57
|
|
|
foreach (\explode('.', $key) as $part) { |
58
|
|
|
if (\is_array($temp) && \array_key_exists($part, $temp)) { |
59
|
|
|
$temp = $temp[$part]; |
60
|
|
|
} else { |
61
|
|
|
return $default; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $temp; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function forceAutoload() |
69
|
|
|
{ |
70
|
|
|
$autoloader = $this->workDir . '/vendor/autoload.php'; |
71
|
|
|
|
72
|
|
|
if (\array_search($autoloader, \get_included_files()) === false) { |
73
|
|
|
require_once $autoloader; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.