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

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

Simple PHP Router ⇄

Hey! This is a simple and small single class PHP router that can handle the whole URL routing for your project. It utilizes RegExp and PHP's anonymous functions to create a lightweight and fast routing system. The router supports dynamic path parameters, special 404 and 405 routes as well as verification of request methods like GET, POST, PUT, DELETE, etc. The codebase is very small and very easy to understand. So you can use it as a boilerplate for a more complex router.

Take a look at the index.php file. As you can see the Route::add() method is used to add new routes to your project. The first argument takes the path segment. You can also use RegExp in there to parse out variables. All matching variables will be pushed to the handler method defined in the second argument. The third argument will match the request method. The default method is 'get'.

📋 Simple example:

You will find a more complex example with a build in navigation in the index.php file.

🎶 Installation using Composer

Just run composer require steampixel/simple-php-router Than add the autoloader to your project like this:

⛺ Use a different basepath

If your script lives in a subfolder (e.g. /api/v1) set this basepath in your run method:

Do not forget to edit the basepath in .htaccess too if you are on Apache2.

⏎ Use return instead of echo

You don't have to use echo to output your content. You can also use the return statement. Everything that gets returned is echoed automatically.

⇒ Use arrow functions

Since PHP 7.4 you can also use arrow functions to output your content. So you can easily use variables from outside and you can write shorter code. Please be aware that an Arrow function must always return a value. Therefore you cannot use echo directly in here. You can find an example in index.php. However, this is deactivated, as it only works from PHP 7.4.

📖 Return all known routes

This is useful, for example, to automatically generate test routes or help pages.

On top of that you could use a library like https://github.com/hoaproject/Regex to generate working example links for the different expressions.

🧰 Enable case sensitive routes, trailing slashes and multi match mode

The second, third and fourth parameters of Route::run('/', false, false, false); are set to false by default. Using this parameters you can switch on and off several options:

⁉ Something does not work?

🚀 Pages, Templates, Themes, Components

This is a simple router. So there is no templating at all. But it works perfectly together with simplePHPComponents and simplePHPPortals. There is a complete boilerplate project including these dependencies and this router called simplePHPPages. You can use it for you next project.

🎓 What skills do you need?

Please be aware that for this router you need a basic understanding of PHP. Many problems stem from people lacking basic programming knowledge. You should therefore have the following skills:

Please note that we are happy to help you if you have problems with this router. Unfortunately, we don't have a lot of time, so we can't help you learn PHP basics.

🚢 Test setup with Docker

I have created a little Docker test setup.

  1. Build the image: docker build -t simplephprouter docker/image-php-7.2

  2. Spin up a container

    • On Linux / Mac or Windows Powershell use: docker run -d -p 80:80 -v $(pwd):/var/www/html --name simplephprouter simplephprouter
    • On Windows CMD use docker run -d -p 80:80 -v %cd%:/var/www/html --name simplephprouter simplephprouter
  3. Open your browser and navigate to http://localhost

🪟 Test Setup in Windows using IIS

With IIS now fully supporting PHP, this example can be run using the included web.config. The web.config has a rewrite rule, similar to the .htaccess rewrite rule, but specifically for IIS. The rewrite rule will send all incoming requests to index.php in your root. The rest is done by the simple php router.

Setup

This setup tutorial assumes you have the knowledge to create sites in IIS and set up bindings for http/https and custom DNS. If you need more information, this article will help you with that part.

  1. If you haven't done so yet, install php on windows. This article Install IIS and PHP | Microsoft Docs will guide you to install the required php dependencies on your windows machine.
  2. In IIS Manager, create a site and point the physical location to root of the simplePHPRouter folder. It is recommended you connect to the the physical location with an account that has "Read/Write" rights to that folder.
  3. (Optional) Create a DNS entry in your hosts file pointing 127.0.0.1 to the domain name you have used to set up the site.
  4. Browse to the newly created website and the sample site should display now.

✅ Todo

📃 License

This project is licensed under the MIT License. See LICENSE for further information.


All versions of simple-php-router with dependencies

PHP Build Version
Package Version
No informations.
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 steampixel/simple-php-router contains the following files

Loading the files please wait ....