/** * Registers the services provided by this provider. * * @return void */ public function register() { $this->app->singleton('url/canonical/resolver', function () { return new CanonicalUrlResolver(); }); $this->app->singleton('url/canonical', function () { return \Core::make('url/canonical/resolver')->resolve(array()); }); $this->app->bindShared('url/resolver/path', function () { return new PathUrlResolver(); }); $this->app->bindShared('url/resolver/page', function () { return new PageUrlResolver(\Core::make('url/resolver/path')); }); $this->app->bindShared('url/resolver/route', function () { $generator = \Route::getGenerator(); $list = \Route::getList(); return new RouteUrlResolver(\Core::make('url/resolver/path'), $generator, $list); }); $this->app->bind('url/manager', function () { $manager = new ResolverManager('concrete.path', \Core::make('url/resolver/path')); $manager->addResolver('concrete.page', \Core::make('url/resolver/page')); $manager->addResolver('concrete.route', \Core::make('url/resolver/route')); return $manager; }); }
/** * @param string $route * * @return string|null */ protected static function getAssetContentsByRoute($route) { $result = null; try { $routes = \Route::getList(); /* @var $routes \Symfony\Component\Routing\RouteCollection */ $context = new \Symfony\Component\Routing\RequestContext(); $request = \Request::getInstance(); $context->fromRequest($request); $matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context); $matched = null; try { $matched = $matcher->match($route); } catch (\Exception $x) { $m = null; // Route matcher requires that paths ends with a slash if (preg_match('/^(.*[^\\/])($|\\?.*)$/', $route, $m)) { try { $matched = $matcher->match($m[1] . '/' . (isset($m[2]) ? $m[2] : '')); } catch (\Exception $x) { } } } if (isset($matched)) { $controller = $matched['_controller']; if (is_callable($controller)) { ob_start(); $r = call_user_func($controller, false); if ($r !== false) { $result = ob_get_contents(); } ob_end_clean(); } } } catch (\Exception $x) { } return $result; }