Esempio n. 1
0
 public static function dispatch($route, $method, $matches)
 {
     sgContext::setCurrentRoute($route);
     if (isset($route['disabled']) && $route['disabled'] == true) {
         if (sgConfiguration::get('settings.debug')) {
             exit('<pre>Route "' . $route['name'] . '" is disabled.' . "\n</pre>");
         }
         $obj = new sgBaseController($matches);
         sgContext::getInstance()->setController($obj);
         print $obj->throwErrorCode('404');
     } else {
         $plugins = sgConfiguration::getInstance()->getPlugins();
         foreach ($plugins as $plugin) {
             if (isset($plugin->configuration)) {
                 sgToolkit::executeMethod($plugin->configuration, 'preExecute');
             }
         }
         sgToolkit::executeMethod(sgConfiguration::getInstance(), 'preExecute');
         if (isset($route['class'])) {
             if (class_exists($route['class'])) {
                 $obj = new $route['class']($matches);
                 sgContext::getInstance()->setController($obj);
                 if (method_exists($obj, $method)) {
                     sgToolkit::executeMethod($obj, 'preExecute');
                     print $obj->{$method}();
                     sgToolkit::executeMethod($obj, 'postExecute');
                 } else {
                     throw new BadMethodCallException("Method, {$method}, not supported");
                 }
             } else {
                 throw new Exception('Class, ' . $route['class'] . ', not found');
             }
         } else {
             $obj = new sgBaseController($matches);
             sgContext::getInstance()->setController($obj);
             sgToolkit::executeMethod($obj, 'preExecute');
             print $obj->{$method}();
             sgToolkit::executeMethod($obj, 'postExecute');
         }
         sgToolkit::executeMethod(sgConfiguration::getInstance(), 'postExecute');
         foreach ($plugins as $plugin) {
             if (isset($plugin->configuration)) {
                 sgToolkit::executeMethod($plugin->configuration, 'postExecute');
             }
         }
     }
 }