Root.php 2.54 KB
<?php
/**
 * Created by PhpStorm.
 * User: Zip
 * Date: 14/12/7
 * Time: 上午12:45
 */

namespace Hood\Core;

use Hood\Core\Server;

class Root
{

    /**
     * server file
     * @var String
     */
    protected $serviceFile;

    /**
     * 应用环境
     * @var string
     */
    protected $applicationEnv;


    /**
     * 缓存时间
     * @var int
     */
    protected $_cacheExpire = 3600;

    /**
     * 缓存
     * @var bool
     */
    protected $_cacheStatus = false;


    /**
     * reset默认缓存是否开启
     * @var bool
     */
    protected $_defaultCacheStatus = false;

    /**
     * 缓存key
     * @var null
     */
    protected $_cacheKey = null;

    /**
     * 缓存tagName
     * @var string
     */
    protected $_cacheTagName = '';


    /**
     * 删除多个缓存tag
     */
    protected $_delTags = array();


    /**
     * 强制使用从
     * @var bool
     */
    protected $_slave = false;

    /**
     * 强制使用主
     * @var bool
     */
    protected $_master = false;


    public function __construct()
    {
        defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
        defined('APPLICATION_SYSTEM_CONFIG') || define('APPLICATION_SYSTEM_CONFIG', '/Data/Code/SystemConfig');
    }

    /**
     * 获取应用环境
     * @return string
     */
    public function getApplicationEnv()
    {
        return $this->applicationEnv;
    }

    /**
     * 设置应用环境
     * @param $env
     * @return $this
     */
    public function setApplicationEnv($env)
    {
        define('APPLICATION_ENV', $env);
        return $this;
    }

    /**
     *
     * @param $configFile
     * @return $this
     */
    public function setApplicationSystemConfig($configFile)
    {
        define('APPLICATION_SYSTEM_CONFIG', $configFile);
        return $this;
    }

    /**
     * 获取server
     * @param $serviceName
     * @param string $suffix
     * @return Server
     */
    public function getServerHost($serviceName, $suffix = 'config.ini')
    {
        $serviceFileArray = array(
            $serviceName,
            APPLICATION_ENV,
            $suffix
        );
        $this->serviceFile = $serviceFile = APPLICATION_SYSTEM_CONFIG . DIRECTORY_SEPARATOR . implode('.', $serviceFileArray);
        $server = new Server();
        $server->setFileName($serviceFile);
        return $server;
    }


    public function master()
    {
        $this->_master = true;
        return $this;
    }

    public function slave()
    {
        $this->_slave = true;
        return $this;
    }
}