sinevia/php-library-fastest

v3.2.0 2019-01-14 22:48 UTC

This package is auto-updated.

Last update: 2022-05-15 05:39:02 UTC


README

Fastest router

How it works

Simple and unassuming router.

  1. The router checks for an action parameter in the URL. If not found assumes "home".
index.php?a=home (this is default)
index.php?a=register

  1. Executes a PHP function for the requested action.

  2. The action function has the same name as the requested action with the "_action" postfix.

(action: home => function: home_action)
(action: register => function: register_action)
  1. Dashes, spaces, and forward slashes are replaced with underscores
(action: auth/login => function: auth_login_action)
(action: auth-login => function: auth_login_action)

Installation

  1. Using composer (recommended)
composer require sinevia/php-library-fastest
  1. Manually. Copy the fastest.php file and use the include_once function to include

Usage

  1. Add the following line to where the router will be working. It can be the main router of the app, or a standalone PHP webpage.
// Add the actions
require_once('../actions/home_action.php');
require_once('../actions/login_action.php');

// Execute the router
\Sinevia::fastest();
  • Optionally the action can be set manually, for instance to have nice URLs
// Manually set the action and execute
$uri = strtok($_SERVER["REQUEST_URI"],'?');
$result = \Sinevia::fastest(['action' => $uri]);
  • Optionally the result can be output as string to be processed manually further
// Get the result as string and output
$result = \Sinevia::fastest(['output_as_string' => true]);
die($result);
  1. Example functions
/**
 * The home function
 * route: ?a= or /
 */
function home_action {
    return 'Home';
}

/**
 * The login function
 * route: ?a=login or /login
 */
function login_action {
    return 'Login';
}