Example #1
0
 public function __construct()
 {
     $config = Leguan::get('config');
     $class = "\\Leguan\\View\\Adapter\\{$config->viewEngine}\\Loader";
     $loader = new $class();
     $this->_obj = $loader->getView();
 }
Example #2
0
 public function __construct()
 {
     $config = Leguan::get('config');
     $dbEngine = $config->dbEngine;
     $dbEngine = ucwords($dbEngine);
     $class = "\\Leguan\\Sql\\Adapter\\{$dbEngine}";
     $this->_obj = new $class();
 }
Example #3
0
 public function __construct()
 {
     $config = Leguan::get('config');
     $cacheType = $config->cacheType;
     $cacheType = ucwords($cacheType);
     $class = "\\Leguan\\Cache\\Adapter\\{$cacheType}";
     $this->_obj = new $class();
 }
Example #4
0
 /**
  * 写入緩存內容
  *
  * @param $name
  * @param $value
  * @return void
  */
 public function write($name, $value)
 {
     $path = Leguan::get('path');
     $fileName = $path->dataCache . $path->ds . "{$name}.php";
     if (!file_exists($path->dataCache) && !mkdir($path->dataCache, 0777, true)) {
         die("创建目录失败 {$cacheDir}");
     }
     $data = "<?php\n\t\treturn '" . serialize($value) . "';";
     file_put_contents($fileName, $data);
 }
Example #5
0
 public function __construct()
 {
     $config = Leguan::get('config');
     $dbEngine = ucwords($config->dbEngine);
     $escape = "dbEscape{$dbEngine}";
     if ($config->{$escape} !== null) {
         //设置表、字段转义字符
         $this->_escape = $config->{$escape};
     }
     $this->_db = Leguan::get('db');
 }
Example #6
0
 public function write($msg)
 {
     $path = Leguan::get('path');
     $fileName = $path->log . $path->ds . date('Ym') . $path->ds . date('d') . ".txt";
     $dirName = dirname($fileName);
     if (!file_exists($dirName) && !mkdir($dirName, 0777, true)) {
         die("创建目录失败 {$cacheDir}");
     }
     $handle = fopen($fileName, 'w');
     fwrite($handle, date('Y-m-d H:i:s') . " {$msg}\r\n");
     fclose($handle);
 }
Example #7
0
 /**
  * 加载应用级别和模块级别帮助文件
  */
 public function __call($name, $arguments)
 {
     static $obj = array();
     $url = Leguan::get('url');
     $helper = array('Common', $url->m);
     foreach ($helper as $value) {
         $helper = "\\{$value}\\Helper\\Helper";
         if (!isset($obj[$helper])) {
             $obj[$helper] = new $helper();
         }
         if (is_callable(array($obj[$helper], $name))) {
             return call_user_func_array(array($obj[$helper], $name), $arguments);
         }
     }
     return null;
 }
Example #8
0
 /**
  * 初始化数据库连接信息
  */
 protected function _init()
 {
     $config = Leguan::get('config');
     if (empty(self::$_db)) {
         self::$_dbCharset = $config->charset != null ? $config->charset : self::$_dbCharset;
         self::$_dbCharset = str_replace('-', '', self::$_dbCharset);
         self::$_dbPrefix = $config->dbPrefix;
         if (empty($config->dbDsn)) {
             $dsn = new Dsn($config->dbEngine, $config->dbHost, $config->dbName, $config->dbPort);
             $config->dbDsn = $dsn->getDsn();
         }
         try {
             self::$_db = new \PDO($config->dbDsn, $config->dbUser, $config->dbPwd);
             //禁用prepared statements的仿真效果
             self::$_db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
             self::$_db->exec("set names '" . self::$_dbCharset . "'");
         } catch (PDOException $e) {
             echo 'Connection failed: ' . $e->getMessage();
         }
     }
 }
Example #9
0
 private function _getPathUrl($path)
 {
     $pathArr = $this->_getPathArr($path);
     $urlArr = array();
     array_unshift($urlArr, array_pop($pathArr));
     array_unshift($urlArr, array_pop($pathArr));
     array_unshift($urlArr, array_pop($pathArr));
     foreach ($pathArr as $key => $value) {
         array_push($urlArr, $key);
         array_push($urlArr, $value);
     }
     $config = Leguan::get('config');
     return "/" . implode('/', $urlArr) . $config->urlExtension;
 }
Example #10
0
 public function __get($name)
 {
     return Leguan::get($name);
 }
Example #11
0
 /**
  * 表单处理
  */
 private function _exec($name, $type, $tmp_name, $error, $size)
 {
     if ($size > $this->_fileSize) {
         return '上传文件失败,文件不能大于' . $this->_fileSize / 1024 / 1024 . 'MB';
     }
     $extension = Leguan::get('path')->getExtension($name);
     if (empty($extension)) {
         return '文件扩展名不能为空';
     }
     if (!in_array($extension, $this->_fileExtension)) {
         return "上传文件失败,文件类型不允许为扩展{$extension}";
     }
     $path = Leguan::get('path');
     $dirName = date('Ym') . $path->ds . date('d');
     $realPath = array($this->_fileDir, $dirName);
     $realPath = implode($path->ds, $realPath);
     //判断目录是否存在
     if (!file_exists($realPath)) {
         mkdir($realPath, 0777, true);
     }
     $fileName = md5_file($tmp_name) . ".{$extension}";
     $filePath = array();
     array_push($filePath, $dirName . $path->ds . $fileName);
     move_uploaded_file($tmp_name, "{$realPath}{$path->ds}{$fileName}");
     return $filePath;
 }
Example #12
0
 /**
  * 获取数据库查询次数
  */
 public function getQueryNum()
 {
     $db = Leguan::get('db');
     return $db->getQueryNum();
 }
Example #13
0
 /**
  * html转义
  */
 public function htmlEscape($html)
 {
     $config = Leguan::get('config');
     $func = $config->viewEscape;
     return $func($html);
 }
Example #14
0
 /**
  * 获取get请求数据
  *
  * @param $name string
  * @return mixed
  */
 public function get($name = null)
 {
     $url = Leguan::get('url');
     if (empty($name)) {
         return $url->getUrlAll();
     }
     return $url->{$name};
 }
Example #15
0
 /**
  * 框架入口
  */
 public static function run()
 {
     self::_init();
     Leguan::get('routing')->run();
 }