/** * Load the controller and run the method * * @static * @return object instance of controller */ public static final function &instance() { if (self::$insta === NULL) { // Include the Controller file require self::$controller; // Make sure the controller class exists try { // Start validation of the controller $class = new ReflectionClass(ucfirst(str_replace('-', '_', X4Route_core::$control) . '_controller')); } catch (ReflectionException $e) { // Controller does not exist $class = new ReflectionClass('X4Page_controller'); } // Create a new controller instance $controller = $class->newInstance(); // caching // only if area is public and _POST is empty if (CACHE && X4Route_core::$folder == 'public' && !X4Route_core::$post) { X4Cache_core::setPrefix(COOKIE); X4Cache_core::setStore(APATH . 'files/tmp/'); // if no cache to read if (!X4Cache_core::Start($_SERVER['REQUEST_URI'], CACHE_TIME)) { self::$caching = true; } else { self::$inst = false; if (DEBUG) { echo X4Bench_core::info('<span>X4WebApp v. {x4wa_version} - execution time: {execution_time} - memory usage: {memory_usage} - queries: {queries} - included files: {included_files}</span>'); } } } if (self::$inst) { try { // Load the controller method $method = $class->getMethod(str_replace('-', '_', X4Route_core::$method)); if ($method->isProtected() or $method->isPrivate()) { // Do not attempt to invoke protected methods throw new ReflectionException('protected controller method'); } // Default arguments $arguments = X4Route_core::$args; } catch (ReflectionException $e) { // Use __call instead $method = $class->getMethod('__call'); // Use arguments in __call format $arguments = array(X4Route_core::$method, X4Route_core::$args); } // Execute the controller method $method->invokeArgs($controller, $arguments); } } return self::$insta; }