Skip to content

Commit ca8cda5

Browse files
committed
实现功能,从composer.lock读取依库
1 parent 8a828a2 commit ca8cda5

File tree

2 files changed

+127
-8
lines changed

2 files changed

+127
-8
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@ php bin/satis build satis.json ./public
2828
```
2929
启动服务【可选】
3030
```bash
31-
php -S 0.0.0.0:80 -t public/
31+
php -S 0.0.0.0:80 -t ./public
3232
```
3333

34+
## composer.json添加配置
35+
```json
36+
{
37+
"repositories": [{
38+
"type": "composer",
39+
"url": "http://192.168.50.45"
40+
}],
41+
"config":{
42+
"secure-http":false
43+
}
44+
}
45+
```
3446

3547
# Satis
3648

public/admin.php

+114-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<center>
2-
<br/>
2+
33
<div style="width:400px;">
4-
<form action="/admin.php" method="GET">
5-
<input name="q" type="text" style="width:300px;height:35px;line-height:35px;font-size:25px;"/>
6-
<input type="submit" value="search" style=";height:35px;line-height:35px;font-size:25px;" />
4+
<form action="/admin.php?action=query" method="GET">
5+
<p style="text-align: left;">搜索</p>
6+
<input name="q" type="text" style="width:300px;height:35px;line-height:35px;font-size:25px;"/>
7+
<input type="submit" value="search" style=";height:35px;line-height:35px;font-size:25px;" />
8+
</form>
9+
10+
<form action="/admin.php?action=upload" method="post" enctype="multipart/form-data">
11+
<p style="text-align: left;">上传composer.lock</p>
12+
<input name="file" type="file" style="width:300px;height:35px;line-height:35px;font-size:25px;"/>
13+
<input type="submit" value="upload" style=";height:35px;line-height:35px;font-size:25px;" />
714
</form>
815
</div>
916
</center>
@@ -13,21 +20,102 @@
1320

1421
<?php
1522

23+
$action = $_GET['action'];
1624
$q = $_GET['q'];
1725
$p = intval($_GET['p']);
1826
if ($p <1) $p = 1;
1927

2028
echo "<center><div id='list' style='width:400px;text-align:left'>";
2129

30+
31+
32+
if ($action == 'upload') {
33+
$tmp_file = isset($_FILES['file']['tmp_name'])?$_FILES['file']['tmp_name']:"";
34+
35+
if ($tmp_file) {
36+
$json = @json_decode(file_get_contents($tmp_file), true);
37+
38+
$packages = array_merge(
39+
isset($json['packages'])? $json['packages'] : array(),
40+
isset($json['packages-dev']) ? $json['packages-dev'] : array()
41+
);
42+
if (empty($packages)) {
43+
echo "请上传composer.lock文件";
44+
}
45+
$repos = array();
46+
foreach ($packages as $package) {
47+
48+
if (isset($package['source'])) {
49+
$source = $package['source'];
50+
if (isset($source['url']) && isset($source['type'])) {
51+
$repo = array();
52+
$repo['type'] = $source['type'];
53+
$repo['url'] = $source['url'];
54+
$repo['version'] = $package['version'];
55+
$repos[$package['name']] = $repo;
56+
}
57+
}
58+
}
59+
60+
echo "<pre>";
61+
62+
//print_r($repos);
63+
//读物去sataics.json
64+
$satis_json_file = __DIR__."/../satis.json";
65+
$satisData = @json_decode(file_get_contents($satis_json_file), true);
66+
67+
68+
$requires = array();
69+
foreach ($repos as $key => $repo) {
70+
$versionArr = array($repo['version']);
71+
72+
if (isset($satisData['require'][$key])) {
73+
$old_versions = explode("|", $satisData['require'][$key]);
74+
$versionArr = array_merge($versionArr, $old_versions);
75+
$versionArr = array_unique($versionArr);
76+
}
77+
$requires[$key] = implode("|", $versionArr);
78+
79+
//print_r(implode("|", $versionArr));
80+
//echo "\n";
81+
unset($repos[$key]['version']);
82+
}
83+
84+
$new_require = array_merge(
85+
$satisData['require'],
86+
$requires
87+
);
88+
print_r($new_require);
89+
90+
$new_repos = array_merge(
91+
array_values($repos),
92+
$satisData['repositories']
93+
);
94+
95+
$satisData['repositories'] = $new_repos;
96+
$satisData['require'] = $new_require;
97+
98+
file_put_contents($satis_json_file, json_encode($satisData));
99+
100+
//print_r(json_encode(array_values($repos)));
101+
echo "</pre>";
102+
103+
}
104+
die;
105+
}
106+
107+
108+
109+
110+
22111
if ($q) {
23-
$url = "https://packagist.org/search.json?q=" . $q . "&page=" . $p;
112+
$url = "https://packagist.org/search.json?action=query&q=" . $q . "&page=" . $p;
24113
$result = curl_text($url);
25114
$json = @json_decode($result,true);
26115

27116
$next = $json['next'];
28117
$p++;
29118

30-
31119
if ($json) {
32120
echo "<h1>search packages</h1>";
33121
foreach ($json['results'] as $result) {
@@ -37,7 +125,26 @@
37125
echo "<a href='/admin.php?q=".$q."&p=".$p."'>next</a>";
38126
}
39127

40-
128+
// Had to use isset, because current version of json-schema
129+
// cant handle "require" constraints,
130+
131+
// $packages = array_merge(
132+
// (isset($data->packages)) ? $data->packages : array(),
133+
// (isset($data->{'packages-dev'})) ? $data->{'packages-dev'} : array()
134+
// );
135+
//
136+
// $repos = array();
137+
// foreach ($packages as $package) {
138+
// if (isset($package->source)) {
139+
// $source = $package->source;
140+
// if (isset($source->url) && isset($source->type)) {
141+
// $repo = new Repository();
142+
// $repo->setUrl($source->url);
143+
// $repo->setType($source->type);
144+
// $repos[] = $repo;
145+
// }
146+
// }
147+
// }
41148

42149

43150
echo "<pre>";

0 commit comments

Comments
 (0)