public function testGeneratorDefaultsToApplicationRoutes() { $this->routes->push($app = new IlluminateRouteCollection()); $app->add(new IlluminateRoute(['GET'], '/app', ['as' => 'foo', 'controller' => 'FooController@foo'])); $this->routes->push($api = new ApiRouteCollection('v1')); $api->add(new ApiRoute(['GET'], '/api', ['as' => 'foo', 'controller' => 'FooController@foo'])); $this->assertEquals('http://www.foo.com/app', $this->url->route('foo')); $this->assertEquals('http://www.foo.com/app', $this->url->action('FooController@foo')); }
/** * Merge the existing routes with the new routes. * * @param \Illuminate\Routing\RouteCollection $routes * * @return \Illuminate\Routing\RouteCollection */ protected function mergeExistingRoutes(RouteCollection $routes) { if (!isset($this->oldRoutes)) { $this->oldRoutes = $this->router->getRoutes(); } foreach ($this->oldRoutes as $route) { $routes->add($route); } return $routes; }
/** * @param string $prefix * * @return RouteCollection */ public static function getRoutesByPrefix($prefix) { $prefix = ltrim(trim($prefix), '/'); $routes = self::getRoutes(); $prefixLength = strlen($prefix); $filteredRoutes = new RouteCollection(); foreach ($routes as $route) { $uri = ltrim(trim($route->getUri()), '/'); if (substr($uri, 0, $prefixLength) == $prefix) { $filteredRoutes->add($route); } } return $filteredRoutes; }
/** * Add a route to the underlying route collection. * * @param array|string $methods * @param string $uri * @param \Closure|array|string|null $action * @return \Illuminate\Routing\Route */ protected function addRoute($methods, $uri, $action) { return $this->routes->add($this->createRoute($methods, $uri, $action)); }
/** * Execute the console command. * * @return boolean */ public function fire() { $this->call('route:clear'); $routes = $this->getFreshApplicationRoutes(); if (count($routes) == 0) { $this->error("Your application doesn't have any routes."); return false; } $languages = $this->laravel['config']['app.supported_locales']; $baseLanguage = $this->laravel['config']['app.locale']; foreach ($languages as $language) { $fileList[$language] = $this->files->allFiles(sprintf('%s/resources/lang/%s/routes', $this->laravel->basePath(), $language)); } $localizedURIs = []; if (!empty($fileList) && is_array($fileList)) { /** * @var \Symfony\Component\Finder\SplFileInfo $file */ foreach ($fileList as $language => $files) { foreach ($files as $file) { $category = $file->getBasename('.php'); $localizedURIs[$language][$category] = (include $file->getRealPath()); } } } $localizedRouteCollection = new RouteCollection(); foreach ($languages as $language) { /** * @var \Illuminate\Routing\Route $route */ foreach ($routes as $route) { //Keeping only our route information $route->prepareForSerialization(); $action = $route->getAction(); if (isset($action['category']) && isset($action['as'])) { if (isset($localizedURIs[$language][$action['category']][$action['as']])) { $tmp = clone $route; $tmp->setUri($localizedURIs[$language][$action['category']][$action['as']]); $action['as'] = $language . '.' . $action['as']; $tmp->setAction($action); } } $localizedRouteCollection->add($tmp); } } $this->files->put($this->laravel->getCachedRoutesPath(), $this->buildRouteCacheFile($localizedRouteCollection)); $this->info('Localized routes cached successfully!'); return true; }