use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\Resource\FileResource; $locator = new FileLocator(__DIR__ . '/config'); $loader = new YamlFileLoader($locator); if (function_exists('apc_add')) { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\PhpFileCache(__DIR__ . '/../cache/routes'); } if (!$app['debug'] && $cache->contains($app['app.runconfig']['routing']['cachename'])) { $routes = $cache->fetch($app['app.runconfig']['routing']['cachename']); foreach ($routes as $name => $route) { $r = new \Silex\Route(); $r->unserialize($route); $app['routes']->add($name, $r); } } else { $routes = $loader->load('routes.yml'); $array = array(); foreach ($routes->all() as $name => $route) { $array[$name] = $route->serialize(); } $cache->save($app['app.runconfig']['routing']['cachename'], $array, $app['app.runconfig']['routing']['cachettl']); $app['routes']->addCollection($routes); } $app->error(function (\Exception $e, $code) use($app) {