router::call PHP Method

call() public method

public call ( $callback )
    function call($callback)
    {
        if (is_callable($callback)) {
            call_user_func($callback, self::$params);
        } else {
            $parts = explode(c::get('router.delimiter'), $callback);
            $class = $parts[0];
            $method = isset($parts[1]) ? $parts[1] : null;
            if (class_exists($class)) {
                $controller = new $class();
                if ($method && method_exists($controller, $method)) {
                    $controller->{$method}(self::$params);
                } else {
                    throw new BadMethodCallException('Method, ' . $method . ', not supported.');
                }
            } else {
                throw new Exception('Class, ' . $class . ', not found.');
            }
        }
    }

Usage Example

Example #1
0
File: index.php Project: Minasu/wd
<?php

define('ROOTPATH', __DIR__);
require ROOTPATH . "/../lib/base/router.php";
$Router = new router();
$Router->call();