Dependencies.
This commit is contained in:
parent
59b0d2bdc4
commit
a62e594095
22
index.php
22
index.php
|
@ -1,6 +1,10 @@
|
|||
<?php
|
||||
// see app.php for application logic
|
||||
|
||||
if (!file_exists('config.php')) die('APP not configured');
|
||||
|
||||
$config = require 'config.php';
|
||||
|
||||
// AUTOLOADING
|
||||
|
||||
spl_autoload_register(function ($class){
|
||||
|
@ -14,17 +18,23 @@ Debugger::enable(!empty($config['show_debug']) ? Debugger::DEVELOPMENT : Debugge
|
|||
Debugger::$showBar = false;
|
||||
Debugger::$errorTemplate = __DIR__ . '/tpl/500.htm';
|
||||
|
||||
// ROUTES DEFINITION
|
||||
// FRAMEWORK API
|
||||
|
||||
$routeCollector = new FastRoute\RouteCollector(new FastRoute\RouteParser\Std(), new FastRoute\DataGenerator\GroupCountBased());
|
||||
|
||||
|
||||
// user
|
||||
// requireLogin
|
||||
|
||||
$dependencies = [];
|
||||
|
||||
function di($service)
|
||||
{
|
||||
// stub
|
||||
global $dependencies;
|
||||
if (isset($dependencies[$service])) {
|
||||
return $dependencies[$service];
|
||||
} else {
|
||||
throw new Exception('Dependency ' . $service . ' not found!');
|
||||
}
|
||||
}
|
||||
|
||||
function flash($msg)
|
||||
|
@ -70,6 +80,12 @@ function route($method, $url, $callback)
|
|||
$routeCollector->addRoute($method, $url, $callback);
|
||||
}
|
||||
|
||||
// DEPENDECIES
|
||||
$dependencies['config'] = $config;
|
||||
$dependencies['pdo'] = new PDO('sqlite:' . __DIR__ . '/' . $config['database']);
|
||||
$dependencies['rows'] = new severak\database\rows($dependencies['pdo']);
|
||||
|
||||
// ROUTES
|
||||
require 'app.php';
|
||||
|
||||
// finally running the APP
|
||||
|
|
Loading…
Reference in New Issue