-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
98 lines (89 loc) · 2.73 KB
/
Copy pathindex.php
File metadata and controls
98 lines (89 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* @file
* Demo page for Composer dependency tree.
*/
require 'vendor/autoload.php';
use JsonSchema\Validator;
use markfullmer\DependencyTree;
include 'head.html';
$json_lock = file_get_contents('./data/composer.lock');
$json_root = file_get_contents('./data/composer.json');
if (isset($_POST['json']) && isset($_POST['lock'])) {
$json_lock = $_POST['lock'];
$json_root = $_POST['json'];
}
$checked = '';
$version = FALSE;
if (isset($_POST['version'])) {
$checked = 'checked="checked"';
$version = TRUE;
}
$expanded = '';
$expand = '';
if (isset($_POST['expanded'])) {
$expanded = 'checked="checked"';
$expand = 'true';
}
echo '
<div class="container">
<form action="//' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '" method="POST">
<div class="row">
<div class="six columns">
<label for="json">Paste <code>composer.json</code> here</label>
<textarea id="json" class="u-full-width textbox" placeholder="Paste composer.json" name="json">' . $json_root . '</textarea>
</div>
<div class="six columns">
<label for="lock">Paste <code>composer.lock</code> here</label>
<textarea id="lock" class="u-full-width textbox" placeholder="Paste composer.json" name="lock">' . $json_lock . '</textarea>
</div>
</div>
<div class="row">
<div class="twelve columns">
<label><input name="version" type="checkbox" ' . $checked . ' />Display version information</label>
<label><input name="expanded" type="checkbox" ' . $expanded . ' />Begin with tree expanded</label>
<input type="submit" name="submit" value="Generate tree" />
</div>
</div>
</form>
<span>Click colored circles to expand/collapse dependencies.</span>
<figure id="tree"></figure>
</div>
<script>
var json = document.getElementById("json");
var myCodeMirror = CodeMirror.fromTextArea(json, { "theme": "ambiance" });
var lock = document.getElementById("lock");
var myCodeMirror = CodeMirror.fromTextArea(lock, {"theme": "ambiance"});
</script>
';
$print = TRUE;
$validator = new Validator();
$data = json_decode($json_root);
$schema = (object) ['$ref' => 'https://getcomposer.org/schema.json'];
$validator->validate($data, $schema);
if (!$validator->isValid()) {
$print = FALSE;
foreach ($validator->getErrors() as $error) {
echo '<pre>';
printf("[%s] %s\n", $error['property'], $error['message']);
echo '</pre>';
}
}
json_decode($json_lock);
if (!json_last_error() == JSON_ERROR_NONE) {
$print = FALSE;
}
if ($print) {
$data = DependencyTree::generateTree($json_root, $json_lock, $version);
echo '
<script>
dependencyTree(' . $data . ', "figure#tree", ' . $expand . ');
</script>
';
}
else {
echo '<h3>Invalid input</h3>';
}
?>
</body>
</html>