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) { if ($app['debug']) { return; } $page = 404 == $code ? '404.twig' : '500.twig'; return new Response($app['twig']->render($page, array('code' => $code)), $code); });