改名
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/4 0004
|
||||
* Time: 14:42
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
use Snowflake\Abstracts\Component;
|
||||
@@ -24,26 +24,28 @@ class ActiveQuery extends Component
|
||||
use QueryTrait;
|
||||
|
||||
/** @var array */
|
||||
public $with = [];
|
||||
public array $with = [];
|
||||
|
||||
/** @var bool */
|
||||
public $asArray = FALSE;
|
||||
public bool $asArray = FALSE;
|
||||
|
||||
/** @var bool */
|
||||
public $useCache = FALSE;
|
||||
public bool $useCache = FALSE;
|
||||
|
||||
/** @var Connection $db */
|
||||
public $db = NULL;
|
||||
/**
|
||||
* @var Connection|null
|
||||
*/
|
||||
public ?Connection $db = NULL;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* 参数绑定
|
||||
*/
|
||||
public $attributes = [];
|
||||
public array $attributes = [];
|
||||
|
||||
|
||||
/** @var ActiveRecord */
|
||||
public $modelClass;
|
||||
public ActiveRecord $modelClass;
|
||||
|
||||
/**
|
||||
* Comply constructor.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/3/30 0030
|
||||
* Time: 14:39
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
* @return mixed|ActiveQuery
|
||||
* @throws Exception
|
||||
*/
|
||||
public function hasOne($modelName, $foreignKey, $localKey)
|
||||
public function hasOne(string $modelName, $foreignKey, $localKey)
|
||||
{
|
||||
if (!$this->has($localKey)) {
|
||||
throw new Exception("Need join table primary key.");
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
* Date: 2018/4/9 0009
|
||||
* Time: 9:44
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Base;
|
||||
|
||||
|
||||
use ArrayIterator;
|
||||
use Database\ActiveQuery;
|
||||
use Exception;
|
||||
use Snowflake\Abstracts\Component;
|
||||
use Database\ActiveRecord;
|
||||
@@ -25,12 +26,11 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
/**
|
||||
* @var ActiveRecord[]
|
||||
*/
|
||||
protected $_item = [];
|
||||
protected array $_item = [];
|
||||
|
||||
/** @var ActiveRecord */
|
||||
protected $model;
|
||||
protected ?ActiveRecord $model;
|
||||
|
||||
protected $query;
|
||||
protected ActiveQuery $query;
|
||||
|
||||
/**
|
||||
* Collection constructor.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/3/30 0030
|
||||
* Time: 14:39
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Base;
|
||||
|
||||
|
||||
@@ -38,23 +38,23 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
protected $_attributes = [];
|
||||
protected array $_attributes = [];
|
||||
|
||||
/** @var array */
|
||||
protected $_oldAttributes = [];
|
||||
protected array $_oldAttributes = [];
|
||||
|
||||
/** @var array */
|
||||
protected $_relate = [];
|
||||
protected array $_relate = [];
|
||||
|
||||
/** @var null|string */
|
||||
protected $primary = NULL;
|
||||
protected ?string $primary = NULL;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isNewExample = TRUE;
|
||||
protected bool $isNewExample = TRUE;
|
||||
|
||||
protected $actions = [];
|
||||
protected array $actions = [];
|
||||
|
||||
/** @var Relation */
|
||||
protected $_relation = [];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Base;
|
||||
|
||||
|
||||
@@ -18,12 +18,11 @@ use Snowflake\Snowflake;
|
||||
class CollectionIterator extends \ArrayIterator
|
||||
{
|
||||
|
||||
/** @var ActiveRecord */
|
||||
private $model;
|
||||
private ActiveRecord $model;
|
||||
|
||||
|
||||
/** @var ActiveQuery */
|
||||
private $query;
|
||||
private ActiveQuery $query;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Base;
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ use Database\Condition\RLikeCondition;
|
||||
class ConditionClassMap
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
public static $conditionMap = [
|
||||
public static array $conditionMap = [
|
||||
'IN' => [
|
||||
'class' => InCondition::class
|
||||
],
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/4 0004
|
||||
* Time: 13:38
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
use Database\Base\AbstractCollection;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/3/30 0030
|
||||
* Time: 15:23
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
|
||||
@@ -28,19 +28,19 @@ class Command extends Component
|
||||
const FETCH_COLUMN = 'FETCH_COLUMN';
|
||||
|
||||
/** @var Connection */
|
||||
public $db;
|
||||
public Connection $db;
|
||||
|
||||
/** @var string */
|
||||
public $sql = '';
|
||||
public string $sql = '';
|
||||
|
||||
/** @var array */
|
||||
public $params = [];
|
||||
public array $params = [];
|
||||
|
||||
/** @var string */
|
||||
private $_modelName;
|
||||
private string $_modelName;
|
||||
|
||||
/** @var PDOStatement */
|
||||
private $prepare;
|
||||
private PDOStatement $prepare;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -17,7 +17,7 @@ use Snowflake\Snowflake;
|
||||
class ArrayCondition extends Condition
|
||||
{
|
||||
|
||||
private $math = ['like', 'in', 'or', 'eq', 'neq', 'gt', 'ngt', 'lt', 'nlt'];
|
||||
private array $math = ['like', 'in', 'or', 'eq', 'neq', 'gt', 'ngt', 'lt', 'nlt'];
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -14,15 +14,15 @@ use Snowflake\Core\Str;
|
||||
abstract class Condition extends BaseObject
|
||||
{
|
||||
|
||||
protected $column = '';
|
||||
protected $opera = '=';
|
||||
protected string $column = '';
|
||||
protected string $opera = '=';
|
||||
|
||||
/** @var array|mixed */
|
||||
protected $value;
|
||||
|
||||
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
|
||||
|
||||
protected $attributes = [];
|
||||
protected array $attributes = [];
|
||||
|
||||
abstract public function builder();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Condition;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
|
||||
class LLikeCondition extends Condition
|
||||
{
|
||||
|
||||
public $pos = '';
|
||||
public string $pos = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
|
||||
class LikeCondition extends Condition
|
||||
{
|
||||
|
||||
public $pos = '';
|
||||
public string $pos = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Database\Condition;
|
||||
class MathematicsCondition extends Condition
|
||||
{
|
||||
|
||||
public $type = '';
|
||||
public string $type = '';
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
|
||||
class NotLikeCondition extends Condition
|
||||
{
|
||||
|
||||
public $pos = '';
|
||||
public string $pos = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Condition;
|
||||
|
||||
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
|
||||
class RLikeCondition extends Condition
|
||||
{
|
||||
|
||||
public $pos = '';
|
||||
public string $pos = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database;
|
||||
|
||||
|
||||
+2
-4
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/4 0004
|
||||
* Time: 15:40
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
use Database\Traits\QueryTrait;
|
||||
@@ -20,9 +20,7 @@ class Db
|
||||
{
|
||||
use QueryTrait;
|
||||
|
||||
private static $db;
|
||||
|
||||
private static $isActive = false;
|
||||
private static bool $isActive = false;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Date: 2018/4/4 0004
|
||||
* Time: 15:47
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database;
|
||||
|
||||
@@ -22,28 +23,30 @@ abstract class HasBase
|
||||
/** @var ActiveRecord|Collection */
|
||||
protected $data;
|
||||
|
||||
/** @var ActiveRecord */
|
||||
protected $model;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected string $model;
|
||||
|
||||
/** @var */
|
||||
protected $primaryId;
|
||||
|
||||
/** @var array */
|
||||
protected $value = [];
|
||||
protected array $value = [];
|
||||
|
||||
|
||||
/** @var Relation $_relation */
|
||||
protected $_relation;
|
||||
protected Relation $_relation;
|
||||
|
||||
/**
|
||||
* HasBase constructor.
|
||||
* @param ActiveRecord $model
|
||||
* @param $model
|
||||
* @param $primaryId
|
||||
* @param $value
|
||||
* @param Relation $relation
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($model, $primaryId, $value, $relation)
|
||||
public function __construct($model, $primaryId, $value, Relation $relation)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
if (empty($value)) $value = [];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/4 0004
|
||||
* Time: 13:58
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
use Exception;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/4 0004
|
||||
* Time: 13:47
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
use Exception;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/3/30 0030
|
||||
* Time: 14:39
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
* Time: 17:22
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Mysql;
|
||||
|
||||
|
||||
@@ -21,20 +23,42 @@ use Snowflake\Core\JSON;
|
||||
class Columns extends Component
|
||||
{
|
||||
|
||||
private $columns = [];
|
||||
/**
|
||||
* @var array
|
||||
* field types
|
||||
*/
|
||||
private array $columns = [];
|
||||
|
||||
/** @var Connection $db */
|
||||
public $db;
|
||||
public $table = '';
|
||||
private $_primary = [];
|
||||
private $_auto_increment = [];
|
||||
/**
|
||||
* @var Connection
|
||||
* Mysql client
|
||||
*/
|
||||
public Connection $db;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* tableName
|
||||
*/
|
||||
public string $table = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* field primary key
|
||||
*/
|
||||
private array $_primary = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* by mysql field auto_increment
|
||||
*/
|
||||
private array $_auto_increment = [];
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
public function table($table)
|
||||
public function table(string $table)
|
||||
{
|
||||
return $this->structure($this->table = $table);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Mysql;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Orm;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Orm;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Orm;
|
||||
|
||||
|
||||
+8
-12
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database;
|
||||
|
||||
@@ -19,28 +19,25 @@ class Pagination extends Component
|
||||
{
|
||||
|
||||
/** @var ActiveQuery */
|
||||
private $activeQuery;
|
||||
private ActiveQuery $activeQuery;
|
||||
|
||||
/** @var int 从第几个开始查 */
|
||||
private $_offset = 0;
|
||||
private int $_offset = 0;
|
||||
|
||||
/** @var int 每页数量 */
|
||||
private $_limit = 100;
|
||||
private int $_limit = 100;
|
||||
|
||||
/** @var int 最大查询数量 */
|
||||
private $_max = 0;
|
||||
private int $_max = 0;
|
||||
|
||||
/** @var int 当前已查询数量 */
|
||||
private $_length = 0;
|
||||
private int $_length = 0;
|
||||
|
||||
/** @var Closure */
|
||||
private $_callback;
|
||||
|
||||
/** @var Coroutine\Channel */
|
||||
private $_channel;
|
||||
private Closure $_callback;
|
||||
|
||||
/** @var Coroutine\WaitGroup */
|
||||
private $_group;
|
||||
private Coroutine\WaitGroup $_group;
|
||||
|
||||
/**
|
||||
* PaginationIteration constructor.
|
||||
@@ -51,7 +48,6 @@ class Pagination extends Component
|
||||
{
|
||||
parent::__construct($config);
|
||||
$this->activeQuery = $activeQuery;
|
||||
// $this->_channel = new Coroutine\Channel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database;
|
||||
|
||||
@@ -13,10 +13,10 @@ use Snowflake\Abstracts\Component;
|
||||
class Relation extends Component
|
||||
{
|
||||
|
||||
private $_relations = [];
|
||||
private array $_relations = [];
|
||||
|
||||
/** @var ActiveQuery[] $_query */
|
||||
private $_query = [];
|
||||
private array $_query = [];
|
||||
|
||||
/**
|
||||
* @param string $identification
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/6/27 0027
|
||||
* Time: 17:49
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database;
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/3/30 0030
|
||||
* Time: 14:56
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Database\Traits;
|
||||
|
||||
|
||||
@@ -20,21 +20,23 @@ use Exception;
|
||||
*/
|
||||
trait QueryTrait
|
||||
{
|
||||
public $where = [];
|
||||
public $select = [];
|
||||
public $join = [];
|
||||
public $order = [];
|
||||
public $offset = NULL;
|
||||
public $limit = NULL;
|
||||
public $group = '';
|
||||
public $from = '';
|
||||
public $alias = 't1';
|
||||
public $filter = [];
|
||||
public array $where = [];
|
||||
public array $select = [];
|
||||
public array $join = [];
|
||||
public array $order = [];
|
||||
public ?int $offset = NULL;
|
||||
public ?int $limit = NULL;
|
||||
public string $group = '';
|
||||
public string $from = '';
|
||||
public string $alias = 't1';
|
||||
public array $filter = [];
|
||||
|
||||
public $ifNotWhere = false;
|
||||
public bool $ifNotWhere = false;
|
||||
|
||||
/** @var ActiveRecord */
|
||||
public $modelClass;
|
||||
/**
|
||||
* @var ActiveRecord
|
||||
*/
|
||||
public ActiveRecord $modelClass;
|
||||
|
||||
/**
|
||||
* clear
|
||||
|
||||
Reference in New Issue
Block a user