1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ComposerJson extends Object |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function ComposerJson($gitHubModuleInstance) |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
if (! $gitHubModuleInstance) { |
8
|
|
|
user_error("CheckComposerJson needs an instance of GitHubModule"); |
9
|
|
|
} |
10
|
|
|
$this->gitHubModuleInstance = $gitHubModuleInstance; |
|
|
|
|
11
|
|
|
$this->moduleName = $gitHubModuleInstance->ModuleName; |
|
|
|
|
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
private function readJsonFromFile() |
15
|
|
|
{ |
16
|
|
|
$folder = GitHubModule::Config()->get('absolute_temp_folder'); |
17
|
|
|
$filename = $folder . '/' . $this->moduleName . '/composer.json'; |
18
|
|
|
|
19
|
|
|
set_error_handler(array($this, 'catchFopenWarning'), E_WARNING); |
20
|
|
|
$file = fopen($filename, 'r'); |
21
|
|
|
restore_error_handler(); |
22
|
|
|
if ($file) { |
23
|
|
|
$json = fread($file, filesize($filename)); |
24
|
|
|
$array = json_decode($json); |
25
|
|
|
$this->jsonData = $array; |
|
|
|
|
26
|
|
|
fclose($file); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
return (isset($this->jsonData)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function updateJsonData() |
34
|
|
|
{ |
35
|
|
|
if (! isset($this->jsonData)) { |
36
|
|
|
$this->readJsonFromFile(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
if (isset($this->jsonData)) { |
41
|
|
|
GeneralMethods::outputToScreen("<li> Updating composer.json </li>"); |
42
|
|
|
$composerUpdates = ClassInfo::subclassesFor('UpdateComposer'); |
43
|
|
|
array_shift($composerUpdates); |
44
|
|
|
|
45
|
|
|
$limitedComposerUpdates = $this->Config()->get('updates'); |
46
|
|
|
|
47
|
|
|
if ($limitedComposerUpdates && count($limitedComposerUpdates)) { |
48
|
|
|
$composerUpdates = array_intersect($composerUpdates, $limitedComposerUpdates); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
foreach ($composerUpdates as $composerUpdate) { |
53
|
|
|
$obj = $composerUpdate::create($this); |
54
|
|
|
$obj->run(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->writeJsonToFile(); |
58
|
|
|
} else { |
59
|
|
|
GeneralMethods::outputToScreen('<li style = "color: red;"> ' . $this->moduleName. ' has no composer.json !!!</li>'); |
60
|
|
|
//UpdateModules::$unsolvedItems[$this->moduleName] = 'No composer.json'; |
|
|
|
|
61
|
|
|
|
62
|
|
|
UpdateModules::addUnsolvedProblem($this->moduleName, 'No composer.json'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function checkOrAddExtra() { |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function writeJsonToFile() |
71
|
|
|
{ |
72
|
|
|
if (! $this->jsonData) { //if not loaded |
73
|
|
|
return false; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$folder = GitHubModule::Config()->get('absolute_temp_folder'); |
77
|
|
|
$filename = $folder . '/' . $this->gitHubModuleInstance->ModuleName . '/composer.json'; |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$file = fopen($filename, 'w'); |
82
|
|
|
if ($file) { |
83
|
|
|
fwrite($file, json_encode($this->jsonData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
84
|
|
|
} |
85
|
|
|
fclose($file); |
86
|
|
|
|
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getDescription() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
if (! property_exists ($this, 'jsonData') || ! $this->jsonData) { //if not loaded |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $this->jsonData->description; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
private function catchFopenWarning() |
101
|
|
|
{ |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.