Beispiel #1
0
function autoloadlitpi($classname)
{
    $filepathFromMapping = classmap($classname);
    $sitepath = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    if ($filepathFromMapping == '') {
        //Process Namespace Directoryseparator
        $namepart = explode('\\', $classname);
        //If we not found some default root namespace
        //Make VENDOR is default namespace
        if (!in_array(strtolower($namepart[0]), array('model', 'controller', 'vendor'))) {
            array_unshift($namepart, 'Vendor');
        }
        $filepath = $sitepath;
        for ($i = 0; $i < count($namepart); $i++) {
            $filepath .= trim($namepart[$i]);
            if ($i == count($namepart) - 1) {
                $filepath .= '.php';
            } else {
                $filepath .= DIRECTORY_SEPARATOR;
            }
        }
    } else {
        $filepath = $sitepath . $filepathFromMapping;
    }
    if (is_readable($filepath)) {
        include_once $filepath;
        return true;
    } else {
        return false;
    }
}
Beispiel #2
0
$registry->set('conf', $conf);
$db = new MyPdoProxy();
$db->addMaster($conf['db']['host'], $conf['db']['user'], $conf['db']['pass'], $conf['db']['name']);
$db->addSlave($conf['db']['host'], $conf['db']['user'], $conf['db']['pass'], $conf['db']['name']);
$registry->set('db', $db);
/////////////////////////
///// Important, process to include controller file
///This is the main different with LITPI framework core
//Parsing route information to include module/controller
$route = isset($_GET['route']) ? trim($_GET['route'], '/\\') : '';
$parts = explode('/', $route);
for ($i = 0; $i < count($parts); $i++) {
    $parts[$i] = htmlspecialchars($parts[$i]);
}
$module = array_shift($parts);
$controller = array_shift($parts);
$registry->set('module', $module);
$registry->set('controller', $controller);
$class = '\\controller\\' . $module . '\\' . $controller;
//Init slim object
$app = new \Slim\Slim();
//check if valid controller
if (classmap($class) != '') {
    $myControllerObj = new $class($registry, $app);
    $myControllerObj->run();
} else {
    $app->notFound(function () use($app) {
        echo file_get_contents('404.html');
    });
}
$app->run();