本文整理匯總了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;
}