Download the PHP package ssnepenthe/simple-wp-routing without Composer

On this page you can find all versions of the php package ssnepenthe/simple-wp-routing. 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 simple-wp-routing

simple-wp-routing

Syntactic sugar over the WP_Rewrite API so we can pretend that WordPress has a modern router.

Warning

This package is currently in development and is subject to breaking changes without notice until v1.0 has been tagged.

It is one in a series of WordPress toys I have been working on with the intention of exploring ways to modernize the feel of working with WordPress.

As the label suggests, it should be treated as a toy.

Installation

Basic Usage

Intended usage is via the Router class.

Overview

Route Syntax

The default route syntax comes from FastRoute.

Route variables are wrapped in curly brackets and match the regex pattern [^/]+ by default (e.g. users/{user}). Custom regex patterns can be provided using a name:pattern syntax (e.g. users/{user:\d+}). Capture groups are not allowed in custom patterns.

Optional route segments are defined using square brackets (e.g. users/{user}[/favorites]). Nested optional segments are also supported (e.g. users[/{user}[/favorites]]). Optional segments are only supported at the end of route strings.

If you have a route syntax that you prefer over FastRoute, you can provide a custom route parser. Your parser must implement \SimpleWpRouting\Parser\RouteParserInterface. Refer to the included tests/Unit/Parser/FastRouteRouteParserTest.php file to understand route parser requirements.

Route Handlers

Route handlers are automatically called within the 'parse_request' hook when their corresponding route/method pair matches the current request.

Allowed types for handlers are defined by the callable resolver. With the default config, handlers must be a PHP callable. If using the PSR container callable resolver, handlers may also be a string identifier that resolves a callable from your container or a callable shaped array where index 0 is a string identifier that resolves an object from your container and index 1 is a callable method on that object.

The function signature is defined by the configured invoker. The default invoker provides an array containing all matched route variables keyed by variable name. The PHP-DI invoker provides matched route variables directly by name.

HTTP exceptions can be used as a convenient escape hatch from handlers.

NotFoundHttpException

This is currently the only non-internal HTTP exception and can be used to show a 404 page.

Route handlers can optionally return an instance of SimpleWpRouting\Responder\ResponderInterface. The respond method on the returned responder will automatically be invoked on the WordPress parse_request action.

This allows common behavior to easily be wrapped up for reuse.

The following basic responder implementations are included:

JsonResponder

Responses are sent using wp_send_json_success or wp_send_json_error depending on the status code, so data will be available at response.data.

QueryResponder

Query variables are applied on the parse_request hook, before the main query is run.

RedirectResponder

Redirects are sent using wp_safe_redirect by default. You can pass false as the 4th constructor argument to use wp_redirect instead:

TemplateResponder

Templates are loaded via the template_include filter.

Active Callbacks

Allowed types for active callbacks are also defined by the configured callable resolver.

Active callbacks should return a boolean value - when true the route will be considered active, when false the route will be considered inactive.

Rewrite rules and query variables for inactive routes are still registered with WordPress, but visiting the route will result in a 404 response.

Error Templates

Basic 400 and 405 error templates are included with styling loosely modeled after the twentytwentytwo 404 template.

These can be overridden in themes by creating 400.php and 405.php templates or 400.html and 405.html block templates.

Likely Changes

Types of various SPL exceptions used throughout the package as well as revisiting the general hierarchy of package exceptions.

Responder internals - partials concept is a bit convoluted/over-engineered. Any changes shouldn't affect the top-level responders meant for use by end-users.


All versions of simple-wp-routing with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.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 ssnepenthe/simple-wp-routing contains the following files

Loading the files please wait ....