Ejemplo n.º 1
0
        function ascLogo($txtTableInfo)
        {
            $line_length = array_sum($txtTableInfo) + count($txtTableInfo) + 1;
            $asc_logo_data = <<<ASC_LOGO
                                   __         v%s
  ______________  ______________  / /_  ____
 / ___/ ___/ __ \\/ ___/ ___/ __ \\/ __ \\/ __ \\
/ /__/ /  / /_/ (__  )__  ) /_/ / / / / /_/ /
\\___/_/   \\____/____/____/ .___/_/ /_/ .___/
                        /_/         /_/
ASC_LOGO;
            $logo_lines = explode("\n", sprintf($asc_logo_data, \Cross\Core\Delegate::getVersion()));
            $offset = 6;
            $max_length = 0;
            foreach ($logo_lines as $line) {
                $length = strlen($line);
                if ($length > $max_length) {
                    $max_length = $length;
                }
            }
            $half_length = floor($line_length / 2 - ($max_length - $offset) / 2);
            foreach ($logo_lines as $line) {
                for ($i = 0; $i <= $line_length; $i++) {
                    if ($i == $half_length) {
                        echo $line;
                    } elseif ($i < $half_length) {
                        echo ' ';
                    }
                }
                echo PHP_EOL;
            }
            echo PHP_EOL;
        }
Ejemplo n.º 2
0
 /**
  * 输出结果
  *
  * @param Closure $process_closure
  * @param array $params
  * @throws CoreException
  */
 private function response(Closure $process_closure, $params)
 {
     $need_params = '';
     $closure_params = array();
     $ref = new ReflectionFunction($process_closure);
     $parameters = $ref->getParameters();
     if (count($parameters) > count($params)) {
         foreach ($parameters as $r) {
             if (!isset($params[$r->name])) {
                 $need_params .= sprintf('%s ', $r->name);
             }
         }
         throw new CoreException("所需参数: {$need_params}未指定");
     }
     foreach ($parameters as $p) {
         if (!isset($params[$p->name])) {
             throw new CoreException("不匹配的参数: {$p->name}");
         }
         $closure_params[$p->name] = $params[$p->name];
     }
     $rep = call_user_func_array($process_closure, $closure_params);
     if (null != $rep) {
         $this->delegate->getResponse()->display($rep);
     }
 }
Ejemplo n.º 3
0
 /**
  * 设置Response
  *
  * @param array $config
  */
 private function setResponseConfig(array $config)
 {
     if (isset($config['content_type'])) {
         $this->delegate->getResponse()->setContentType($config['content_type']);
     }
     if (isset($config['status'])) {
         $this->delegate->getResponse()->setResponseStatus($config['status']);
     }
 }
Ejemplo n.º 4
0
 /**
  * request response view
  *
  * @param string $property
  * @return Response|Request|View|Config|null
  */
 function __get($property)
 {
     switch ($property) {
         case 'config':
             return $this->config = $this->delegate->getConfig();
         case 'request':
             return $this->request = Request::getInstance();
         case 'response':
             return $this->response = Response::getInstance();
         case 'view':
             return $this->view = $this->initView();
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * 输出结果
  *
  * @param Closure $process_closure
  * @param array $params
  * @throws CoreException
  */
 private function response(Closure $process_closure, array $params = array())
 {
     $closure_params = array();
     $ref = new ReflectionFunction($process_closure);
     $parameters = $ref->getParameters();
     if (!empty($parameters)) {
         foreach ($parameters as $p) {
             if (!isset($params[$p->name])) {
                 throw new CoreException("未指定的参数: {$p->name}");
             }
             $closure_params[$p->name] = $params[$p->name];
         }
     }
     $content = call_user_func_array($process_closure, $closure_params);
     if (null != $content) {
         $this->delegate->getResponse()->display($content);
     }
 }
Ejemplo n.º 6
0
 /**
  * 调用app指定controller
  *
  * @param $controller
  * @param array $params
  * @return string
  */
 protected function getAppResponse($controller, $params = array())
 {
     return Delegate::loadApp('test')->get($controller, $params, true);
 }
Ejemplo n.º 7
0
 /**
  * 默认控制器
  */
 function index()
 {
     $this->data['version'] = Delegate::getVersion();
     $this->display($this->data);
 }
Ejemplo n.º 8
0
 /**
  * 初始化request
  *
  * @param Delegate $delegate
  */
 private function __construct(Delegate $delegate)
 {
     $this->request = $delegate->getRequest();
     $this->request_type = $this->getRequestType();
     $this->request_string = $delegate->getRouter()->getUriRequest('/');
 }
Ejemplo n.º 9
0
 /**
  * 运行框架
  *
  * @param object|string $router
  * @param null $args 指定参数
  * @param bool $return_response_content 是否输出执行结果
  * @return array|mixed|string
  * @throws CoreException
  */
 public function dispatcher($router, $args = null, $return_response_content = false)
 {
     $init_prams = true;
     $router = $this->parseRouter($router, $args, $init_prams);
     $cr = $this->initController($router['controller'], $router['action']);
     $annotate_config = $this->getAnnotateConfig();
     if ($init_prams) {
         $action_params = array();
         if (isset($annotate_config['params'])) {
             $action_params = $annotate_config['params'];
         }
         $this->initParams($router['params'], $action_params);
     } else {
         $this->setParams($router['params']);
     }
     $this->delegate->getClosureContainer()->run('dispatcher');
     $cache = false;
     if (isset($annotate_config['cache']) && Request::getInstance()->isGetRequest()) {
         $cache = $this->initRequestCache($annotate_config['cache']);
     }
     if (isset($annotate_config['before'])) {
         $this->getClassInstanceByName($annotate_config['before']);
     }
     if (!empty($annotate_config['basicAuth'])) {
         Response::getInstance()->basicAuth($annotate_config['basicAuth']);
     }
     if ($cache && $cache->getExpireTime()) {
         $response_content = $cache->get();
     } else {
         $action = $this->getAction();
         $controller_name = $this->getController();
         try {
             $cr->setStaticPropertyValue('action_annotate', $annotate_config);
             $cr->setStaticPropertyValue('view_controller_namespace', $this->getViewControllerNameSpace($controller_name));
             $cr->setStaticPropertyValue('controller_name', $controller_name);
             $cr->setStaticPropertyValue('call_action', $action);
             $cr->setStaticPropertyValue('url_params', $this->getParams());
             $cr->setStaticPropertyValue('app_delegate', $this->delegate);
             $controller = $cr->newInstance();
         } catch (Exception $e) {
             throw new CoreException($e->getMessage());
         }
         if (Response::getInstance()->isEndFlush()) {
             return true;
         }
         ob_start();
         $response_content = $controller->{$action}();
         if (!$response_content) {
             $response_content = ob_get_contents();
         }
         ob_end_clean();
         if ($cache) {
             $cache->set(null, $response_content);
         }
     }
     if (!empty($annotate_config['response'])) {
         $this->setResponseConfig($annotate_config['response']);
     }
     if ($return_response_content) {
         return $response_content;
     } else {
         Response::getInstance()->display($response_content);
     }
     if (isset($annotate_config['after'])) {
         $this->getClassInstanceByName($annotate_config['after']);
     }
     return true;
 }