Download the PHP package ixianming/laravel-route-service-provider without Composer

On this page you can find all versions of the php package ixianming/laravel-route-service-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-route-service-provider

Laravel RouteServiceProvider

The documentation details the functionality of the extension package, which is more informative, but not more complex.

Usually, the default configuration can meet most of the needs, so you don't need to set it after installing the extension package. You just need to be familiar with the default rules to use it.

[TOC]

About the extension package

The extension package's ServiceProvider inherits Laravel's App\Providers\RouteServiceProvider. therefore, after installing the extension package, the explicit bindings, filters, custom parsing logic, etc. of the routing model defined in the boot() method in App\Providers\RouteServiceProvider are still available.

It should be noted that the changes to map(), mapApiRoutes(), and mapWebRoutes() in App\Providers\RouteServiceProvider are invalid, because the extension overwrites the map() method and the map() method no longer references mapApiRoutes(), mapWebRoutes().

Features

Installation

Installation conditions

Installation

Use Package Auto-Discovery

Don't Use Package Auto-Discovery

If the Laravel version is less than 5.5 or don't use package auto-discovery:

Manually add function to handle the output format of exception information

Add the code before the return of the render method of the App\Exceptions\Handler class:

After modification, the render method should look like this:

Notes for uninstall

Use

Set the middleware groups that are allowed to match routing files

The extension package default web and api middleware groups can match routing files.

To add middleware groups that are allowed to match routing files, add the $allowMatchRouteMiddlewareGroups attribute to app/Providers/RouteServiceProvider.php:

Set whether the global default exception response format is Json

Before using this function, manually add a function to handle the output format of exception information in the render method of App\Exceptions\Handler class, otherwise this function is invalid.

To set the global default exception information response format to Json format, add the $defaultExceptionJsonResponse attribute to app/Providers/RouteServiceProvider.php and set its value to true:

Set whether to allow registration of closure-based route

By default, extension package are allowed to register and use closure-based route.

It is recommended to prohibit registration and use closure-based route.

Why prohibit registration and use of closure-based route:

  • When an application is published, Laravel is usually optimized, and route cache is one of the optimization items. If the Laravel version is below 8.0, the route cache does not apply to closure-based route. If closure-based route is used in Laravel versions below 8.0, an error will be reported when generating the cache! To prevent route cache from being unavailable when the code is released, the best solution is to always disable closure routing.

  • During team development, this configuration can forcibly restrict the way developers can register routes and reduce the risk of mistakes.

To prohibit registration and use of closure-based route, add the $closureRoute attribute to app/Providers/RouteServiceProvider.php and set its value to false:

Set whether the name of the named route allows duplicate names

Name requirements for named routes are unique by default.

Note: The name of a named route should not end with . (English period). In laravel, ending with . will be considered as a route name prefix, not a full name.

Why the name of named routes need to be unique:

To allow duplicate names for named routes, add the $uniqueRouteName attribute to app/Providers/RouteServiceProvider.php and set its value to false:

After banning named routes with the same name, if there are named routes with the same name in all routes, an error message will be thrown. The extension package also indicates the route file path and line where the named route with the same name is located, as well as the middleware group to which it belongs, in order to quickly locate the problem.

Set whether the controller can be reused

Controllers are allowed to be reused by default.

Why prohibit controller reuse:

If you need to prevent controller reuse, add the $allowReuseAction property to app/Providers/RouteServiceProvider.php and set its value to false:

After the controller is prohibited from being reused, it will be checked in all routes whether the controller is reused. If it is reused, an error message will be thrown. The extension package also indicates the route file path and line where the route of the reused controller is located, as well as the middleware group to which it belongs, in order to quickly locate the problem.

Check for duplicate definition URLs

This feature is mandatory and does not provide a switch option.

In Laravel, if you define the same URL, the later routes will overwrite the existing ones. Duplicate definitions are not what we expect, because it makes routing messy, difficult to maintain, and difficult to manage.

After installing the extension package, the extension package will check for duplicate URLs in all routes. If it exists, an exception message will be thrown. The extension package will also indicate the routing file path and line where the duplicate URL is located, as well as the middleware group to which it is located, in order to quickly locate the problem.

URL refers to the full URL with domain name restrictions.

Default rules

Default routing file matching rules

After installing the extension package, the corresponding routing file is automatically matched for each middleware group that is allowed to match the routing file. These routing files can be placed anywhere in the routes directory.

Default matching rules:

Route files names that meet the above rules will be assigned to the middleware group with corresponding names.

Note: In the default rules, the path or file name is not case sensitive.

Note: The same routing file in the routes directory is not allowed to be loaded by multiple middleware groups.

Note: When the same route file in the routes directory is repeatedly loaded more than 3 times, the extension package will throw an exception. The developer should check whether the routing file is repeatedly quoted. If the routing matching rules are customized, you should also check the correctness of the matching rules.

For example:

The root namespace used by default

The root namespace used by all middleware groups that are allowed to match routing files defaults to the value of the attribute $namespace in App\Providers\RouteServiceProvider.

The subdomain used by default

The subdomain name used by all middleware groups that are allowed to match routing files are empty by default.

The routing prefix used by default

E.g:

By default, the prefix of the web middleware group is empty; the prefix of the api middleware group uses the name api of the middleware group. And so on.

The route name prefix used by default

The route name prefix name used by all middleware groups that are allowed to match routing files are empty by default.

Regular expression constraints for routing parameters used by default

The routing parameter regular expression constraints where used by all middleware groups that are allowed to match routing files are empty by default.

Default exception message response format

Before using this function, manually add a function to handle the output format of exception information in the render method of App\Exceptions\Handler class, otherwise this function is invalid.

Custom rules

Custom rules will override the default rules, and uncustomized ones will continue to use the default rules.

Tip: when setting custom rules, if there is an error in setting, an exception will be thrown, and the response format of the exception information will be determined by the default rule.

Custom rules are only valid for middleware groups that are allowed to match routing files. If a middleware group is not allowed to match routing files, even the rules are not useful.

To set custom rules, add the method to app/Providers/RouteServiceProvider.php:

The method return a two-dimensional array. The one-dimensional key {middlewareGroupName} is the name of the middleware group that needs to be customized.

The value of {middlewareGroupName} is also an array. The configurable keys are namespace, domain, prefix, name, where, eJsonResponse, and matchRule.

Customize root namespace used by middleware group

Reminder: If the middleware group customizes the root namespace and does not have the same value as the property $namespace in App\Providers\RouteServiceProvider. Then, when using methods such as action(), redirectToAction(), etc., where the incoming parameter is a controller string, the controller string with the full namespace starting with \ should be passed when the incoming parameter belongs to the controller under that middleware group.

Recommendation: Regardless of whether the root namespace is customizable or not, the controller string with the full namespace starting with \ should be passed when using methods with the controller string as an incoming parameter such as action(), redirectToAction().

e.g.

The Welcome@index controller belongs to the web middleware group and uses the default root namespace App\Http\Controllers.

Before customizing the root namespace of the web middleware group, when using the action() method, you can call: action('Welcome@index'); or action('\App\Http\Controllers\Welcome@index');.

After customizing the root namespace, you need to call: action('\CustomNamespace\Welcome@index');.

If you need to customize the root namespace used by the middleware group, set the namespace key-value pair under the configuration array of the middleware group.

If you do not need to customize the root namespace of the middleware group, please do not set this item's key-value pair under the configuration array of the middleware group, otherwise the default value will be overwritten.

Customize subdomains used by middleware group

To customize the subdomain restrictions used by the middleware group, set the domain key-value pair under the configuration array of that middleware group.

If you do not need to customize the subdomain restrictions of the middleware group, do not set the key-value pairs for this item under the configuration array of that middleware group, otherwise the default value will be overwritten.

Customize routing prefixe used by middleware group

To customize the routing prefix used by the middleware group, set the prefix key-value pair under the configuration array of that middleware group.

If you do not need to customize the routing prefix of the middleware group, do not set the key-value pairs for this item under the configuration array of that middleware group, otherwise the default value will be overwritten.

Customize route name prefix used by middleware group

To customize the route name prefix used by the middleware group, set the name key-value pair under the configuration array of that middleware group.

If you do not need to customize the route name prefix of the middleware group, do not set the key-value pair for this item under the configuration array of that middleware group, otherwise the default value will be overwritten.

Customize regular expression constraints for routing parameters used by middleware group

To customize the routing parameter regular expression constraint used by the middleware group, set the where key value pair under the configuration array of that middleware group.

If you do not need to customize the routing parameter regular expression constraint of the middleware group, do not set the key-value pairs for this item under the configuration array of that middleware group, otherwise the default value will be overwritten.

Customize whether the exception message response format of the middleware group is Json

Before using this function, manually add a function to handle the output format of exception information in the render method of App\Exceptions\Handler class, otherwise this function is invalid.

If you need to customize whether the exception message response format of the middleware group is Json, please set the eJsonResponse key-value pair under the configuration array of the middleware group.

If you do not need to customize the exception message response format of the middleware group, do not set the key-value pairs for this item under the configuration array of that middleware group, otherwise the default value will be overwritten.

Custom routing file matching rules for middleware groups

If you need to customize the routing file matching rules used by the middleware group, please set the matchRule key-value pair under the configuration array of the middleware group.

Note: When the same route file in the routes directory is repeatedly loaded more than 3 times, the extension package will throw an exception. The developer should check whether the routing file is repeatedly quoted. If the routing matching rules are customized, you should also check the correctness of the matching rules.

If you do not need to customize the routing file matching rules of the middleware group, do not set the key-value pair for this item under the configuration array of the middleware group, otherwise the default value will be overwritten.

Generate route cache

When the application is released to the production environment, don't forget to generate the route cache in the production environment!

input the command:

This command generates the route cache file in the bootstrap/cache directory.

Note that route cache does not apply to closure-based route. To use route cache, all closure routes must be converted to controller classes.

If closure route is used, an error will be reported when generating the cache!

In addition, if you add any new routes, you must generate a new route cache!

If you want to remove the cache route file, you can use the command:

License

The extension package is open-sourced software licensed under the MIT license.


All versions of laravel-route-service-provider with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
laravel/framework Version ^5.3|^6.0|^7.0|^8.0|^9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ixianming/laravel-route-service-provider contains the following files

Loading the files please wait ....