예제 #1
0
 public function __construct()
 {
     self::$instance =& $this;
     // 每个Controller持有一个单独的CoreLoader实例
     $this->load = CoreHelper::loadClass("CoreLoader", '', null, false);
     CoreHelper::logMessage('info', 'Controller Class Initialized');
 }
예제 #2
0
파일: CoreTask.php 프로젝트: ErosZy/CSF
 public function onTask(swoole_server $serv, $taskId, $fromId, $data)
 {
     if (isset($data["controller"])) {
         $controller = $data["controller"];
         $method = $data["method"];
         $data = $data["data"];
         $instance = CoreHelper::loadClass($controller, "controllers/tasks");
         if (method_exists($instance, $method)) {
             $instance->{$method}($serv, $taskId, $fromId, $data);
         }
     }
 }
예제 #3
0
파일: CoreAction.php 프로젝트: ErosZy/CSF
 public function pub()
 {
     if (count($this->_targets) > 0) {
         $maps = $this->_targets;
         foreach ($maps as $key => $val) {
             $instance = CoreHelper::loadClass($key, "controllers");
             if (method_exists($instance, 'process')) {
                 $instance->process($val);
             }
         }
     }
 }
예제 #4
0
파일: CoreWorker.php 프로젝트: ErosZy/CSF
 protected function _process($data)
 {
     $analysises = $this->_analysisRoutes;
     foreach ($analysises as $key => $val) {
         $instance = CoreHelper::loadClass($val, "analysises");
         if ($instance instanceof CoreAnalysis && method_exists($instance, "process")) {
             $stop = false;
             $data = $instance->process($data, $stop);
             if ($stop) {
                 return $data;
             }
         }
     }
     return $data;
 }
예제 #5
0
파일: CoreLoader.php 프로젝트: ErosZy/CSF
 public function model($model, $name = '')
 {
     if (empty($model)) {
         return $this;
     } elseif (is_array($model)) {
         foreach ($model as $key => $value) {
             is_int($key) ? $this->model($value, '') : $this->model($key, $value);
         }
         return $this;
     }
     $path = '';
     if (($lastSlash = strrpos($model, '/')) !== false) {
         $path = substr($model, 0, ++$lastSlash);
         $model = substr($model, $lastSlash);
     }
     if (empty($name)) {
         $name = $model;
     }
     if (in_array($name, $this->_models, true)) {
         return $this;
     }
     $CN =& getInstance();
     if (isset($CN->{$name})) {
         throw new RuntimeException('The model name you are loading is the name of a resource that is already being used: ' . $name);
     }
     if (!class_exists('CoreModel', false)) {
         CoreHelper::loadClass('CoreModel');
     }
     $model = ucfirst($model);
     if (!class_exists($model)) {
         $modelPath = APPPATH . "models/" . $path . $model . ".php";
         if (file_exists($modelPath)) {
             require_once $modelPath;
             if (!class_exists($model, false)) {
                 throw new RuntimeException($modelPath . " exists, but doesn't declare class " . $model);
             } else {
                 if (!class_exists($model, false)) {
                     throw new RuntimeException('Unable to locate the model you have specified: ' . $model);
                 }
             }
         }
     } elseif (!is_subclass_of($model, 'CoreModel')) {
         throw new RuntimeException("Class " . $model . " already exists and doesn't extend CI_Model");
     }
     $this->_models[] = $name;
     $CN->{$name} = new $model();
     return $this;
 }
예제 #6
0
파일: CoreRouter.php 프로젝트: ErosZy/CSF
 public function route(array $params)
 {
     if (empty($params["router"])) {
         return;
     }
     $maps = self::$_routeMap;
     foreach ($maps as $key => $val) {
         if ($key == $params["router"]) {
             $val = str_replace('.php', '', trim($val, '/'));
             if (($lastSlash = strrpos($val, '/')) !== FALSE) {
                 $subdir = substr($val, 0, ++$lastSlash);
                 $router = substr($val, $lastSlash);
             } else {
                 $subdir = "";
                 $router = $val;
             }
             $instance = CoreHelper::loadClass($router, "actions/" . $subdir);
             if ($instance instanceof CoreAction && method_exists($instance, 'distribute')) {
                 $instance->distribute($params);
             }
             break;
         }
     }
 }
예제 #7
0
파일: CoreError.php 프로젝트: ErosZy/CSF
 function exceptionHandler($exception)
 {
     $error = CoreHelper::loadClass('CoreException');
     $error->logException('error', 'Exception: ' . $exception->getMessage(), $exception->getFile(), $exception->getLine());
 }
예제 #8
0
파일: CoreServer.php 프로젝트: ErosZy/CSF
 private static function createProcessSender(array $routes)
 {
     $workerNum = count($routes);
     $serv = self::$_serv;
     for ($i = 0; $i < $workerNum; $i++) {
         $class = $routes[$i];
         $process = new swoole_process(function () use($class, $serv) {
             require_once BASEPATH . 'CoreEnvSetting.php';
             $instance = CoreHelper::loadClass($class, "controllers/processes");
             $instance->process($serv);
         });
         $serv->addProcess($process);
     }
 }