Download the PHP package dcp/router without Composer

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

WARNING: UNMAINTAINED!

DCP-Router

DCP-Router provides an extensible, event-oriented, MVC and REST router.

Design goals for the project are always to be concise, simple, extensible, and testable.

Build Status Coverage Status

Getting Started

The easiest, and recommended, way of installing the package is through composer.

Just create a composer.json file in your project, and add the following lines:

Then, run the composer command to install DCP-Router:

Alternatively, you can clone the repository and install the package manually.

Basic Usage

Creating MVC Or REST Routers

The first thing you need to do is instantiate your router. You can choose between an MVC or REST router.

Route Dispatching

Once you have created the router, you can begin dispatching routes immediately without any other configuration.

By default, the router will look for controller classes in the root namespace. This is configurable, and is shown in other areas of this README.

For example, if you choose the MVC router to dispatch routes:

Alternatively, if you choose the REST router to dispatch routes:

Default Routes

When no URL, or a partial URL, is presented to the router, it will assume a default route in order to avoid throwing a NotFound exception.

In the case of the MVC Router, when no route is presented, it will assume an index controller with an index action. If a controller is specified, but not an action, it will assume the index action is to be called.

In the case of the REST router, when no route is presented, it will assume an index controller with a GET method. If a controller is specified, but not an HTTP method, it will assume the GET method is to be called.

Not Found Errors

When the router is not able to find a specified resource, it will throw a NotFoundException, allowing you to display a 404 page if desired.

Controller Namespace Prefixes

When your application becomes complex enough to require structuring with namespaces, you can begin setting namespace prefixes for the router use. The router will look for controllers in whatever namespace you specify.

Router Hierarchy

DCP-Router gives you the ability to create separate site areas with their own URL prefix, such as an administrative site section living under /admin.

In order to facilitate this type of functionality, the project relies on hierarchical routing, where the router will pass the URL off to other router instances when a known prefix is seen.

As an example, we will create a controller that should only be reachable by a /admin URL prefix.

Then, we will create an AdminRouter class to facilitate routing to the App\Admin\Controller namespace of the site.

Finally, we instantiate a router, and tell it that anything under the /admin URL prefix should be handled by AdminRouter.

When the router is told to route to /admin/test/hello, it will see that the first piece of the URL is admin. Since a component was registered with the admin key, the router will dispatch the /test/hello portion of the route to AdminRouter, which will then end up calling TestController#helloAction().

Detailed Usage

Event System

The core of DCP-Router utilizes Evenement and has events for every step of the routing process. This allows you to tie in to any point of the process and execute custom logic, if needed.

There are a total of twelve events, six that are called when a controller is dispatched, and six that are called when a secondary router is dispatched. Events are called in the order listed for their respective areas.

Controller events:

Component events:

To tie into an event, you can simply attach a listener for the event. It will be called when the router enters the specific stage of routing.

Coupling With Dependency Injection Containers

One important aspect of the event system is that it allows for easy integration into various dependency injection containers.

The ControllerEvents::CREATE and ComponentEvents::CREATE events are specifically for instantiating a class, so they can be overridden to pull instances out of a DI container.

Contributing

If you would like to contribute to DCP-Router, you can do so in one of two ways:

Testing

DCP-Router utilizes PHPUnit 3.7.x for automated testing.

All changes to the codebase are accompanied by unit tests.


All versions of router with dependencies

PHP Build Version
Package Version
Requires evenement/evenement Version 2.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 dcp/router contains the following files

Loading the files please wait ....