本文整理汇总了PHP中Illuminate\Routing\Router::getRoutes方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getRoutes方法的具体用法?PHP Router::getRoutes怎么用?PHP Router::getRoutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::getRoutes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
// Prepare input
$namespace = $this->getNamespace();
$path = $this->getPath();
// Prepare schema fields
if (!$this->option('no-migration')) {
$this->generateSchemaMigration();
}
// 2. Generate model
$this->call('apigen:model', ['name' => $this->translator->translate($this->argument('name'))->toModelName(), '--path' => $path, '--namespace' => $namespace]);
// 3. Generate repository
$this->call('apigen:repository', ['name' => $this->translator->translate($this->argument('name'))->toModelName(), '--path' => $path, '--namespace' => $namespace]);
// 4. Generate controller
if (!$this->option('no-controller')) {
$this->generateController();
}
// 5. Setup API route
if (!$this->option('no-route') && !$this->option('no-controller')) {
$resourceName = $this->translator->translate($this->argument('name'))->toTableName();
$repositoryName = $this->translator->translate($this->argument('name'))->toRepositoryName();
$routeBaseName = "api.{$resourceName}";
if ($this->router->getRoutes()->hasNamedRoute("{$routeBaseName}.index")) {
$this->error("Assuming routes for {$this->translator->translate($this->argument('name'))->toReadableName()} already exists.");
} else {
$this->info("Setting up route for '{$repositoryName}' ...");
$routeString = "\n\nRoute::resource('{$resourceName}', '{$namespace}\\{$repositoryName}\\{$repositoryName}Controller', [ 'names' => [ " . "\n 'index' => '{$routeBaseName}.index', " . "\n 'create' => '{$routeBaseName}.create', " . "\n 'store' => '{$routeBaseName}.store', " . "\n 'show' => '{$routeBaseName}.show', " . "\n 'edit' => '{$routeBaseName}.edit', " . "\n 'update' => '{$routeBaseName}.update', " . "\n 'destroy' => '{$routeBaseName}.destroy', " . "\n] ]);";
$this->filesystem->append(app_path() . '/routes.php', $routeString);
}
}
// 6. Setup administration interface if needed
if (!$this->option('no-admin')) {
$this->setupAdministrationBackend();
}
}
示例2: getRoutes
/**
* @return RouteCollection
*/
public static function getRoutes()
{
if (is_null(self::$routes)) {
self::$routes = self::$router->getRoutes();
}
return self::$routes;
}
示例3: getProtectedRouteList
/**
* Get route list protected by checkPermission middleware
*
* @return array
*/
public function getProtectedRouteList()
{
if (is_null($this->protectedRouteList)) {
$this->protectedRouteList = [];
$routeList = $this->router->getRoutes();
/** @var \Illuminate\Routing\Route $route */
foreach ($routeList as $route) {
// we need only routes which has permission checking middleware
if (in_array('checkPermission', $route->middleware()) === false) {
continue;
}
if ($route->getActionName() == 'Closure') {
// permissions and closures doesn't work together
continue;
}
$routeName = $route->getName();
if (empty($routeName)) {
// route name should not be empty
continue;
}
$this->protectedRouteList[$routeName] = ['route_action_name' => $route->getActionName(), 'route_name' => $routeName, 'controller_name' => $this->extractControllerName($route->getActionName()), 'controller_action_name' => $this->extractControllerActionName($route->getActionName())];
}
}
return $this->protectedRouteList;
}
示例4: getRoutes
/**
* Compile the routes into a displayable format.
*
* @return array
*/
public function getRoutes()
{
$results = [];
foreach ($this->router->getRoutes() as $route) {
$results[] = $this->getRouteInformation($route);
}
return array_filter($results);
}
示例5: 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;
}
示例6: getForPath
/**
* {@inheritdoc}
*/
public function getForPath($path)
{
/** @var Request $request */
$request = Request::create($path);
try {
$collectionMatcher = new RouteCollectionMatcher($this->router->getRoutes());
if ($route = $collectionMatcher->getRouteForRequest($request)) {
return $this->extractPermissionFrom($route);
}
} catch (HttpException $e) {
}
return null;
}
示例7: getData
/**
* @return mixed get the data to be serialized
*/
public function getData()
{
$this->router = app('router');
$this->url = app('url');
$data = array('currentRoute' => $this->router->current());
$routes = $this->router->getRoutes();
$results = array();
foreach ($routes as $name => $route) {
$results[] = $this->getRouteInformation($route, $data['currentRoute']);
}
$data['routes'] = $results;
return array('router' => $data);
}
示例8: mergeOldRoutes
/**
* Merge the old application routes with the API routes.
*
* @param string $version
*
* @return array
*/
protected function mergeOldRoutes($version)
{
if (!isset($this->oldRoutes)) {
$this->oldRoutes = $this->router->getRoutes();
}
if (!isset($this->mergedRoutes[$version])) {
$this->mergedRoutes[$version] = $this->routes[$version];
foreach ($this->oldRoutes as $route) {
$this->mergedRoutes[$version]->add($route);
}
}
return $this->mergedRoutes[$version];
}
示例9: excludedRouteNames
protected function excludedRouteNames($request)
{
$routes = $this->router->getRoutes();
foreach ($this->excludedRouteNames as $name) {
if ($routes->hasNamedRoute($name)) {
$route = $routes->getByName($name);
if ($route->matches($request)) {
return true;
}
}
}
return false;
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$route = $this->router->getRoutes()->match($request);
if ($route) {
$subdomain = $route->parameter(config('tenant.subdomain'));
$config = $this->tenantManager->getDatabaseConfig($subdomain);
if ($config) {
config()->set("database.connections.tenant", $config);
$this->db->setDefaultConnection('tenant');
$this->db->reconnect('tenant');
return $next($request);
}
}
abort(404);
}
示例11: last_page
/**
* @return string
*/
public function last_page()
{
$lang = null;
$collection = $this->router->getRoutes();
$route = $collection->match(Request::create($this->wrappedObject->last_page));
if ($route->getName() != null) {
$langOptions = $this->getWioData($route->getName(), $route->parameters());
if (!isset($langOptions['url'])) {
$langOptions['url'] = route($route->getName(), $route->parameters());
}
if (!isset($langOptions['langString'])) {
$langString = 'online.' . $route->getName();
} else {
$langString = 'online.' . $langOptions['langString'];
unset($langOptions['langString']);
}
$lang = $this->translator->get($langString, $langOptions);
// May happen if we have two routes 'xy.yx.zz' and 'xy.yx'
if (is_array($lang)) {
$lang = $this->translator->get($langString . '.index', $langOptions);
}
}
if ($lang == null) {
// $lang = Lang::get('online.unknown', ['url' => '']);
// Used for debugging, should be left here until we have added all routes
$lang = 'online.' . $route->getName();
}
return $lang;
}
示例12: __construct
/**
* Create a new route command instance.
*
* @param \Illuminate\Routing\Router $router
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Illuminate\Filesystem\Filesystem $filesystem
*/
public function __construct(Router $router, ConfigRepository $config, Filesystem $filesystem)
{
parent::__construct();
$this->routes = $router->getRoutes();
$this->config = $config->get('path2api');
$this->filesystem = $filesystem;
}
示例13: testResourceRoute
public function testResourceRoute()
{
/* @var Dispatcher $dispatcher */
$dispatcher = $this->getMock(Dispatcher::class);
$router = new Router($dispatcher, null);
$routeHelper = new RouteHelper($router);
$routeHelper->resource('test', 'TestController')->get('get_test', 'get_test')->post('post_test', 'post_test')->put('put_test', 'put_test')->patch('patch_test', 'patch_test')->delete('delete_test', 'delete_test')->rawGet('rawget', 'rawget')->rawPost('rawpost', 'rawpost')->rawPut('rawput', 'rawput')->rawPatch('rawpatch', 'rawpatch')->rawDelete('rawdelete', 'rawdelete')->done();
$routes = $router->getRoutes();
$this->assertRoute($routes, 'test', 'GET', 'TestController@index');
$this->assertRoute($routes, 'test?' . RouteHelper::PAGINATION_URI, 'GET', 'TestController@index');
$this->assertRoute($routes, 'test', 'POST', 'TestController@store');
$this->assertRoute($routes, 'test/{test}', 'GET', 'TestController@show');
$this->assertRoute($routes, 'test/{test}', 'PUT', 'TestController@update');
$this->assertRoute($routes, 'test/{test}', 'PATCH', 'TestController@update');
$this->assertRoute($routes, 'test/{test}', 'DELETE', 'TestController@destroy');
$this->assertRoute($routes, 'test/{test}/get_test', 'GET', 'TestController@get_test');
$this->assertRoute($routes, 'test/{test}/post_test', 'POST', 'TestController@post_test');
$this->assertRoute($routes, 'test/{test}/put_test', 'PUT', 'TestController@put_test');
$this->assertRoute($routes, 'test/{test}/patch_test', 'PATCH', 'TestController@patch_test');
$this->assertRoute($routes, 'test/{test}/delete_test', 'DELETE', 'TestController@delete_test');
$this->assertRoute($routes, 'test/rawget', 'GET', 'TestController@rawget');
$this->assertRoute($routes, 'test/rawpost', 'POST', 'TestController@rawpost');
$this->assertRoute($routes, 'test/rawput', 'PUT', 'TestController@rawput');
$this->assertRoute($routes, 'test/rawpatch', 'PATCH', 'TestController@rawpatch');
$this->assertRoute($routes, 'test/rawdelete', 'DELETE', 'TestController@rawdelete');
}
示例14: __construct
public function __construct(Arr $arr, Request $request, Router $router)
{
$this->arr = $arr;
$this->request = $request;
$this->user = $request->user();
$this->router = $router;
$this->routes = $router->getRoutes();
}
示例15: __construct
public function __construct(Router $router, Filesystem $filesystem, $appUrl, $savePath, $saveName)
{
parent::__construct();
$this->routes = $router->getRoutes();
$this->filesystem = $filesystem;
$this->appUrl = $appUrl;
$this->filePath = $savePath . '/' . $saveName . '.html';
}