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'); } } } }
private static function _initPlugins($dir, array $plugins) { foreach ($plugins as $pluginName) { $plugin = new StdClass(); $plugin->name = $pluginName; $plugin->path = "{$dir}/plugins/{$pluginName}"; sgAutoloader::loadPaths(array($plugin->path)); $class = $plugin->name . "Configuration"; if (class_exists($class)) { $configuration = new $class(); sgToolkit::executeMethod($configuration, 'preConfig'); $plugin->configuration = $configuration; } self::loadConfig('settings', "{$plugin->path}/config/config.php", true); self::loadConfig('routing', "{$plugin->path}/config/routing.php", true); if (isset($configuration)) { sgToolkit::executeMethod($configuration, 'postConfig'); } self::$enabledPlugins[$plugin->name] = $plugin; } }
public function render($template = NULL) { $plugins = sgConfiguration::getInstance()->getPlugins(); foreach ($plugins as $plugin) { if (isset($plugin->configuration)) { sgToolkit::executeMethod($plugin->configuration, 'preRender'); } } sgToolkit::executeMethod(sgConfiguration::getInstance(), 'preRender'); sgToolkit::executeMethod($this, 'preRender'); try { if ($template) { $this->loadTemplate($template); } else { if (isset($this->matchedRoute['template'])) { $this->loadTemplate($this->matchedRoute['template']); } else { $this->loadTemplate($this->matchedRoute['name']); } } } catch (Exception $e) { return $this->throwError($e); } // update route cache with appropriate template if (sgConfiguration::get('settings.cache_routes')) { $method = strtoupper($_SERVER['REQUEST_METHOD']); $path = sgContext::getCurrentPath(); sgGlue::$cachedRoutes["{$method} {$path}"]['template'] = str_replace('.html', '', sgView::getInstance()->getView()->getName()); } return sgView::getInstance()->render($this->getTemplateVars()); }