Example #1
0
 public static function instance($className, $args = array())
 {
     global $root;
     settype($className, 'string');
     settype($args, 'array');
     $fileName = str_replace('_', DIRECTORY_SEPARATOR, $className);
     if (!is_readable("{$root}/bin/{$fileName}.php")) {
         return false;
     }
     include_once "{$root}/bin/{$fileName}.php";
     if (!class_exists($className, false)) {
         return false;
     }
     $reflection = new ReflectionClass($className);
     if ($reflection->getParentClass()->getName() != 'WebBase') {
         return false;
     }
     if (null === self::$match) {
         self::$match = $className;
     }
     $controller = call_user_func(array(&$reflection, 'newInstance'), $args);
     if ($controller->type && !empty($controller->type) && Response::canSendHeaders()) {
         Response::setHeader('Content-Type', $controller->type, true);
     }
     if (Request::isPost() && method_exists($controller, 'submit')) {
         $controller->submit();
     }
     if (Response::canSendHeaders()) {
         Response::sendResponse();
     }
     if (method_exists($controller, 'dispatch')) {
         $controller->dispatch();
     }
     return true;
 }