Пример #1
0
 public static function build($config)
 {
     //Début session
     @session_start();
     //security
     FoxFWKernel::security();
     //Chargement de la configuration
     $GLOBALS['Config'] = $config;
     //verifier la syntaxe JSON
     if ($GLOBALS['Config'] == NULL) {
         die($config_url . ': syntaxe error !');
     }
     //activier ou pas les erreurs PHP
     if (!$GLOBALS['Config']['FoxFW']['php_error']) {
         error_reporting(0);
     }
     //-------------------------------------------------------------
     //Default constante
     foreach ($GLOBALS['Config']['Define'] as $key => $value) {
         define($key, $value);
     }
     //Dépendences
     foreach ($GLOBALS['Config']['Require'] as $key => $value) {
         FoxFWKernel::addVendor($value);
     }
     //model
     foreach ($GLOBALS['Config']['Model'] as $key => $value) {
         FoxFWKernel::addBundleFile($value);
     }
     //Route
     if (!isset($GLOBALS['Config']['Route'])) {
         exit('No route defined !');
     }
     $GLOBALS['Route'] = FoxFWKernel::ObjJsonFileBuild($GLOBALS['Config']['Route'], 'route.json');
     if ($GLOBALS['Route'] == NULL) {
         die('Route syntaxe error !');
     }
     //-------------------------------------------------------------
     //Configuration RedBean ORM
     $co = $GLOBALS['Config']['RedBean'];
     R::setup($co['connect'], $co['user'], $co['pass']);
     //-------------------------------------------------------------
     //Chargement User
     $GLOBALS['User'] = new FoxFWUsers();
     //-------------------------------------------------------------
     //création de la table de routage
     $GLOBALS['Router'] = new AltoRouter();
     $GLOBALS['Router']->setBasePath($GLOBALS['Config']['AltoRouter']['BasePath'] . '/');
     //Chargement des routes dans AltoRouter
     foreach ($GLOBALS['Route'] as $key => $value) {
         $GLOBALS['Router']->map($value->method, $value->path, $value->controller, $key);
     }
     //-------------------------------------------------------------
     //Configuration de twig
     $cache = false;
     if ($GLOBALS['Config']['FoxFW']['cache']) {
         $cache = _CACHE;
     }
     Twig_Autoloader::register();
     $loader = new \Twig_Loader_Filesystem('./');
     $GLOBALS['Twig'] = new \Twig_Environment($loader, array('cache' => $cache));
     //twig extension function User !
     $GLOBALS['Twig']->addGlobal('User', $GLOBALS['User']);
     //-------------------------------------------------------------
     //security formulaire
     FoxFWKernel::securityFormSend();
     //-------------------------------------------------------------
     //extension du Kernel !
     if (isset($GLOBALS['Config']['Addon'])) {
         foreach ($GLOBALS['Config']['Addon'] as $key => $value) {
             if (file_exists($value)) {
                 require_once $value;
             }
         }
     }
     //-------------------------------------------------------------
     //traitement de la page
     $etat = 404;
     $match = $GLOBALS['Router']->match();
     //recuperer la page charger
     //controller principal
     if ($match) {
         if ($GLOBALS['User']->isRole($GLOBALS['Route'][$match['name']]->firewall)) {
             $etat = FoxFWKernel::controller($match['target'], $match['params']);
             //si pas d'erreur
             if ($etat == 200) {
                 return true;
             }
         } else {
             $etat = 401;
         }
     }
     //Erreur controller
     $error = $GLOBALS['Config']['FoxFW']['controller_error'] . '#e' . $etat;
     if (FoxFWKernel::controller($error, array()) == 200) {
         return true;
     }
     //Default error serveur
     header('HTTP/1.0 500 Not Found');
     echo 'Erreur interne du serveur !';
     return false;
 }