<?php

namespace Main\Lib;

use Dever;

class Core
{
    protected $checkUser = false;
    protected $data;
    public function __construct()
    {
        # 获取用户信息
        $this->user = Dever::load('passport/user')->data();
        $this->data['uid'] = false;
        if ($this->user) {
            $this->data['uid'] = $this->user['id'];
        }
        if ($this->checkUser && !$this->user) {
            $refer = base64_encode(Dever::url());
            $url = Dever::url('main/login?' . Dever::load('passport/login')->createRefer());
            Dever::location($url);
        }

        # 测试时给个默认用户吧
        if ($this->data['uid'] <= 0) {
            $this->data['uid'] = 1;
        }

        # 获取基本配置
        $key = 'config';
        $this->data['config'] = Dever::cache($key);
        if (!$this->data['config']) {
            $this->data['config'] = Dever::db('main/config')->one();
            Dever::cache($key, $this->data['config']);
        }
    }

    protected function log()
    {
        $input = Dever::json_encode(Dever::input());
        $url = Dever::url();
        Dever::log($url . '||' . $input, 'request');
    }
}