예제 #1
0
 public function executePluginListEnabled($arguments, $options)
 {
     $plugins = sgConfiguration::getInstance()->getPlugins();
     foreach ($plugins as $plugin) {
         sgCLI::println($plugin->name, sgCLI::STYLE_INFO);
     }
 }
예제 #2
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');
             }
         }
     }
 }
 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());
 }