Download the PHP package trulyao/php-router without Composer

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

PHP Router

PHP-Router is a modern, fast, and adaptable composer package that provides express-style routing in PHP without a framework.

This website is powered by this package -> View site

Installation

Create a new dockerized PHP project (contains MySQL, Apache2, PHPMyAdmin) that uses this package by running this Composer command:

Update .htaccess file

This is very important to get the router working correctly.

Warning: Depending on your Apache configuration, some headers will not be allowed to come through to your application, this has nothing to do with this package, you just need to enable them in your Apache configuration.

Features

Usage

index.php

/views - The directory where your views/controllers/source files are located.

/demo - This is the base URL for your application eg. api for /api/* or v1 for /v1/*.

The $req object

The $req object contains the request data, it also has helper methods for accessing this data.

Note: The $req object is passed to all middleware and callback functions. If you use any of the response methods like send(), the middleware will not move on to the next one.

The $res object

The $res object is used to control the response and holds data related to responses and just like the request object, it has methods you can use.

More methods will also be added in the future.

You can access these any functions outside your index or main file too by using the namespace Trulyao\PhpRouter\HTTP. Also, you are not constrained to any particular coding style or variable naming convention either.

Error Pages

You can easily add a custom 404, 405 or 500 page by creating a file in the /views directory (or wherever your base path is; where your controllers or views are) called 404.php, 405.php or 500.php

Views & Templates

In views, you are provided with the following variables by default:

Note: headers are made case-insensitive while accessing them in views. This package also comes with a templating engine that is turned off by default, you can enable or disable it by passing a boolean value to the render method. This templating engine is still experimental and does not support a lot of features yet. Check this file for an example of how to use it.

You can use any of these variables in a PHP view file by using $query[\'field_name'], $data[\'field_name'] etc or in a template file (most likely html) by using the directives like @query('field_name'), @body().

Components and Raw Code

You can execute some PHP codes in views by using the @php ... @endphp directives. This is quite limited and useful for codes that don't echo anything like the session_start() function as all the output is at the top of the view file.

You can also use the @component directive to include a component file.

For more examples, check out the examples directory. If you have forked and/or cloned this repo; to start the test server, run composer run start:dev, the base URL is http://localhost:20000/demo. Here are all the available endpoints:

Contribute

This documentation will be updated as soon as new features and methods are added to the package.

Warning: PHP, like a lot of other languages, runs from top to bottom, to avoid conflicts, put your chained routes at the bottom of the file; it is still fairly unstable and may override your dynamic routes eg. putting /chained which is a chained route before /:id for a GET request will only direct you to the /chained route because it technically matches the latter. Using a URL like http://domain.com/work#web will NOT return anything after the # symbol, this is a not an issue with this package or PHP, this data is never sent to the server by the browser. See a discussion here


All versions of php-router with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
php Version >=7.4
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 trulyao/php-router contains the following files

Loading the files please wait ....