<?php
/**
 * @Statement: [ An Ordinary Person ]
 * @Author: 闻子 < QQ：270988107 >
 * @Copyright: 闻子 2016-2019 All rights reserved.
 *
 *    .--,       .--,
 *   ( (  \.---./  ) )
 *    '.__/o   o\__.'
 *       {=  ^  =}
 *        >  -  <
 *       /       \
 *      //       \\
 *     //|   .   |\\
 *     "'\       /'"_.-~^`'-.
 *        \  _  /--'         `
 *      ___)( )(___
 *     (((__) (__)))    高山仰止,景行行止.虽不能至,心向往之.
 *
 */

namespace app\common\controller;

use think\Controller;

class Base extends Controller
{

    /**
     * 初始化定义信息
     * @author 闻子 <270988107@qq.com>
     */
	public function initialize()
	{
		$this->initParamInfo();
	}

    /**
     * 定义常量信息
     * @author 闻子 <270988107@qq.com>
     */
    final private function initParamInfo()
    {
        defined('IS_GET')           or define('IS_GET',          $this->request->isGet());
        defined('IS_POST')          or define('IS_POST',         $this->request->isPost());
        defined('MODULE_NAME')      or define('MODULE_NAME',     $this->request->module());
        defined('CONTROLLER_NAME')  or define('CONTROLLER_NAME', $this->request->controller());
        defined('ACTION_NAME')      or define('ACTION_NAME',     $this->request->action());
        defined('URL')              or define('URL',             strtolower($this->request->controller() . '/' . $this->request->action()));
        defined('URL_MODULE')       or define('URL_MODULE',      strtolower($this->request->module()) . '/' . URL);
        defined('CLIENT_IP')        or define('CLIENT_IP',      $this->request->ip());
        defined('PARAM')            or define('PARAM',      $this->request->param());
    }

    /**
     * 测试继承传递数据返回信息
     * 只作为测试，请勿轻易使用
     * @author 闻子 <270988107@qq.com>
     */    
    final protected function jump($jump_type = null, $message = null, $url = null,$data = null)
    {
        if (is_array($jump_type)):
        switch (count($jump_type))
        {
            case 2  : list($jump_type, $message)       = $jump_type; break;
            case 3  : list($jump_type, $message, $url) = $jump_type; break;
            case 4  : list($jump_type, $message, $url,$data) = $jump_type; break;
            default : die(RESULT_ERROR);
        }
        endif;
        $success  = RESULT_SUCCESS;
        $error    = RESULT_ERROR;
        $redirect = RESULT_REDIRECT;
        switch ($jump_type)
        {
            case $success  : $this->success($message, $url,$data); break;
            case $error    : $this->error($message, $url,$data);   break;
            case $redirect : $this->$redirect($message);      break;
            default        : die(RESULT_ERROR);
        }
    }
	    
}