Beispiel #1
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  * @param mixed|null $config 配置
  */
 public function __construct($app, $config)
 {
     $this->app = $app;
     self::$dir = dir_format($app->DIR . (isset($config['sql_dir']) ? $config['sql_dir'] : '/logs/sql'));
     self::$dir .= '/' . date("Y-m-d", $app->TIME) . '/' . date("H", $app->TIME);
     $app->shutdown()->register(array($this, 'write'));
 }
Beispiel #2
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  *
  * @throws \Exception
  */
 public function __construct($app)
 {
     if (!extension_loaded('apc')) {
         throw new \Exception('没有安装APC扩展,请先在php.ini中配置安装APC。');
     }
     $config = $app->config()->getComponentConfig('cache', 'apc');
     isset($config['expire']) and $this->expire = $config['expire'];
 }
Beispiel #3
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  */
 public function __construct($app)
 {
     $this->app = $app;
     register_shutdown_function(array($this, 'execute'), $this->calledByMe);
     $config = $app->config()->getComponentConfig('shutdown', 'default');
     foreach ($config as $call) {
         $this->register($call);
     }
 }
Beispiel #4
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  *
  * @throws \Exception
  */
 public function __construct($app)
 {
     if (!extension_loaded('apc')) {
         new \Exception('会话出错:没有安装APC扩展。', 2048);
     }
     $this->app = $app;
     $this->config = $app->config()->getComponentConfig('session', 'apc');
     $this->start();
 }
Beispiel #5
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  *
  * @throws \Exception
  */
 public function __construct($app)
 {
     if (!extension_loaded('apc')) {
         new \Exception('会话出错:没有安装Memcache扩展。', 2048);
     }
     $this->app = $app;
     $this->config = $app->config()->getComponentConfig('session', 'memcache');
     $this->handler = new \Memcache();
     if (!$this->handler->connect($this->config['host'], $this->config['port'])) {
         new \Exception('会话出错:Memcache连接失败。', 2048);
     }
     $this->start();
 }
Beispiel #6
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  *
  * @throws \Exception
  */
 public function __construct($app)
 {
     if (!extension_loaded('memcache')) {
         throw new \Exception('没有安装memcache扩展,请先在php.ini中配置安装memcache。');
     }
     $config = $app->config()->getComponentConfig('cache', 'memcache');
     isset($config['expire']) and $this->expire = $config['expire'];
     $this->compressed = isset($config['compressed']) ? $config['compressed'] : false;
     $this->connection = new \Memcache();
     if (!$this->connection->addserver($config['host'], $config['port'], $config['persistent'])) {
         throw new \Exception('连接memcache服务器时失败,请确认你的连接参数是否正确。');
     }
 }
Beispiel #7
0
 /**
  * @param Monkey\App $app
  */
 public function __construct($app)
 {
     $config = $app->config()->getComponentConfig('cache', 'file');
     $this->TIME = $app->TIME;
     $this->expire = $config['expire'];
     $this->cachePath = dir_format($app->TEMP . ($config['dir'] ? $config['dir'] : '/fileCache'));
     $this->cacheFile = $config['filename'] ? '/' . $config['filename'] : '/data';
     $this->cacheSize = $config['filesize'] ? $config['filesize'] : '15M';
     $this->dataOnCheck = $config['check'] ? $config['check'] : false;
     //是否验证数据
     if (!dir_check($this->cachePath)) {
         $this->error('缓存目录校验失败。');
     }
     $this->workat($this->cachePath . $this->cacheFile);
 }
Beispiel #8
0
 /**
  * 组装绝对网址链接
  *
  * @param string $pattern 路径模式  get/test/abc-{zh|en}/blog/{year}-([1-9]\d*):language:year:id
  * 其中请求方法get是可选的 如 /test/abc-{zh|en}/blog/{year}-([1-9]\d*):language:year:id
  * @param string $parameters 参数  array('language'=>'en','year'=>'2014','id'=4025
  * @param bool $forceHttps 是否强制使用https协议, false时将使用请求时的协议。
  *
  * @return string  http://www.host.com/.../test/abc-en/blog/2014-4025
  */
 public function toAbsURL($pattern, $parameters = null, $forceHttps = false)
 {
     $uri = $this->toURL($pattern, $parameters);
     $uri = $this->app->request()->getUriPrefix() . $uri;
     $forceHttps and $uri = 'https' . strstr($uri, ':');
     return $uri;
 }
Beispiel #9
0
 /**
  * 独立预处理
  *
  * @param string $sql
  * @param array $driverOptions
  *
  * @return Statement
  *
  * @throws SqlEmptyException
  */
 public function prepareQuery($sql, array $driverOptions = array())
 {
     //效验sql语句
     if (!$sql) {
         $error = array('code' => 1024, 'sql' => '', 'message' => 'sql语句为空,无法执行query操作!', 'connectionName' => $this->name);
         $this->app->logger()->sql($error);
         throw new SqlEmptyException('数据库查询错误。', 1024);
     }
     //处理表前缀
     $sql = preg_replace('/\\{:(\\S+?):\\}/', $this->config['prefix'] . '$1', $sql);
     //保存预处理sql
     $this->prepareSQL = $sql;
     return parent::prepare($sql, $driverOptions);
 }
Beispiel #10
0
 /**
  * 尝试具体配置的连接
  *
  * @param array $config 连接配置
  * @param string $name 连接名称,留空表示测试连接
  *
  * @throws \PDOException
  *
  * @return \Monkey\Database\Connection|false
  */
 public function tryConnecting($config, $name = 'test')
 {
     //设置连接类名
     $class = ucfirst(strtolower($config['protocol']));
     $class = $class == 'Mysql' ? '' : '\\' . $class;
     //如果是Mysql驱动,直接使用父类,目的是获得更高的效率
     $class = __NAMESPACE__ . $class . '\\Connection';
     try {
         //创建连接对象
         $connect = new $class($this->app, $name, $config);
     } catch (\PDOException $e) {
         //处理连接错误,记录错误日志
         $error = array('error_title' => '连接到PDO时出错。', 'message' => $e->getMessage(), 'code' => $e->getCode());
         $this->app->logger()->sql($error);
         throw $e;
     }
     return $connect;
 }
Beispiel #11
0
 private function show($errorInfo, $tpl)
 {
     $errorInfo['goto_index'] = $this->app->FRONT_ROOT_URL . '/index.php';
     if ($this->app->request()->isAjax()) {
         ob_clean();
         //清除之前输出的内容
         echo json_encode(notice(false, $errorInfo));
     } elseif (isset($_SERVER['REMOTE_ADDR'])) {
         //载入显示模板
         if (file_exists($tpl)) {
             require $tpl;
         } else {
             $this->printError($errorInfo, '<br/>', '糟糕,连错误页显示模板也不存在!');
         }
     } else {
         $this->printError($errorInfo, PHP_EOL);
     }
 }
Beispiel #12
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  */
 public function __construct($app)
 {
     $this->app = $app;
     if ('HEAD' == $app->request()->getMethod()) {
         $this->setHttpHeaderOnly(true);
     }
     $this->charset = $app->CHARSET;
     $app->shutdown()->register(array($this, 'send'));
     if (substr($this->app->request()->header()->getContentType(), -4) == 'json') {
         $this->setJson();
     }
     if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip') !== false && !ini_get('zlib.output_compression') && extension_loaded("zlib") && function_exists('gzencode')) {
         ob_start("ob_gzhandler");
     } else {
         ob_start();
     }
 }
Beispiel #13
0
 public function __construct($staticDir)
 {
     $this->DEBUG = E_ALL ^ E_NOTICE ^ E_WARNING;
     parent::__construct($staticDir);
 }
Beispiel #14
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  */
 public function __construct($app)
 {
     $this->app = $app;
     $this->config = $app->config()->getComponentConfig('view', 'default');
     $this->themeUrlBase = $app->FRONT_ROOT_URL . $this->config['theme_url_base'];
     $this->themeDirName = $this->config['theme_dir'];
     $this->template = new Template($app, $this->config);
 }
Beispiel #15
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  * @param string|null $cacheFile 默认使用路由作为缓存文件名(不含后缀名,路径相对于应用程序目录)
  */
 public function __construct($app, $cacheFile = null)
 {
     $this->app = $app;
     $this->setFile($cacheFile ? $cacheFile : $app->router()->getPath());
 }