Download the PHP package poshtive/router without Composer

On this page you can find all versions of the php package poshtive/router. 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 router

Laravel Router

Convention-based route discovery for Laravel controllers using PHP attributes.

Status

Tests codecov

laravel-router is stable and released as 1.0.0.

Highlights

Installation

You can install the package via Composer:

Optionally, you can publish the configuration file using:

Testing

Run the package test suite with:

Generate a Clover coverage report for src/ with:

Configuration

After publishing, optionally edit config/router.php. Below are the available options.

convention (string)

Controls how controller methods become routes. Default is attribute_or_get.

method_extends (bool)

Include methods inherited from parent classes. Default is false.

Example:

With method_extends = true both index and show register as UserController methods.

http_methods_map (array)

Available only when convention = attribute_or_get.

Maps method names to HTTP verbs when no attribute is present. Accepts string or array.

Example:

Attribute precedence: If a #[Route(method: ...)] is present, it overrides this map.

report_skipped_routes (bool)

Log intentionally skipped discovered methods, such as controllers marked with #[DoNotDiscover] or routes guarded by #[LocalOnly] outside the local environment. Default is false.

strict (bool)

Fail route discovery when duplicate route names or duplicate HTTP_VERB + URI combinations are discovered. Default is false.

Sample Configuration

Quick Decision Guide

Registering Routes

In your routes/web.php, add:

Please note that you can still define routes manually as usual.

How It Works

The package scans the specified directory for controller classes and their public methods. It then registers routes based on the chosen convention and any attributes applied to the classes or methods.

In general, the route path is constructed as follows:

With some exception, see Child Controllers.

Only public methods are considered. Methods inherited from parent classes are included only if method_extends is set to true in the configuration. All other methods are ignored.

Index Controller and Method

Controller named IndexController will have its name omitted from the route path. Also, method named index will have its name omitted from the route path.

Example:

Resulting route: GET / and GET /about.

Resulting route: GET /user and GET /user/show.

Resulting route: GET /admin and GET /admin/dashboard. And so on.

Parameter / Model Binding

Method parameters are converted to route parameters in the order they appear in the method signature. Only primitive types (int, string) and classes extending Illuminate\Database\Eloquent\Model are considered.

Example:

This results in:

Parameter Order

By default, parameters are ordered based on their appearance in the method signature.

Results in GET /user/{id}/update/{section}, please note that the id parameter is placed before the method name. You can override this behavior using keepOrder: true in the Route attribute:

Results in GET /user/update/{id}/{section}.

Child Controllers

When a controller name without the Controller suffix has a folder name matching it in the path, all the controllers inside that folder are treated as child controllers of that controller and the route registration is handled accordingly. See the example below for clarity.

Given the following structure:

The routes will be registered as:

So, all the controller's methods inside the User folder must have at least one parameter that extends Illuminate\Database\Eloquent\Model. Registration will fail otherwise.

Available Attributes

All attributes are in the Poshtive\Router\Attributes namespace.

Route

Can be applied to class or method. Defines middleware, route path, HTTP method(s), and parameters order.

[!NOTE] Only middleware are effective on class level. Other options are ignored.

Example:

This means:

For information why keepOrder is needed here, see this section about Parameter Order.

LocalOnly

Can be applied to class or method. Marks the route as local-only, meaning it will only be registered when the application is running in a local environment.

Example:

Means GET /user is only registered in local environment.

DoNotDiscover

Can be applied to class. Marks all the controller's methods to be ignored during route discovery.

Example:

Means no routes from UserController will be registered.

Please note that the Route attribute if any, will still be effective to child classes.

Example:

Means GET /user will be registered with auth middleware even though AuthenticatedConcerns itself is marked as DoNotDiscover.

Where

Can be applied to method. Defines regex constraints for route parameters.

Example:

Means GET /user/{id}/show will only match if {id} is numeric. If Multiple Where attributes are applied, all constraints must be satisfied.

IgnoreParentMiddleware

Can be applied to class or method. When applied to a class, it prevents middleware defined in parent classes from being inherited. When applied to a method, it prevents middleware defined at the class level from being applied to that specific method. This includes middleware defined by parent classes.

Example:

Means GET /user will be registered without any middleware from AuthenticatedConcerns if any.

Means GET /user/show will be registered without any middleware from AuthenticatedConcerns. But, GET /user/app will still have the auth middleware.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Changelog

Release notes are tracked in CHANGELOG.md.

Licensing

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


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^13.0
illuminate/support Version ^13.0
illuminate/routing Version ^13.0
illuminate/pipeline Version ^13.0
symfony/finder Version ^7.4
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 poshtive/router contains the following files

Loading the files please wait ...