本文整理汇总了PHP中Illuminate\Routing\RouteCollection::add方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection::add方法的具体用法?PHP RouteCollection::add怎么用?PHP RouteCollection::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGeneratorDefaultsToApplicationRoutes
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'));
}
示例2: mergeExistingRoutes
/**
* 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;
}
示例3: getRoutesByPrefix
/**
* @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;
}
示例4: addRoute
/**
* 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));
}
示例5: fire
/**
* 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;
}