forked from kawahara/composer-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.php
More file actions
79 lines (57 loc) · 2.39 KB
/
routes.php
File metadata and controls
79 lines (57 loc) · 2.39 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
<?php
$app->get('/', function () use ($app) {
$body = $app['twig']->render('index.html.twig', array(
'app' => $app,
));
return new Symfony\Component\HttpFoundation\Response($body, 200, array('Cache-Control' => 's-maxage=3600,public'));
});
$app->get('{rep}/packages.json', function ($rep) use ($app) {
checkConfig($app, $rep);
$url = $app['repositories'][$rep] . "/packages.json";
$response = $app['browser']->get($url);
if (!$response->isOk()) {
$app->abort($response->getStatusCode(), "");
}
$responseJson = json_decode($response->getContent(), true);
// convert
if (isset($responseJson['notify']) && $responseJson['notify'][0] === '/') {
$responseJson['notify'] = $app['repositories'][$rep] . $responseJson['notify'];
}
if (isset($responseJson['notify-batch']) && $responseJson['notify-batch'][0] === '/') {
$responseJson['notify-batch'] = $app['repositories'][$rep] . $responseJson['notify-batch'];
}
if (isset($responseJson['search']) && $responseJson['search'][0] === '/') {
$responseJson['search'] = $app['repositories'][$rep] . $responseJson['search'];
}
$responseJson['providers-url'] = "/" . $rep . "/p/%package%$%hash%.json";
$path = '/';
$file = 'packages.json';
$localPath = $app['cache_dir'] . "/" . $rep . $path . $file;
makeDirIfNeeded($localPath);
makeLocalCache($responseJson, $localPath);
return $app->json($responseJson);
});
$app->get('{rep}/p/{provider}${hash}.json', function ($rep, $provider, $hash) use ($app) {
checkConfig($app, $rep);
$path = "/p/";
$file = $provider . "$" . $hash . ".json";
$url = $app['repositories'][$rep] . $path . $file;
$localPath = $app['cache_dir'] . "/" . $rep . $path . $file;
return load($app, $url, $localPath);
});
$app->get('{rep}/p/{namespace}/{package}${hash}.json', function ($rep, $namespace, $package, $hash) use ($app) {
checkConfig($app, $rep);
$path = "/p/" . $namespace . "/";
$file = $package . "$" . $hash . ".json";
$url = $app['repositories'][$rep] . $path . $file;
$localPath = $app['cache_dir'] . "/" . $rep . $path . $file;
return load($app, $url, $localPath);
});
$app->get('{rep}/p/{namespace}/{package}.json', function ($rep, $namespace, $package) use ($app) {
checkConfig($app, $rep);
$path = "/p/" . $namespace . "/";
$file = $package . ".json";
$url = $app['repositories'][$rep] . $path . $file;
$localPath = $app['cache_dir'] . "/" . $rep . $path . $file;
return load($app, $url, $localPath);
});