Example #1
0
 public static function config($name)
 {
     // 如果设置了前缀,则替换conf
     if (isset($name['prefix'])) {
         C('SESSION_PREFIX', $name['prefix']);
     }
     // 根据默认值设置获得根据定义的id设置
     if (C('VAR_SESSION_ID') && isset($_REQUEST[C('VAR_SESSION_ID')])) {
         session_id($_REQUEST[C('VAR_SESSION_ID')]);
     } elseif (isset($name['id'])) {
         session_id($name['id']);
     }
     // session 函数参考,http://www.php.net/manual/zh/ref.session.php
     // session runtime 配置参考,http://www.php.net/manual/zh/session.configuration.php
     ini_set('session.auto_start', 0);
     if (isset($name['name'])) {
         session_name($name['name']);
     }
     if (isset($name['path'])) {
         session_save_path($name['path']);
     }
     if (isset($name['domain'])) {
         ini_set('session.cookie_domain', $name['domain']);
     }
     if (isset($name['expire'])) {
         ini_set('session.gc_maxlifetime', $name['expire']);
     }
     if (isset($name['use_trans_sid'])) {
         ini_set('session.use_trans_sid', $name['use_trans_sid'] ? 1 : 0);
     }
     if (isset($name['use_cookies'])) {
         ini_set('session.use_cookies', $name['use_cookies'] ? 1 : 0);
     }
     if (isset($name['cache_limiter'])) {
         session_cache_limiter($name['cache_limiter']);
     }
     if (isset($name['cache_expire'])) {
         session_cache_expire($name['cache_expire']);
     }
     if (isset($name['type'])) {
         C('SESSION_TYPE', $name['type']);
     }
     // 如果存在其他session类型
     if (C('SESSION_TYPE')) {
         // 读取session驱动
         $class = 'Session' . ucwords(strtolower(C('SESSION_TYPE')));
         // 检查驱动类是否存在并加载,不存在则抛出错误
         if (Import::load(EXTEND_PATH . 'Driver/Session/' . $class . '.class.php')) {
             $hander = new $class();
             $hander->execute();
         } else {
             // 类没有定义
             Debug::throw_exception(L('_CLASS_NOT_EXIST_') . ': ' . $class);
         }
     }
     // 启动session
     if (C('SESSION_AUTO_START')) {
         session_start();
     }
 }
Example #2
0
 /**
  * Método que chama a classe de manipulação do cache de acordo com a configuração
  * @return	Cachesource		retorna uma instância do Cachesource de acordo com a configuração
  */
 public static function factory()
 {
     if (!self::$instance) {
         $config = Config::get('cache');
         $class = ucfirst(strtolower($config['type'])) . 'Cachesource';
         Import::load('cachesource', array($class));
         self::$instance = call_user_func(array($class, 'getInstance'));
     }
     return self::$instance;
 }
Example #3
0
<?php

define('CMSPATH', str_replace("\\", "/", dirname(__FILE__)));
define('DS', "/");
define('COREPATH', CMSPATH . DS . 'core');
require_once COREPATH . DS . "loader.php";
$access = Import::load("lib", "Start_Page");
$access = $access and import::load('lib', 'view');
$access = $access and import::load('lib', 'Validate_Auth');
validate_auth::start();
$LestStart = new Start_Page();
if ($access) {
    if ($LestStart->checkURL() == URL . DS) {
        header('Location: http://' . URL . DS . 'login' . DS . "start");
    } else {
        $LestStart->start();
    }
} else {
    echo "No se logro realizar la carga de los archivos.";
}
Example #4
0
<?php

namespace Think\Library;

\Import::load(dirname(__FILE__) . 'RbacAuth' . EXT);
class ApiAuth extends RbacAuth
{
    protected $token;
    public function __construct(string $auth_key, array $rules, array $roles)
    {
        // 执行父类构造函数
        parent::__construct($auth_key, $rules, $roles);
        // 获得token
        $this->token = $_POST['access_token'];
    }
    public function logined()
    {
        if ($this->token && S($this->token)) {
            return true;
        } else {
            return false;
        }
    }
    public function login(int $id, string $token, int $expire)
    {
        // 设置默认值
        if (!$expire) {
            $expire = 60 * 60 * 60 * 24 * 30;
        }
        // 设置session并保存
        S($token, $id);
Example #5
0
 private function datasource($entity = null)
 {
     $class = ucfirst(strtolower($this->config['type'])) . 'Datasource';
     Import::load('datasource', array($class));
     return new $class($this->config, $entity);
 }