public static function create($url)
 {
     $dispatch = new Dispatch();
     // CHECK FRAMEWORK INTEGRITY
     if (!class_exists($dispatch->getControllerDefault())) {
         // CHECK IF DEFAULT CONTROLLER EXISTS
         throw new Exception('Main controller not found', ERROR_FW_CONTROLLER_NOT_FOUND);
     } else {
         if (!method_exists($dispatch->getControllerDefault(), strtolower(FRAMEWORK_NAME))) {
             // CHECK IF HOME ACTION EXISTS
             throw new Exception('Main action not found', 666);
         } else {
             if (method_exists($dispatch->getControllerDefault(), $dispatch->getActionDefault())) {
                 // CHECK IF CONTROLLER HAS INDEX ACTION
                 throw new Exception('Main controller can not have an index action', 666);
             }
         }
     }
     // CHECK MAIN CONTROLLER RULES
     $mainMethods = array_diff(get_class_methods($dispatch->getControllerDefault()), get_class_methods('library\\kernel\\Controller'), array(strtolower(FRAMEWORK_NAME)));
     // MAIN CONTROLLER CAN NOT HAVE ACTION NAMED LIKE EXISTING CONTROLLER
     foreach ($mainMethods as $mainMethod) {
         if (class_exists(NAMESPACE_CONTROLLERS . ucfirst($mainMethod))) {
             throw new Exception('Main controller can not have an action named <b>' . $mainMethod . '</b> due to already existing controller with same name', 666);
         }
     }
     return $dispatch->build($url);
 }
Exemple #2
0
<?php

namespace library\kernel\core;

use plugin\session\Session;
use library\kernel\core\Dispatcher;
use library\kernel\core\Dispatch;
/*
    if(CSRF_ENABLED === true){
        // CONTROLLARE SE SEI IN POST SE C'E' IL TOKEN
        
        // GENERO UN NUOVO TOKEN A PRESCINDERE
    }
*/
// SESSION OPENING
Session::open();
// CREATE DISPATCHER
$dispatch = Dispatch::create($url);
// FREE $url
unset($url);
// SET DISPATCH SINGLETON
Dispatcher::setDispatch($dispatch);
// LOAD FRAMEWORK BUILDER
Dispatcher::start();