改名
This commit is contained in:
+2
-1
@@ -8,6 +8,7 @@ namespace PHPSTORM_META {
|
|||||||
override(Container::get(0), map('@'));
|
override(Container::get(0), map('@'));
|
||||||
// override(\Hyperf\Utils\Context::get(0), map('@'));
|
// override(\Hyperf\Utils\Context::get(0), map('@'));
|
||||||
// override(\make(0), map('@'));
|
// override(\make(0), map('@'));
|
||||||
// override(\di(0), map('@'));
|
override(\di(0), map('@'));
|
||||||
|
override(\duplicate(0), map('@'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-6
@@ -7,6 +7,7 @@ namespace Annotation;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use ReflectionProperty;
|
use ReflectionProperty;
|
||||||
|
use Snowflake\Core\Str;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,16 +38,12 @@ use Snowflake\Snowflake;
|
|||||||
public function execute(mixed $class, mixed $method = null): bool
|
public function execute(mixed $class, mixed $method = null): bool
|
||||||
{
|
{
|
||||||
$injectValue = $this->parseInjectValue();
|
$injectValue = $this->parseInjectValue();
|
||||||
if (!($method instanceof ReflectionProperty)) {
|
if (!($method = $this->getProperty($class, $method))) {
|
||||||
$method = Snowflake::getDi()->getClassProperty($class, $method);
|
|
||||||
if (!$method) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** @var ReflectionProperty $class */
|
/** @var ReflectionProperty $class */
|
||||||
if ($method->isPrivate() || $method->isProtected()) {
|
if ($method->isPrivate() || $method->isProtected()) {
|
||||||
$method = 'set' . ucfirst($class->getName());
|
$method = 'set' . ucfirst(Str::convertUnderline($method->getName()));
|
||||||
if (!method_exists($class, $method)) {
|
if (!method_exists($class, $method)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -58,6 +55,24 @@ use Snowflake\Snowflake;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $class
|
||||||
|
* @param $method
|
||||||
|
* @return ReflectionProperty|bool
|
||||||
|
*/
|
||||||
|
private function getProperty($class, $method): ReflectionProperty|bool
|
||||||
|
{
|
||||||
|
if ($method instanceof ReflectionProperty) {
|
||||||
|
return $method;
|
||||||
|
}
|
||||||
|
$method = Snowflake::getDi()->getClassProperty($class, $method);
|
||||||
|
if (!$method) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $method;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
|||||||
*
|
*
|
||||||
* @param $query
|
* @param $query
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param null|string|ActiveRecord $model
|
* @param string|ActiveRecord|null $model
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($query, array $array = [], $model = null)
|
public function __construct($query, array $array = [], string|ActiveRecord $model = null)
|
||||||
{
|
{
|
||||||
$this->_item = $array;
|
$this->_item = $array;
|
||||||
$this->query = $query;
|
$this->query = $query;
|
||||||
@@ -111,7 +111,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
|||||||
public function getModel(): ActiveRecord
|
public function getModel(): ActiveRecord
|
||||||
{
|
{
|
||||||
if (!is_object($this->model)) {
|
if (!is_object($this->model)) {
|
||||||
$this->model = $this->model::populate([]);
|
$this->model = duplicate($this->model);
|
||||||
$this->model->setIsCreate(false);
|
$this->model->setIsCreate(false);
|
||||||
}
|
}
|
||||||
return $this->model;
|
return $this->model;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ use Database\Relation;
|
|||||||
use Database\SqlBuilder;
|
use Database\SqlBuilder;
|
||||||
use Database\Traits\HasBase;
|
use Database\Traits\HasBase;
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Http\Context;
|
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\Component;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
@@ -141,13 +140,21 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Relation $relation
|
||||||
|
*/
|
||||||
|
public function setRelation(Relation $relation)
|
||||||
|
{
|
||||||
|
$this->_relation = $relation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->container = Snowflake::app();
|
$this->container = Snowflake::app();
|
||||||
|
|
||||||
$an = Snowflake::app()->getAnnotation();
|
$an = Snowflake::app()->getAnnotation();
|
||||||
$an->injectProperty($this);
|
$an->injectProperty($this);
|
||||||
}
|
}
|
||||||
@@ -1010,12 +1017,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public static function populate(array $data): static
|
public static function populate(array $data): static
|
||||||
{
|
{
|
||||||
// $class = Snowflake::app()->getChannel();
|
$model = duplicate(static::class);
|
||||||
// /** @var static $model */
|
|
||||||
// $model = $class->pop(static::class, function () {
|
|
||||||
// return new static();
|
|
||||||
// });
|
|
||||||
$model = new static();
|
|
||||||
$model->_attributes = $data;
|
$model->_attributes = $data;
|
||||||
$model->_oldAttributes = $data;
|
$model->_oldAttributes = $data;
|
||||||
$model->setIsCreate(false);
|
$model->setIsCreate(false);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class CollectionIterator extends \ArrayIterator
|
|||||||
* @param int $flags
|
* @param int $flags
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($model, $query, $array = array(), $flags = 0)
|
public function __construct($model, $query, array $array = [], int $flags = 0)
|
||||||
{
|
{
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
$this->query = $query;
|
$this->query = $query;
|
||||||
|
|||||||
@@ -262,4 +262,16 @@ class Str
|
|||||||
return preg_replace('/(\w{10})(\w{3})(\w{4})(\w{9})(\w{6})/', '$1-$2-$3-$4-$5', $md5);
|
return preg_replace('/(\w{10})(\w{3})(\w{4})(\w{9})(\w{6})/', '$1-$2-$3-$4-$5', $md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $str
|
||||||
|
* @param bool $unfairest
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function convertUnderline(string $str, bool $unfairest = true): string
|
||||||
|
{
|
||||||
|
$str = ucwords(str_replace('_', ' ', $str));
|
||||||
|
$str = str_replace(' ', '', lcfirst($str));
|
||||||
|
return $unfairest ? ucfirst($str) : $str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-1
@@ -21,6 +21,7 @@ use Snowflake\Core\Json;
|
|||||||
use Snowflake\Error\Logger;
|
use Snowflake\Error\Logger;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Exception\ConfigException;
|
use Snowflake\Exception\ConfigException;
|
||||||
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use Swoole\WebSocket\Server;
|
use Swoole\WebSocket\Server;
|
||||||
|
|
||||||
@@ -681,13 +682,47 @@ if (!function_exists('env')) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('di')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @return mixed
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws NotFindClassException
|
||||||
|
*/
|
||||||
|
function di(string $className): mixed
|
||||||
|
{
|
||||||
|
return Snowflake::getDi()->get($className);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('duplicate')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @return mixed
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws NotFindClassException
|
||||||
|
*/
|
||||||
|
function duplicate(string $className): mixed
|
||||||
|
{
|
||||||
|
$class = di($className);
|
||||||
|
return clone $class;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('sweep')) {
|
if (!function_exists('sweep')) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $configPath
|
* @param string $configPath
|
||||||
* @return array|false|string|null
|
* @return array|false|string|null
|
||||||
*/
|
*/
|
||||||
function sweep($configPath = APP_PATH . 'config'): bool|array|string|null
|
function sweep(string $configPath = APP_PATH . 'config'): bool|array|string|null
|
||||||
{
|
{
|
||||||
$array = [];
|
$array = [];
|
||||||
foreach (glob($configPath . '/*') as $config) {
|
foreach (glob($configPath . '/*') as $config) {
|
||||||
|
|||||||
Reference in New Issue
Block a user