Beispiel #1
0
 public function getControllerLang($controller_name)
 {
     if (is_controller_exists($controller_name)) {
         $lng_dir = LANGUAGE_DIR . DIR_SEP . strtolower($controller_name);
         $current_lng_file = wasp_strtolower($this->CURRENT_LANG . '.php');
         $default_lng_file = wasp_strtolower($this->DEFAULT_LANG . '.php');
         if (is_dir($lng_dir) && is_file($lng_dir . DIR_SEP . $default_lng_file)) {
             $strings = (include $lng_dir . DIR_SEP . $default_lng_file);
             if (array_count($strings) > 0) {
                 foreach ($strings as $key => $val) {
                     if (is_varible_name($key) && is_scalar($val)) {
                         $this->strings->{$key} = $val;
                     }
                 }
             }
         }
         if ($this->DEFAULT_LANG != $this->CURRENT_LANG) {
             if (is_dir($lng_dir) && is_file($lng_dir . DIR_SEP . $current_lng_file)) {
                 $strings = (include $lng_dir . DIR_SEP . $current_lng_file);
                 if (array_count($strings) > 0) {
                     foreach ($strings as $key => $val) {
                         if (is_varible_name($key) && is_scalar($val)) {
                             $this->strings->{$key} = $val;
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 public function __construct()
 {
     if (is_file(APP_DIR . DIR_SEP . 'bootstrap.php')) {
         require APP_DIR . DIR_SEP . 'bootstrap.php';
     }
     $router = router();
     $input = input();
     $controller = $router->getControllerName();
     I18n::mySelf();
     if (is_controller_exists($controller)) {
         $className = '\\App\\Controllers\\' . $controller;
         if (class_exists($className) && is_subclass_of($className, '\\Wasp\\Controller')) {
             try {
                 self::$controller = new $className();
             } catch (AppException $e) {
                 wasp_error($e->getMessage(), $e->getFile(), $e->getLine());
             }
         }
     } else {
         show_error_404();
     }
 }
Beispiel #3
0
 /**
  * Show 401 error message
  * 
  */
 function show_error_401()
 {
     if (is_controller_exists('errors')) {
         redirect(['controller' => 'errors', 'method' => 'unauthorized']);
     }
     wasp_error('401 Unauthorized', null, null, 401);
 }
Beispiel #4
0
 public function __construct()
 {
     global $_REQUEST_URI;
     $superfluous = ['.html', '.htm', '.php5', '.php', '.php3', '.shtml', '.phtml', '.dhtml', '.xhtml', '.inc', '.cgi', '.pl', '.xml', '.js'];
     $this->uri = preg_replace("#/+#s", '/', $_REQUEST_URI);
     $this->uri = preg_replace(["#/\$#s", "#^/+#"], '', $this->uri);
     $this->uri = $this->request = str_replace($superfluous, '', $this->uri);
     $this->_load_routes();
     if (array_count(self::$regexps) > 0) {
         foreach (self::$regexps as $key => $val) {
             if (preg_match('#' . $val['regexp'] . '#is', $this->uri)) {
                 $this->uri = preg_replace('#' . $val['regexp'] . '#is', $val['replace'], $this->uri);
                 break;
             }
         }
     }
     if (preg_match("%[^a-z0-9\\/\\-\\.]%isu", $this->uri)) {
         wasp_error("Abnormal request: {$this->uri}", 500);
     }
     class_alias('\\Wasp\\Router', '\\Router');
     if (empty($this->uri)) {
         $this->controller = 'Index';
         $this->method = 'Default';
         $this->action = snake_case($this->controller) . '/' . snake_case($this->method);
         return;
     }
     $do = explode('/', $this->uri);
     $controller = isset($do[0]) ? $do[0] : null;
     $method = isset($do[1]) ? $do[1] : null;
     if (empty($controller) || !is_action_name($controller)) {
         $this->controller = 'Index';
         $this->method = 'Default';
     } else {
         $this->controller = studly_case($controller);
         if (empty($method) || !is_action_name($method)) {
             $this->method = 'Default';
         } else {
             $this->method = studly_case($method);
         }
     }
     $this->action = snake_case($this->controller, '-') . '/' . snake_case($this->method, '-');
     if ($this->controller == 'Coreinfo') {
         if ($this->method == 'Json') {
             $_ = new \stdClass();
             $_->name = CORE_NAME;
             $_->description = FRAMEWORK;
             $_->version = CORE_VERSION;
             $_->status = CORE_VERSION_NAME;
             $_->author = 'Tishchenko Alexander';
             if (!headers_sent()) {
                 header('Cache-Control: no-cache, must-revalidate');
                 header('Expires: ' . date('r', time() - 86400));
                 header(CONTENT_TYPE_JSON);
             }
             exit(json_encode($_));
         } else {
             if (!headers_sent()) {
                 header(CONTENT_TYPE_XML);
             }
             exit("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coreinfo>\n\t<name><![CDATA[" . CORE_NAME . "]]></name>\n\t<description><![CDATA[" . FRAMEWORK . "]]></description>\n\t" . "<version><![CDATA[" . CORE_VERSION . "]]></version>\n" . "\t<status><![CDATA[" . CORE_VERSION_NAME . "]]></status>\n" . "\t<author><![CDATA[Tishchenko Alexander]]></author>\n" . "</coreinfo>");
         }
     } else {
         if ($this->controller == 'Phpinfo' && DEVELOP_MODE) {
             phpinfo();
             exit;
         } else {
             if (!is_controller_exists($this->controller)) {
                 show_error_404();
             }
         }
     }
     array_shift($do);
     array_shift($do);
     $this->_set_get_params($do);
 }
Beispiel #5
0
function display_mvc_wizard()
{
    clear_terminal();
    echo wrap_output(sprintf(__(YZE_METHED_HEADER . "\r\n  \r\n你将生成VC代码结构,请根据提示进操作,%s返回上一步:\r\n1. (1/8)所在功能模块:  "), "生成代码结构", get_colored_text(" 0 ", "red", "white")));
    while (!is_validate_name($module = get_input())) {
        echo get_colored_text(wrap_output(__("\t命名遵守PHP变量命名规则,请重输:  ")), "red");
    }
    echo wrap_output(__("2. (2/8)控制器的名字:  "));
    while (!is_validate_name($controller = get_input())) {
        echo get_colored_text(wrap_output(__("\t命名遵守PHP变量命名规则,请重输:  ")), "red");
    }
    if ($uris = is_controller_exists($controller, $module)) {
        echo wrap_output(__("3. (3/8)控制器已存在,映射URI的是:\n\n"));
        foreach ($uris as $index => $uri) {
            echo "\t " . ($index + 1) . ". {$uri}\n";
        }
        echo wrap_output(__("\n\t选择一个或者输入新的, 回车表示不映射:"));
        $uri = get_input();
        if (is_numeric($uri)) {
            $uri = $uris[$uri - 1];
        }
    } else {
        echo wrap_output(__("3. (3/8)映射URI, 默认URI为/{$module}/{$controller}:  "));
        $uri = get_input();
    }
    echo wrap_output(__("4. (4/8)视图格式(如tpl, xml, json),多个用空格分隔,默认是tpl:  "));
    $view_format = get_input();
    return @array("cmd" => "controller", "controller" => $controller, "uri" => $uri, "module_name" => $module, "view_format" => $view_format ? $view_format : "tpl");
}