Beispiel #1
0
 /**
  * 获取当前请求类型
  *
  * @return string
  */
 private function getRequestType()
 {
     $request_type = 'get';
     if ($this->request->isPostRequest()) {
         $request_type = 'post';
     } elseif ($this->request->isPutRequest()) {
         $request_type = 'put';
     } elseif ($this->request->isDeleteRequest()) {
         $request_type = 'delete';
     }
     return $request_type;
 }
Beispiel #2
0
 /**
  * 按类型解析请求字符串
  *
  * @param string $prefix
  * @param array $url_config
  * @return string
  */
 public function getUriRequest($prefix = '/', &$url_config = array())
 {
     $url_config = $this->config->get('url');
     switch ($url_config['type']) {
         case 1:
         case 3:
             $request = Request::getInstance()->getUriRequest('QUERY_STRING', $url_config['rewrite']);
             break;
         case 2:
         case 4:
         case 5:
             $request = Request::getInstance()->getUriRequest('PATH_INFO', $url_config['rewrite']);
             break;
         default:
             $request = '';
     }
     return $prefix . htmlspecialchars(urldecode(ltrim($request, '/')), ENT_QUOTES);
 }
Beispiel #3
0
 /**
  * 初始化App配置
  * @param string $app_name
  * @param array $runtime_config
  * @return $this
  * @throws \Cross\Exception\FrontException
  */
 private static function initConfig($app_name, array $runtime_config)
 {
     $config = Config::load(APP_PATH_DIR . $app_name . DIRECTORY_SEPARATOR . 'init.php')->parse($runtime_config);
     $request = Request::getInstance();
     $host = $request->getHostInfo();
     $index_name = $request->getIndexName();
     $request_url = $request->getBaseUrl();
     $base_script_path = $request->getScriptFilePath();
     //设置app名称和路径
     $config->set('app', array('name' => $app_name, 'path' => APP_PATH_DIR . $app_name . DIRECTORY_SEPARATOR));
     //静态文件url和绝对路径
     $config->set('static', array('url' => $host . $request_url . '/static/', 'path' => $base_script_path . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR));
     //url相关设置
     $config->set('url', array('index' => $index_name, 'host' => $host, 'request' => $request_url, 'full_request' => $host . $request_url));
     return $config;
 }
Beispiel #4
0
 /**
  * 根据给定的参数解析文件的绝对路径
  * <pre>
  *  格式如下:
  *  1 file_name 直接指定文件路径
  *  2 ::[path/]file_name 从当前项目根目录查找
  *  3 app::[path/]file_name 当前app路径
  *  4 core::[path/]file_name 核心目录
  * </pre>
  *
  * @param $class
  * @param string $append_file_ext
  * @return array
  */
 static function parseFileRealPath($class, $append_file_ext = '.php')
 {
     $files = $list = array();
     $_defines = array('app' => self::$app_path, 'static' => Request::getInstance()->getScriptFilePath() . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR, 'project' => PROJECT_REAL_PATH);
     if (is_array($class)) {
         $files = $class;
     } elseif (false !== strpos($class, ',')) {
         $files = array_map('trim', explode(',', $class));
     } else {
         $files[] = $class;
     }
     foreach ($files as $f) {
         if (false !== strpos($f, '::')) {
             list($path, $file_info) = explode('::', $f);
             if (!$path) {
                 $path = 'project';
             }
             $file_real_path = $_defines[strtolower($path)] . str_replace('/', DIRECTORY_SEPARATOR, $file_info);
             $file_path_info = pathinfo($file_real_path);
             if (!isset($file_path_info['extension'])) {
                 $file_real_path .= $append_file_ext;
             }
             $list[] = $file_real_path;
         } else {
             $list[] = $f;
         }
     }
     return $list;
 }