diff --git a/vendor/autoload.php b/vendor/autoload.php index fc8e44c10..497b0c5f2 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitf3ef7a459e4b29cdf35865d01f6cf929::getLoader(); +return ComposerAutoloaderInit100512daef0328603db43c7860e1b81c::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index c421d1d38..ad4bd6ede 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitf3ef7a459e4b29cdf35865d01f6cf929 +class ComposerAutoloaderInit100512daef0328603db43c7860e1b81c { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInitf3ef7a459e4b29cdf35865d01f6cf929 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitf3ef7a459e4b29cdf35865d01f6cf929', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit100512daef0328603db43c7860e1b81c', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInitf3ef7a459e4b29cdf35865d01f6cf929', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit100512daef0328603db43c7860e1b81c', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit100512daef0328603db43c7860e1b81c::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInitf3ef7a459e4b29cdf35865d01f6cf929 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit100512daef0328603db43c7860e1b81c::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequiref3ef7a459e4b29cdf35865d01f6cf929($fileIdentifier, $file); + composerRequire100512daef0328603db43c7860e1b81c($fileIdentifier, $file); } return $loader; } } -function composerRequiref3ef7a459e4b29cdf35865d01f6cf929($fileIdentifier, $file) +function composerRequire100512daef0328603db43c7860e1b81c($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 9fa69c889..ac4bceeab 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929 +class ComposerStaticInit100512daef0328603db43c7860e1b81c { public static $files = array ( '9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php', @@ -314,9 +314,9 @@ class ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitf3ef7a459e4b29cdf35865d01f6cf929::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit100512daef0328603db43c7860e1b81c::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit100512daef0328603db43c7860e1b81c::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit100512daef0328603db43c7860e1b81c::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 5c982a2a2..097767a27 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -260,20 +260,20 @@ }, { "name": "topthink/think-mongo", - "version": "v1.6", - "version_normalized": "1.6.0.0", + "version": "v1.7", + "version_normalized": "1.7.0.0", "source": { "type": "git", "url": "https://github.com/top-think/think-mongo.git", - "reference": "1c6d29f58bd7caa8da088c167b4e65ddac621588" + "reference": "fc552c8fe5798679a52f4f0d7e60763f64aeb155" }, "dist": { "type": "zip", - "url": "https://files.phpcomposer.com/files/top-think/think-mongo/1c6d29f58bd7caa8da088c167b4e65ddac621588.zip", - "reference": "1c6d29f58bd7caa8da088c167b4e65ddac621588", + "url": "https://files.phpcomposer.com/files/top-think/think-mongo/fc552c8fe5798679a52f4f0d7e60763f64aeb155.zip", + "reference": "fc552c8fe5798679a52f4f0d7e60763f64aeb155", "shasum": "" }, - "time": "2017-02-13 07:17:51", + "time": "2017-05-05 07:52:33", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/topthink/think-mongo/src/Connection.php b/vendor/topthink/think-mongo/src/Connection.php index 752ffd048..e2ba9c35b 100644 --- a/vendor/topthink/think-mongo/src/Connection.php +++ b/vendor/topthink/think-mongo/src/Connection.php @@ -66,6 +66,8 @@ class Connection 'hostname' => '', // 数据库名 'database' => '', + // 是否是复制集 + 'is_replica_set' => false, // 用户名 'username' => '', // 密码 @@ -162,6 +164,18 @@ class Connection return $this->links[$linkNum]; } + /** + * 指定当前使用的查询对象 + * @access public + * @param Query $query 查询对象 + * @return $this + */ + public function setQuery($query, $model = 'db') + { + $this->query[$model] = $query; + return $this; + } + /** * 创建指定模型的查询对象 * @access public @@ -567,7 +581,11 @@ class Connection // 主从式采用读写分离 if ($master) // 主服务器写入 { - $r = $m; + if ($this->config['is_replica_set']) { + return $this->replicaSetConnect(); + } else { + $r = $m; + } } elseif (is_numeric($this->config['slave_no'])) { // 指定服务器读 $r = $this->config['slave_no']; @@ -586,6 +604,41 @@ class Connection return $this->connect($dbConfig, $r); } + /** + * 创建基于复制集的连接 + * @return Manager + */ + public function replicaSetConnect() + { + $this->dbName = $this->config['database']; + $this->typeMap = $this->config['type_map']; + if ($this->config['debug']) { + $startTime = microtime(true); + } + $this->config['params']['replicaSet'] = $this->config['database']; + $manager = new Manager($this->buildUrl(), $this->config['params']); + if ($this->config['debug']) { + // 记录数据库连接信息 + Log::record('[ DB ] CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $this->config['dsn'], 'sql'); + } + return $manager; + } + + /** + * 根据配置信息 生成适用于链接复制集的 URL + * @return string + */ + private function buildUrl() + { + $url = 'mongodb://' . ($this->config['username'] ? "{$this->config['username']}" : '') . ($this->config['password'] ? ":{$this->config['password']}@" : ''); + $hostList = explode(',', $this->config['hostname']); + $portList = explode(',', $this->config['hostport']); + for ($i = 0; $i < count($hostList); $i++) { + $url = $url . $hostList[$i] . ':' . $portList[0] . ','; + } + return rtrim($url, ",") . '/'; + } + /** * 析构方法 * @access public diff --git a/vendor/topthink/think-mongo/src/Query.php b/vendor/topthink/think-mongo/src/Query.php index 022486a3a..efb30af37 100644 --- a/vendor/topthink/think-mongo/src/Query.php +++ b/vendor/topthink/think-mongo/src/Query.php @@ -1044,6 +1044,17 @@ class Query return $this; } + /** + * 设置软删除字段及条件(暂无支持) + * @access public + * @param false|string $field 查询字段 + * @param mixed $condition 查询条件 + * @return $this + */ + public function useSoftDelete($field, $condition = null) + { + } + /** * 不主动获取数据集 * @access public @@ -1800,7 +1811,7 @@ class Query * 查找单条记录 * @access public * @param array|string|Query|\Closure $data - * @return array|false|Cursor|string|Model + * @return array|null|Cursor|string|Model * @throws ModelNotFoundException * @throws DataNotFoundException * @throws AuthenticationException @@ -2005,6 +2016,8 @@ class Query $result = $this->table($tableName)->find(); if ($result instanceof Model) { $result = $result->toArray(); + } elseif (!$result) { + $result = []; } $fields = array_keys($result); $type = [];