Root.php 2 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 = true;

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

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


    /**
     * 删除多个缓存tag
     */
    protected $_delTags = '';


    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);
        return new Server($serviceFile);
    }
}