Exemplo n.º 1
0
 function checkLocalCache($localPath)
 {
     makeDirIfNeeded($localPath);
     if (file_exists($localPath)) {
         return file_get_contents($localPath);
     }
     return false;
 }
Exemplo n.º 2
0
    $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";