コード例 #1
0
 /**
  * 加载视图处理类并完成视图类的实例化
  *
  * 注:本类方法为回调类方法。
  *
  * @access protected
  * @return object
  */
 protected function initView()
 {
     //当视图文件格式为PHP时,采用Widget自身的视图机制。即:非View Class的视图机制
     if (VIEW_EXT == Configure::VIEW_EXT_PHP) {
         return null;
     }
     //分析视图类文件路径
     $filePath = DOIT_ROOT . '/core/WidgetTemplate.php';
     //加载视图处理类文件
     Doit::loadFile($filePath);
     //实例化视图类
     $viewObject = WidgetTemplate::getInstance();
     $viewObject->widgetId = $this->_getWidgetName();
     return $viewObject;
 }
コード例 #2
0
 /**
  * 写入日志
  *
  * @access public
  *
  * @param string $message     所要写入的日志内容
  * @param string $level       日志类型. 参数:Warning, Error, Notice
  * @param string $logFileName 日志文件名
  *
  * @return boolean
  */
 public static function write($message, $level = 'Error', $logFileName = null)
 {
     //参数分析
     if (!$message) {
         return false;
     }
     //当日志写入功能关闭时
     if (Configure::get('application.log') === false) {
         return true;
     }
     $logFilePath = self::_getLogFilePath($logFileName);
     //分析日志文件存放目录
     $logDir = dirname($logFilePath);
     if (!is_dir($logDir)) {
         mkdir($logDir, 0777, true);
     }
     //分析记录日志的当前页面
     $controllerId = Doit::getControllerName();
     $actionId = Doit::getActionName();
     //分析日志内容
     $message = "[{$controllerId}][{$actionId}]:" . $message;
     return error_log(date('[Y-m-d H:i:s]') . " {$level}: {$message} IP: {$_SERVER['REMOTE_ADDR']}\n", 3, $logFilePath);
 }
コード例 #3
0
 /**
  * 加载视图处理类并完成视图类的实例化
  *
  * 注:本类方法为回调类方法。通过在Controller Class的继承子类中重载本类方法,来实现自定义DoitPHP项目的视图机制的操作。
  *
  * @access protected
  * @return object
  */
 protected function initView()
 {
     //分析视图类文件路径
     $filePath = DOIT_ROOT . '/core/' . (VIEW_EXT == Configure::VIEW_EXT_PHP ? 'View.php' : 'Template.php');
     //加载视图处理类文件
     Doit::loadFile($filePath);
     //返回视图实例化对象
     return VIEW_EXT == Configure::VIEW_EXT_PHP ? View::getInstance() : Template::getInstance();
 }
コード例 #4
0
 /**
  * 分析视图缓存文件名
  *
  * @access protected
  *
  * @param string $cacheId 视图文件的缓存ID
  *
  * @return string
  */
 protected function _parseCacheFile($cacheId)
 {
     return CACHE_PATH . '/htmls/' . Doit::getControllerName() . DS . md5($cacheId) . '.action.html';
 }
コード例 #5
0
 /**
  * 加载并单例模式实例化扩展模块(通常为第三方程序)
  *
  *  注:这里所调用的扩展模声要放在项目extension目录里的子目录中
  *
  * @access public
  *
  * @param string $extensionName 扩展插件名称
  *
  * @access object
  */
 public static final function loadExtension($extensionName)
 {
     //参数分析
     if (!$extensionName) {
         return false;
     }
     //当所加载的扩展模块还示被实例化时
     if (!isset(self::$_extensionObjArray[$extensionName])) {
         //加载扩展模块的引导文件(index)
         $extensionPath = self::_getExtRoot($extensionName) . DS . $extensionName . 'Ext.php';
         Doit::loadFile($extensionPath);
         self::$_extensionObjArray[$extensionName] = Doit::singleton('extensions.' . $extensionName . 'Ext');
     }
     return self::$_extensionObjArray[$extensionName];
 }
コード例 #6
0
     *
     * @example $controllerName = Doit::getControllerName();
     *
     * @access public
     * @return string controller名称(字母全部小写)
     */
    public static function getControllerName()
    {
        return strtolower(self::$_controller);
    }
    /**
     * 获取当前运行的Action名称
     *
     * @example $actionName = Doit::getActionName();
     *
     * @access public
     * @return string action名称(字母全部小写)
     */
    public static function getActionName()
    {
        return self::$_action;
    }
}
/**
 * 自动加载引导文件的加载
 */
Doit::loadFile(DOIT_ROOT . '/core/AutoLoad.php');
/**
 * 调用SPL扩展,注册__autoload()函数.
 */
spl_autoload_register(array('doitphp\\core\\AutoLoad', 'loadClass'));
コード例 #7
0
 /**
  * 构造函数
  *
  * @access public
  * @return boolean
  */
 public function __construct()
 {
     $this->_cookieObj = Doit::singleton('Cookie');
     return true;
 }
コード例 #8
0
 /**
  * 设置某cookie变量的值
  *
  * @access public
  *
  * @param string $cookieName cookie的变量名
  * @param mixed $value cookie值
  * @param integer $expire cookie的生存周期
  * @param string $path cookie所存放的目录
  * @param string $domain cookie所支持的域名
  *
  * @return boolean
  */
 public function set($cookieName, $value, $expire = null, $path = null, $domain = null)
 {
     //参数分析
     if (!$cookieName) {
         return false;
     }
     $expire = is_null($expire) ? $this->_options['expire'] : $expire;
     $path = is_null($path) ? $this->_options['path'] : $path;
     $domain = is_null($domain) ? $this->_options['domain'] : $domain;
     $expire = $_SERVER['REQUEST_TIME'] + $this->_options['expire'];
     if ($this->_options['secretkey']) {
         $value = Doit::singleton('Encrypt')->encode(serialize($value), $this->_options['secretkey']);
     } else {
         $value = base64_encode(serialize($value));
     }
     setcookie($cookieName, $value, $expire, $path, $domain);
     $_COOKIE[$cookieName] = $value;
     return true;
 }
コード例 #9
0
 /**
  * 加载自定义配置文件所引导的文件
  *
  * @access private
  *
  * @param string $className 所需要加载的类的名称,注:不含后缀名
  *
  * @return void
  */
 private static function _loadImportConfigFile($className)
 {
     //定义自动加载状态。(true:已加载/false:未加载)
     $atuoLoadStatus = false;
     //分析配置文件import引导信息
     $importRules = Configure::get('import');
     //当配置文件引导信息合法时
     if ($importRules && is_array($importRules)) {
         foreach ($importRules as $rules) {
             if (!$rules) {
                 continue;
             }
             //当配置文件引导信息中含有*'时,将设置的规则中的*替换为所要加载的文件类名
             if (strpos($rules, '*') !== false) {
                 $filePath = str_replace('*', $className, $rules);
             } else {
                 $filePath = $rules . DS . str_replace('_', DS, $className) . '.php';
             }
             //当自定义自动加载的文件存在时
             if (is_file($filePath)) {
                 //加载文件
                 Doit::loadFile($filePath);
                 $atuoLoadStatus = true;
                 break;
             }
         }
     }
     return $atuoLoadStatus;
 }