Overview

Namespaces

  • Sleepy
  • Module
    • Authentication
    • CSV
    • DB
    • FormBuilder
    • FSDB
    • IP2Country
    • Mailer
    • MobiDetect
    • Navigation
    • StaticCache
  • PHP

Classes

  • Debug
  • Hook
  • Router
  • SM
  • Template

Exceptions

  • RouteNotFound
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Class Router

Implements routing functionality based on a URI.

Usage

\Sleepy\Router::route('/user/{{ id }}/*', function ($route) {
      echo "The route uses the pattern: ", $route->pattern;
      echo "Route was matched using method: ", $route->method;
      echo "The wildcard matched: ", $route->splat;
      echo "Showing user ", $route->params['id'], "</br>";
  });

Changelog

Version 1.1

  • updated private prefix (_) for consistency
  • updated documentation

Version 1.0

  • With unit tests in place, we're ready to call this 1.0

Version 0.4

  • Simplified interface, thanks @cameff
Namespace: Sleepy
License: http://opensource.org/licenses/MIT
Author: Jaime A. Rodriguez hi.i.am.jaime@gmail.com
Version: 1.1
Todo: Document the class and add it to homepage
Date: July 18, 2016
Located at class.router.php
Methods summary
public static array
# getArray( string $string )

Gets an array from a string based on Router::$delimeter

Gets an array from a string based on Router::$delimeter

Parameters

$string
a string to explode()

Returns

array
an exploded string
public static object
# route( string $pattern, function $func )

Creates a new route

Creates a new route

Parameters

$pattern
A pattern to match
$func
A callback function

Returns

object
\Sleepy\Route()
public static object
# mvc( string $pattern, function $defaults = array() )

Creates a new route, uses a controller and view

Creates a new route, uses a controller and view

Parameters

$pattern
A pattern to match
$defaults
$func A callback function

Returns

object
\Sleepy\Route()
public static object
# redirect( string $controller, function $action = 'index', $params = '' )

Creates a new route

Creates a new route

Parameters

$controller
$pattern A pattern to match
$action
$func A callback function
$params

Returns

object
\Sleepy\Route()
public static boolean
# start( $currentPath = '' )

Starts parsing the Router::routes

Starts parsing the Router::routes

Returns

boolean
true if a route was matched
public static
# reset( )
Properties summary
private static array $_routes

An array of routes

An array of routes

Private

# array()
public static boolean $routeFound

Has a route been matched?

Has a route been matched?

# false
public static string $delimiter

The delimiter for the route pattern

The delimiter for the route pattern

# '/'
public static boolean $querystring

If true, parse the querystring instead of the path

If true, parse the querystring instead of the path

# false
public static array $parameters

An array of parameters, either from the path or querystring

An array of parameters, either from the path or querystring

# array()
sleepyMUSTACHE v.0.8 API documentation generated by ApiGen