Пример #1
0
 static function bootstrap($controller, $method)
 {
     try {
         if ($controller && $method) {
             define('CURRENT_ACTION', substr($controller . ':' . $method, 2));
             if (property_exists($controller, 'static_class')) {
                 if (method_exists($controller, '__before')) {
                     call_user_func($controller . '::__before');
                 }
                 call_user_func(array($controller, $method), explode('/', URL_REQUEST));
                 if (method_exists($controller, '__after')) {
                     call_user_func($controller, '::__after');
                 }
             } else {
                 $object = new $controller();
                 if (method_exists($controller, '__before')) {
                     $object->__before();
                 }
                 call_user_func_array(array($object, $method), array(explode('/', URL_REQUEST)));
                 if (method_exists($controller, '__after')) {
                     $object->__after();
                 }
             }
         } else {
             throw new Exception('absent controller or method', 101);
         }
     } catch (Exception $e) {
         logger::exception('exception', $e->getCode() . ' : ' . $e->getMessage());
         if (preg_match('/^(similar|product)$/', ENVIRONMENT)) {
             if (http::is_ajax()) {
                 http::json(array('error' => 4, 'message' => $e->getMessage(), 'data' => null));
             } else {
                 http::abort($e->getMessage(), '', 10);
             }
         }
         debug::exception($e);
     }
 }