Пример #1
0
 /**
  * Running route
  */
 public static function run()
 {
     static $called;
     if (!$called) {
         $next = debug_backtrace();
         $next = next($next);
         if (empty($next['class']) || $next['class'] != __NAMESPACE__ . '\\Controller' || strtolower($next['function']) != 'run') {
             Enproject::Run();
             // instance Call run
         }
         $called = true;
         // start Benchmark
         Benchmark::set('route', 'start');
         static::singleton()->parse();
     }
     return static::singleton();
 }
Пример #2
0
 /**
  * Run the controller
  *
  * @return  void
  */
 public static final function run()
 {
     // being set cached here to prevent being overide
     static::$x_is_request_head = Request::isHead();
     /**
      * doing hook before routes if exists
      * in here hook execution could add route
      * or any what they are doing
      */
     Hook::doAction('x_before_route');
     // doing route
     Route::run();
     // set arguments default
     $args = array('app' => Enproject::singleton(), 'response' => Response::singleton(), 'current_route' => Route::getCurrent());
     // get current route details
     $getCurentRoute = Route::getCurrent();
     $Key = $getCurentRoute['name'];
     $RouteKey = $getCurentRoute['route'];
     // get method
     $method = Route::getMethod();
     // check if method is callable
     if (!is_callable($method)) {
         throw new \Exception("Route method is not exist!", E_USER_ERROR);
     }
     /**
      * Reflection check
      */
     if (is_array($method)) {
         $Reflection = new ReflectionMethod($method[0], $method[1]);
     } else {
         $Reflection = new ReflectionFunction($method);
     }
     /**
      * Split and fix method callback with array each of method for right way property uses
      */
     foreach ($Reflection->getParameters() as $key => $value) {
         $name = $value->getName();
         if (Route::getDefaultValue($Key, $RouteKey, $name, null) !== null) {
             $args[$name] = Route::getDefaultValue($Key, $RouteKey, $name);
             continue;
         }
         $pos = $value->getPosition();
         if (Route::getDefaultValue($Key, $RouteKey, $pos, null) !== null) {
             $args[$name] = Route::getDefaultValue($Key, $RouteKey, $pos);
             continue;
         }
         if ($pos < 3) {
             continue;
         }
         $custName = array_key_exists($name, $args) ? $name . $key : $name;
         if ($value->canBePassedByValue()) {
             if ($value->isOptional() && $value->isDefaultValueAvailable()) {
                 $args[$custName] = $value->isDefaultValueConstant() ? constant($value->getDefaultValueConstantName()) : $value->getDefaultValue();
             } elseif ($value->allowsNull()) {
                 $args[$custName] = null;
             } elseif ($value->isArray()) {
                 /* if array arguments */
                 $args[$custName] = array();
             } elseif ($value->isCallable()) {
                 /* if callable arguments */
                 $args[$custName] = function () {
                 };
                 // closure is callable
             } else {
                 throw new \Exception(sprintf("Parameter \$%s on Route must be can passed by value!", $value->getName()), E_USER_ERROR);
             }
         } else {
             throw new \Exception(sprintf("Parameter \$%s on Route must be can passed by value!", $value->getName()), E_USER_ERROR);
         }
     }
     // determine args as references
     $args =& $args;
     Benchmark::set('app', 'end');
     /**
      * intitalize template if possible
      * This must be called before calling Method
      */
     Template::init();
     // start buffer if not exists
     ob_get_level() || ob_start();
     // call the method
     call_user_func_array($method, $args);
     // call hook after routes
     Hook::doAction('x_after_route');
     // freed the memory
     unset($args, $Reflection, $name, $method);
     /**
      * Dont show display if Fatal Error
      * because fatal has call static::displayRender() it self
      */
     if (!static::$x_is_fatal && !Route::isFatalError()) {
         // init display
         static::displayRender();
     }
 }
Пример #3
0
 /**
  * Get application instantly
  * @param  string $appname  the application key name
  * @param  object $object   Object application
  * @return object           Enproject instance
  */
 public static function set($appname, $object)
 {
     return Enproject::set("\\Http\\{$appname}", $object);
 }
Пример #4
0
 /**
  * Get application instantly
  *
  * @param  string $appname  the application key name
  * @param  object $object   Object application
  * @return object           Enproject instance
  */
 public static function set($appname, $object)
 {
     return Enproject::set("\\Cryptography\\{$appname}", $object);
 }