Download the PHP package / without Composer

On this page you can find all versions of the php package /. 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?
/
Rate from 1 - 5
Rated 5.00 based on 2 reviews

Informations about the package

WP Route

A Route Service for WordPress that uses the WordPress rewrite engine and adds Laravel syntax to it.

Table of Contents

Introduction

A Route is an address or endpoint in the application. Routes are defined in the /routes directory of your project, unless otherwise specified.

All files in this directory are loaded by the framework while it is booting up.

Note that the Route API imitates Laravel Route

Routes MUST call a Controller as callback!

Getting Started

To get started install the package as described below in Installation.

To use the tool have a look at Usage

Installation

Install with composer

Dependencies

morningtrain/php-loader

PHP Loader is used to load and initialize all Hooks

illuminate/pipeline

Illuminate Pipeline

Symfony HTTP Foundation

Symfony Http Foundation

Usage

Setup

Initialize the package with Route::setup($path) or, if the package is already initialized, load a directory of routes with Route::loadDir($path)

Adding a route

A route with arguments

Using named routes

Grouping Routes

You may group a set of routes to apply a shared prefix to all of them or to apply shared middleware.

With prefix

With middleware

With both prefix and middleware

Accessing WP Query Vars

WordPress query vars are added to the Request class as query data. So you can access them like so:

Middleware

Middleware are functions called for a route after it has been matched against a url, but before its callback is called.

Middleware are useful for validating a group of routes, validating a users permissions or hijacking a request.

Read more about them here: Laravel Docs - Middleware

A quick example

Middleware are function that receive a request object and a closure that represents the next middleware in the pipeline. It is important to always return $next($request); at the end of a valid middleware.

In the example below we create a middleware that stops the pipeline if the current user is not logged in and returns a response with status 404. If the user is logged in the middleware pipeline continues and eventually lets the route call its controller.

A middleware is allowed to either continue the pipeline, return a Response or throw an exception. Responses must be \Symfony\Component\HttpFoundation\Response and will be sent automatically. Exceptions are caught and converted into custom \Morningtrain\WP\Route\Responses\WPErrorResponse that are then displayed using wp_die()

Rest

You can also register rest endpoints using the same syntax! Behind the scenes all Rest routes are registered using register_rest_route

Options

You can use middleware, prefix, groups and names on Rest routes the same way as you can on rewrite routes!!

Note: Middleware is applied AFTER WordPress has identified the route and passed through all other verifications such as permission_callback, but before the controller or supplied callback is called.

Public

To make an endpoint public chain public() on either the route or its group. This simply sets the permission_callback to __return_true. This defaults to __return_false.

Expose

You can expose the endpoint URL to the DOM by chaining expose() onto the route or its group. This outputs the url to a JavaScript object similar to the way localize_script would.

The exposed url can be accessed like so:

Note: to expose an endpoint it has to be named.

Changing the namespace

You can set the namespace the same way you would a prefix.

This can be combined with prefixes

Credits

Testing

License

The MIT License (MIT). Please see License File for more information.


All versions of with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
morningtrain/php-loader Version ^0.3.0
illuminate/pipeline Version ^8|^9
symfony/http-foundation Version ^6
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 / contains the following files

Loading the files please wait ....