[更新]ComposerUpdate

This commit is contained in:
Anyon 2018-07-20 10:48:58 +08:00
parent 02bf4a0784
commit cfd2d2eff0
18 changed files with 183 additions and 111 deletions

View File

@ -22,6 +22,8 @@ ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特
+ 模型和数据库增强
+ 依赖注入完善
+ 支持PSR-3日志规范
+ 中间件支持(`V5.1.6+`
+ 支持`Swoole`/`Workerman`运行(`V5.1.18+`
### 废除的功能:
@ -31,6 +33,32 @@ ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特
> ThinkPHP5.1的运行环境要求PHP5.6+。
## 安装
使用composer安装
~~~
composer create-project topthink/think tp
~~~
启动服务
~~~
cd tp
php think run
~~~
然后就可以在浏览器中访问
~~~
http://localhost:8000
~~~
更新框架
~~~
composer update topthink/framework
~~~
## 在线手册

View File

@ -20,7 +20,7 @@ use think\route\Dispatch;
*/
class App extends Container
{
const VERSION = '5.1.18';
const VERSION = '5.1.19';
/**
* 当前模块路径

View File

@ -11,15 +11,19 @@
namespace think;
use ArrayAccess;
use ArrayIterator;
use Closure;
use Countable;
use InvalidArgumentException;
use IteratorAggregate;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
use ReflectionMethod;
use think\exception\ClassNotFoundException;
class Container implements \ArrayAccess
class Container implements ArrayAccess, IteratorAggregate, Countable
{
/**
* 容器对象实例
@ -152,6 +156,9 @@ class Container implements \ArrayAccess
} elseif ($concrete instanceof Closure) {
$this->bind[$abstract] = $concrete;
} elseif (is_object($concrete)) {
if (isset($this->bind[$abstract])) {
$abstract = $this->bind[$abstract];
}
$this->instances[$abstract] = $concrete;
} else {
$this->bind[$abstract] = $concrete;
@ -278,6 +285,16 @@ class Container implements \ArrayAccess
}
}
/**
* 获取容器中的对象实例
* @access public
* @return array
*/
public function all()
{
return $this->instances;
}
/**
* 清除容器中的对象实例
* @access public
@ -502,4 +519,16 @@ class Container implements \ArrayAccess
{
$this->__unset($key);
}
//Countable
public function count()
{
return count($this->instances);
}
//IteratorAggregate
public function getIterator()
{
return new ArrayIterator($this->instances);
}
}

View File

@ -113,12 +113,26 @@ class Cookie
$expire = !empty($config['expire']) ? $_SERVER['REQUEST_TIME'] + intval($config['expire']) : 0;
if ($config['setcookie']) {
setcookie($name, $value, $expire, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
$this->setCookie($name, $value, $expire, $config);
}
$_COOKIE[$name] = $value;
}
/**
* Cookie 设置保存
*
* @access public
* @param string $name cookie名称
* @param mixed $value cookie值
* @param array $option 可选参数
* @return void
*/
protected function setCookie($name, $value, $expire, $option = [])
{
setcookie($name, $value, $expire, $option['path'], $option['domain'], $option['secure'], $option['httponly']);
}
/**
* 永久保存Cookie数据
* @access public
@ -205,7 +219,7 @@ class Cookie
$name = $prefix . $name;
if ($config['setcookie']) {
setcookie($name, '', $_SERVER['REQUEST_TIME'] - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
$this->setcookie($name, '', $_SERVER['REQUEST_TIME'] - 3600, $config);
}
// 删除指定cookie
@ -234,7 +248,7 @@ class Cookie
foreach ($_COOKIE as $key => $val) {
if (0 === strpos($key, $prefix)) {
if ($config['setcookie']) {
setcookie($key, '', $_SERVER['REQUEST_TIME'] - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
$this->setcookie($key, '', $_SERVER['REQUEST_TIME'] - 3600, $config);
}
unset($_COOKIE[$key]);
}

View File

@ -236,6 +236,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 设置当前模型 确保查询返回模型对象
$query = Db::connect($this->connection, false, $this->query);
$query->model($this)
->name($this->name)
->json($this->json, $this->jsonAssoc)
->setJsonFieldType($this->jsonType);
@ -246,8 +247,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 设置当前数据表和模型名
if (!empty($this->table)) {
$query->table($this->table);
} else {
$query->name($this->name);
}
if (!empty($this->pk)) {
@ -766,7 +765,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if ($this->exists || (!empty($auto) && isset($data[$pk]))) {
$result[$key] = self::update($data, [], $this->field);
} else {
$result[$key] = self::create($data, $this->field);
$result[$key] = self::create($data, $this->field, $this->replace);
}
}

View File

@ -258,7 +258,6 @@ class Request
* php://input内容
* @var string
*/
// php://input
protected $input;
/**
@ -986,7 +985,7 @@ class Request
public function post($name = '', $default = null, $filter = '')
{
if (empty($this->post)) {
$this->post = !empty($_POST) ? $_POST : $this->getJsonInputData($this->input);
$this->post = !empty($_POST) ? $_POST : $this->getInputData($this->input);
}
return $this->input($this->post, $name, $default, $filter);
@ -1003,22 +1002,19 @@ class Request
public function put($name = '', $default = null, $filter = '')
{
if (is_null($this->put)) {
$data = $this->getJsonInputData($this->input);
if (!empty($data)) {
$this->put = $data;
} else {
parse_str($this->input, $this->put);
}
$this->put = $this->getInputData($this->input);
}
return $this->input($this->put, $name, $default, $filter);
}
protected function getJsonInputData($content)
protected function getInputData($content)
{
if (false !== strpos($this->contentType(), 'application/json')) {
if (false !== strpos($this->contentType(), 'application/json') || 0 === strpos($content, '{"')) {
return (array) json_decode($content, true);
} elseif (strpos($content, '=')) {
parse_str($content, $data);
return $data;
}
return [];
@ -2055,6 +2051,30 @@ class Request
return $this;
}
/**
* 设置php://input数据
* @access public
* @param string $input RAW数据
* @return $this
*/
public function withInput($input)
{
$this->input = $input;
return $this;
}
/**
* 设置文件上传数据
* @access public
* @param array $files 上传信息
* @return $this
*/
public function withFiles(array $files)
{
$this->file = $files;
return $this;
}
/**
* 设置COOKIE数据
* @access public

View File

@ -528,7 +528,7 @@ class Query
* @param array $data 操作的数据
* @param string $field 分表依据的字段
* @param array $rule 分表规则
* @return string
* @return array
*/
public function getPartitionTableName($data, $field, $rule = [])
{
@ -575,9 +575,7 @@ class Query
$tableName[] = 'SELECT * FROM ' . $this->getTable() . '_' . ($i + 1);
}
$tableName = '( ' . implode(" UNION ", $tableName) . ') AS ' . $this->name;
return $tableName;
return ['( ' . implode(" UNION ", $tableName) . ' )' => $this->name];
}
/**
@ -2723,11 +2721,13 @@ class Query
if (!empty($this->options['soft_delete'])) {
// 软删除
list($field, $condition) = $this->options['soft_delete'];
if ($condition) {
unset($this->options['soft_delete']);
$this->options['data'] = [$field => $condition];
return $this->connection->update($this);
}
}
$this->options['data'] = $data;

View File

@ -34,6 +34,10 @@ class BelongsTo extends OneToOne
$this->joinType = 'INNER';
$this->query = (new $model)->db();
$this->relation = $relation;
if (get_class($parent) == $model) {
$this->selfRelation = true;
}
}
/**

View File

@ -33,6 +33,10 @@ class HasMany extends Relation
$this->foreignKey = $foreignKey;
$this->localKey = $localKey;
$this->query = (new $model)->db();
if (get_class($parent) == $model) {
$this->selfRelation = true;
}
}
/**

View File

@ -33,6 +33,10 @@ class HasOne extends OneToOne
$this->localKey = $localKey;
$this->joinType = 'INNER';
$this->query = (new $model)->db();
if (get_class($parent) == $model) {
$this->selfRelation = true;
}
}
/**

View File

@ -118,38 +118,4 @@ class Resource extends RuleGroup
return $this;
}
/**
* 设置资源允许
* @access public
* @param array $only
* @return $this
*/
public function only($only)
{
return $this->option('only', $only);
}
/**
* 设置资源排除
* @access public
* @param array $except
* @return $this
*/
public function except($except)
{
return $this->option('except', $except);
}
/**
* 设置资源路由的变量
* @access public
* @param array $vars
* @return $this
*/
public function vars($vars)
{
return $this->option('var', $vars);
}
}

View File

@ -932,11 +932,11 @@ abstract class Rule
/**
* 解析URL的pathinfo参数和变量
* @access protected
* @access public
* @param string $url URL地址
* @return array
*/
protected function parseUrlPath($url)
public function parseUrlPath($url)
{
// 分隔符替换 确保路由定义使用统一的分隔符
$url = str_replace('|', '/', $url);
@ -953,6 +953,7 @@ abstract class Rule
$path = explode('/', $url);
} elseif (false !== strpos($url, '=')) {
// 参数1=值1&参数2=值2...
$path = [];
parse_str($url, $var);
} else {
$path = [$url];

View File

@ -503,6 +503,39 @@ class RuleGroup extends Rule
return $this->option('prefix', $prefix);
}
/**
* 设置资源允许
* @access public
* @param array $only
* @return $this
*/
public function only($only)
{
return $this->option('only', $only);
}
/**
* 设置资源排除
* @access public
* @param array $except
* @return $this
*/
public function except($except)
{
return $this->option('except', $except);
}
/**
* 设置资源路由的变量
* @access public
* @param array $vars
* @return $this
*/
public function vars($vars)
{
return $this->option('var', $vars);
}
/**
* 合并分组的路由规则正则
* @access public

View File

@ -45,7 +45,7 @@ class Url extends Dispatch
$url = $bind . ('.' != substr($bind, -1) ? $depr : '') . ltrim($url, $depr);
}
list($path, $var) = $this->parseUrlPath($url);
list($path, $var) = $this->rule->parseUrlPath($url);
if (empty($path)) {
return [null, null, null];
}
@ -160,34 +160,4 @@ class Url extends Dispatch
return $controller;
}
/**
* 解析URL的pathinfo参数和变量
* @access private
* @param string $url URL地址
* @return array
*/
private function parseUrlPath($url)
{
// 分隔符替换 确保路由定义使用统一的分隔符
$url = str_replace('|', '/', $url);
$url = trim($url, '/');
$var = [];
if (false !== strpos($url, '?')) {
// [模块/控制器/操作?]参数1=值1&参数2=值2...
$info = parse_url($url);
$path = explode('/', $info['path']);
parse_str($info['query'], $var);
} elseif (strpos($url, '/')) {
// [模块/控制器/操作]
$path = explode('/', $url);
} elseif (false !== strpos($url, '=')) {
// 参数1=值1&参数2=值2...
parse_str($url, $var);
} else {
$path = [$url];
}
return [$path, $var];
}
}

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInita50785d4573eb0507f755f9262e3b8fc::getLoader();
return ComposerAutoloaderInit5a29168a045363ae5963661dddea68b7::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita50785d4573eb0507f755f9262e3b8fc
class ComposerAutoloaderInit5a29168a045363ae5963661dddea68b7
{
private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInita50785d4573eb0507f755f9262e3b8fc
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita50785d4573eb0507f755f9262e3b8fc', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit5a29168a045363ae5963661dddea68b7', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInita50785d4573eb0507f755f9262e3b8fc', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit5a29168a045363ae5963661dddea68b7', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInita50785d4573eb0507f755f9262e3b8fc::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit5a29168a045363ae5963661dddea68b7::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -48,19 +48,19 @@ class ComposerAutoloaderInita50785d4573eb0507f755f9262e3b8fc
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInita50785d4573eb0507f755f9262e3b8fc::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit5a29168a045363ae5963661dddea68b7::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirea50785d4573eb0507f755f9262e3b8fc($fileIdentifier, $file);
composerRequire5a29168a045363ae5963661dddea68b7($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequirea50785d4573eb0507f755f9262e3b8fc($fileIdentifier, $file)
function composerRequire5a29168a045363ae5963661dddea68b7($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInita50785d4573eb0507f755f9262e3b8fc
class ComposerStaticInit5a29168a045363ae5963661dddea68b7
{
public static $files = array (
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
@ -303,9 +303,9 @@ class ComposerStaticInita50785d4573eb0507f755f9262e3b8fc
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita50785d4573eb0507f755f9262e3b8fc::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita50785d4573eb0507f755f9262e3b8fc::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita50785d4573eb0507f755f9262e3b8fc::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit5a29168a045363ae5963661dddea68b7::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5a29168a045363ae5963661dddea68b7::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5a29168a045363ae5963661dddea68b7::$classMap;
}, null, ClassLoader::class);
}

View File

@ -191,17 +191,17 @@
},
{
"name": "topthink/framework",
"version": "v5.1.18",
"version_normalized": "5.1.18.0",
"version": "v5.1.19",
"version_normalized": "5.1.19.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
"reference": "833fcaf0f29f23bdceaae655f64d10c18b9bf562"
"reference": "3a0fea90ed2a99b181ce503090e08be1171ed091"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/833fcaf0f29f23bdceaae655f64d10c18b9bf562",
"reference": "833fcaf0f29f23bdceaae655f64d10c18b9bf562",
"url": "https://api.github.com/repos/top-think/framework/zipball/3a0fea90ed2a99b181ce503090e08be1171ed091",
"reference": "3a0fea90ed2a99b181ce503090e08be1171ed091",
"shasum": ""
},
"require": {
@ -217,7 +217,7 @@
"sebastian/phpcpd": "2.*",
"squizlabs/php_codesniffer": "2.*"
},
"time": "2018-07-02T05:29:17+00:00",
"time": "2018-07-13T14:10:28+00:00",
"type": "think-framework",
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",