/** * @param string|object $object * @return multitype: */ public static function getControllerResources($controller) { $front = JO_Front::getInstance(); $controller_name = $front->formatControllerName($controller); if ($front->isDispatchable($controller)) { JO_Loader::setIncludePaths(array($front->getDispatchDirectory())); JO_Loader::loadFile($front->classToFilename($controller_name), null, true); if (version_compare(PHP_VERSION, '5.2.6') === -1) { $class = new ReflectionObject(new $controller_name()); $classMethods = $class->getMethods(); $methodNames = array(); foreach ($classMethods as $method) { $methodNames[] = $method->getName(); } } else { $methodNames = get_class_methods(new $controller_name()); } $_classResources = array(); foreach ($methodNames as $method) { if (6 < strlen($method) && 'Action' === substr($method, -6)) { $_classResources[substr($method, 0, -6)] = substr($method, 0, -6); } } return $_classResources; } return array(); }
public function dispatch($controller = null, $action = null, $params = array()) { $this->setHelpersPath(); $controller = $controller ? $controller : $this->getRequest()->getController(); $response = JO_Response::getInstance(); if (!$this->isDispatchable($controller) && $this->isDispatchable('error')) { $controller = 'error'; $action = 'error404'; } if ($this->isDispatchable($controller)) { JO_Loader::setIncludePaths(array($this->getDispatchDirectory())); $className = $this->formatControllerName($controller); JO_Loader::loadFile($this->classToFilename($className), null, true); $controller_instance = new $className($this->getRequest()); if (!$controller_instance instanceof JO_Action) { require_once 'JO/Exception.php'; throw new JO_Exception('Controller "' . $className . '" is not an instance of JO_Action'); } $action = $action ? $action : $this->getRequest()->getAction(); // by default, buffer output $disableOb = $this->getParam('disableOutputBuffering'); $obLevel = ob_get_level(); if (empty($disableOb)) { ob_start(); } try { $controller_instance->dispatch($controller, $action, $params); } catch (Exception $e) { // Clean output buffer on error $curObLevel = ob_get_level(); if ($curObLevel > $obLevel) { do { ob_get_clean(); $curObLevel = ob_get_level(); } while ($curObLevel > $obLevel); } throw $e; } if (empty($disableOb)) { $content = ob_get_clean(); $response->appendBody($content); } // Destroy the page controller instance and reflection objects $controller_instance = null; } else { $controller_instance = new JO_Action(); $controller_instance->dispatch($controller, 'error404'); // Destroy the page controller instance and reflection objects $controller_instance = null; // require_once 'JO/Exception.php'; // throw new JO_Exception( // 'Controller "' . $controller . '" is not found' // ); } }