|
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
|
|
|
|
|
67
|
|
|
protected function writeJsonToFile() |
|
68
|
|
|
{ |
|
69
|
|
|
if (! $this->jsonData) { //if not loaded |
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$folder = GitHubModule::Config()->get('absolute_temp_folder'); |
|
74
|
|
|
$filename = $folder . '/' . $this->gitHubModuleInstance->ModuleName . '/composer.json'; |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
$file = fopen($filename, 'w'); |
|
79
|
|
|
if ($file) { |
|
80
|
|
|
fwrite($file, json_encode($this->jsonData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
|
81
|
|
|
} |
|
82
|
|
|
fclose($file); |
|
83
|
|
|
|
|
84
|
|
|
return true; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getDescription() |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
if (! property_exists ($this, 'jsonData') || ! $this->jsonData) { //if not loaded |
|
90
|
|
|
return false; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $this->jsonData->description; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
private function catchFopenWarning() |
|
98
|
|
|
{ |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
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.