Download the PHP package inroutephp/inroute without Composer

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

Packagist Version Build Status Quality Score

Generate http routing and dispatching middleware from docblock annotations.

Inroute is a code generator. It scans your source tree for annotated routes and generates a PSR-15 compliant http routing middleware. In addition all routes have a middleware pipeline of their own, making it easy to add behaviour at compile time based on custom annotations.

Installation

Table of contents

  1. Writing routes
  2. Piping a route through a middleware
  3. Compiling
  4. Dispatching
  5. Generating route paths
  6. Creating custom annotations
  7. Processing routes using compiler passes
  8. Handling dependencies with a DI container
  9. Dealing with routing errors

Writing routes

Routes are annotated using annotations, are called with a PSR-7 request object and inroute environment and are expected to return a PSR-7 response.

Piping a route through a middleware

Each route has a PSR-15 middleware pipeline of its own. Adding a middleware to a route can be done using the @Pipe annotation. In the following example the pipedAction route is piped through the AppendingMiddleware and the text ::Middleware is appended to the route response.

Compiling

The recommended way of building a project is by using the console build tool. Compiling from pure php involves setting up the compiler something like the following.

Possible settings include

OpenApi

Please note that reading openapi annotations is still very rudimentary. Please open an issue if you have suggestions on more values that should be parsed.

Instead of using the built in annotations inroute is also able to build openapi projects annotated with swagger-php annotations.

Set the core-compiler-passes setting to ['inroutephp\inroute\OpenApi\OpenApiCompilerPass'].

Dispatching

The generated router is a PSR-15 compliant middleware. To dispatch you need to supply an implementation of PSR-7 for request and response objects and some response emitting functionality (of course you should also use a complete middleware pipeline for maximum power).

In this simple example we use

Or to send to piped example from above

Generating route paths

Creating custom annotations

Inroute uses doctrine to read annotations. Creating custom annotations is as easy as

To create annotations that automatically pipes a route through a middleware use something like the following.

Note that you need to supply the AuthMiddleware to authenticate a user and the RequireUserGroupMiddleware to check user priviliges for this example to function as expected. See below on how to inject a dependency container that can deliver these middlewares.

And to annotate your controller methods

Processing routes using compiler passes

Custom annotations are most useful pared with custom compiler passes.

Each route has a middleware pipeline of its own. In the example above all routes annotated with MyAnnotation will be wrapped in SomeCoolMiddleware. This makes it easy to add custom behaviour to routes at compile time based on annotations.

The attribute cool-attribute can be accessed in middlewares using $request->getAttribute('cool-attribute').

Handling dependencies with a DI container

You may have noted that in the example above SomeCoolMiddleware was passed not as an instantiated object but as a class name. The actual object is created at runtime using a PSR-11 compliant dependency injection container. The same is true for controller classes.

Create you container as part of your dispatching logic and pass it to the router using the setContainer() method.

Dealing with routing errors

Route note found (http code 404) and method not allowed (405) situations can be handled in one of two ways.

Using a ResponseFactoryInterface

If you container contains a service Psr\Http\Message\ResponseFactoryInterface then that factory will be used to create and return a 404 or 405 http response.

Catching exceptions

If no factory is defined a inroutephp\inroute\Runtime\Exception\RouteNotFoundException or inroutephp\inroute\Runtime\Exception\MethodNotAllowedException will be thrown.


All versions of inroute with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
psr/container Version ^1
psr/http-factory Version ^1
psr/http-message Version ^1
psr/http-server-middleware Version ^1
aura/router Version ^3
symfony/var-exporter Version ^5
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 inroutephp/inroute contains the following files

Loading the files please wait ....