Example #1
0
/* Main framework class */
class Framework
{
    private $path = '';
    function load($path, $object = null, $alias = null, $i = 0)
    {
        /* Generic loader, attempts to load file by path and return usable object.
         * @param $path: path/to/object
         * @param $object: name of object (default = filename)
         * @param $alias: property that the object will be mapped to (default = object name = filename)
         * @param $i: iterator !!DO NOT PASS THIS PARAM!! */
        $this->parts = array_filter(explode('/', $path));
        if (isset($this->parts[$i]) && is_dir($this->parts[$i])) {
            $this->path .= "{$this->parts[$i]}/";
            $this->load($path, $object, $alias, $i += 1);
        } else {
            if (file_exists("{$this->path}/{$this->parts[$i]}.php")) {
                $name = "{$this->path}/{$this->parts[$i]}.php";
                include $name;
                $obj_name = !empty($object) ? $object : $this->parts[$i];
                $obj = new $obj_name();
                $prop_name = !empty($alias) ? $alias : $obj_name;
                $this->{$prop_name} = $obj;
            }
        }
    }
}
$controller = new Controller();
$request['url'] = substr($_SERVER['REQUEST_URI'], strlen("/{$site['name']}/"));
$route = $controller->create_route($request['url']);