Download the PHP package websk/php-simple-router without Composer

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

PHP Simple Router

A small library for routing HTTP requests in PHP applications and generating XML sitemaps.

The router checks the current path against regular expressions in declaration order, extracts parameters from captured groups, and passes them to a controller method. The library does not impose an application structure or require a dependency injection container or HTTP framework.

Features

Requirements

Installation

Basic routing

A controller can be passed as either an object or a class name. When a class name is used, the router creates the object without constructor arguments.

For a request to /articles/hello%20world?draft=1, the show() method receives hello world. The query string is ignored during route matching.

After a matching handler runs, the router terminates the PHP script. To continue checking subsequent routes, the controller method must return SimpleRouter::CONTINUE_ROUTING:

Declare routes from the most specific to the most general. The application can handle an unmatched request after the route declarations.

Route groups

matchGroup() lets the application skip a block of route declarations when the current URL does not match a common pattern:

Static routes

staticRoute() creates a controller, stores it as the current controller, and calls the specified method. Captured parameters are URL-decoded. An optional layout file is appended as the final method argument.

The active controller is available through SimpleRouter::getCurrentControllerObj(). If the handler returns SimpleRouter::CONTINUE_ROUTING, the router clears the current controller and continues execution.

CRUD routes

The routeBasedCrud() method registers a standard set of URLs for a controller:

URL Controller method
/items listAction()
/items/add addAction()
/items/create createAction()
/items/edit/{id} editAction($id)
/items/save/{id} saveAction($id)
/items/delete/{id} deleteAction($id)

The controller must provide the public methods shown above and have no required constructor arguments.

Resolving a URL handler from the CLI

Command-line utilities can provide the URL explicitly:

When a route matches, its handler is not called. Instead, the router throws an Exception whose message contains the controller class, method, and captured arguments:

Sitemap generation

The sitemap generator uses configuration provided by websk/php-config:

Controllers that provide sitemap URLs implement InterfaceSitemapController:

The url field is required. When freq is omitted, it defaults to never.

To build the sitemap, set the builder before loading the application's regular route declarations, then call finish():

In sitemap mode, route handlers are not called. Each controller class is processed once, and its URLs are collected through getUrlsForSitemap(). Controllers must be instantiable without constructor arguments.

SitemapBuilder writes up to 2,500 URLs per XML file and creates a sitemap.xml index. Old build directories can be removed with:

This removes sitemap directories older than two days.

Development

This command runs PHP syntax checks and the PHPUnit test suite.

License

MIT. See LICENSE for the full license text.


All versions of php-simple-router with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-xmlwriter Version *
websk/php-utils Version 3.0.*
websk/php-config Version 2.2.*
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 websk/php-simple-router contains the following files

Loading the files please wait ...