改名
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Database;
|
|||||||
use Database\Base\BaseActiveRecord;
|
use Database\Base\BaseActiveRecord;
|
||||||
use Database\Traits\HasBase;
|
use Database\Traits\HasBase;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\Pure;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Channel;
|
use Snowflake\Channel;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
@@ -167,8 +168,9 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
* @return static
|
* @return static
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private static function getModelClass(): static
|
#[Pure] private static function getModelClass(): static
|
||||||
{
|
{
|
||||||
|
return new static();
|
||||||
$className = get_called_class();
|
$className = get_called_class();
|
||||||
/** @var Channel $channel */
|
/** @var Channel $channel */
|
||||||
$channel = Snowflake::app()->get('channel');
|
$channel = Snowflake::app()->get('channel');
|
||||||
@@ -305,7 +307,7 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
{
|
{
|
||||||
$data = $this->_attributes;
|
$data = $this->_attributes;
|
||||||
|
|
||||||
$lists = Snowflake::getAnnotation()->getModelMethods(get_called_class());
|
$lists = Snowflake::getAnnotation()->getModelMethods(static::class);
|
||||||
foreach ($lists as $key => $item) {
|
foreach ($lists as $key => $item) {
|
||||||
$data[$key] = $this->{$item}($data[$key] ?? null);
|
$data[$key] = $this->{$item}($data[$key] ?? null);
|
||||||
}
|
}
|
||||||
@@ -334,10 +336,10 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
* @param string $modelName
|
* @param string $modelName
|
||||||
* @param $foreignKey
|
* @param $foreignKey
|
||||||
* @param $localKey
|
* @param $localKey
|
||||||
* @return ActiveQuery
|
* @return HasOne|ActiveQuery
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function hasOne(string $modelName, $foreignKey, $localKey): mixed
|
public function hasOne(string $modelName, $foreignKey, $localKey): HasOne|ActiveQuery
|
||||||
{
|
{
|
||||||
if (!$this->has($localKey)) {
|
if (!$this->has($localKey)) {
|
||||||
throw new Exception("Need join table primary key.");
|
throw new Exception("Need join table primary key.");
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public static function find(): ActiveQuery
|
public static function find(): ActiveQuery
|
||||||
{
|
{
|
||||||
return Snowflake::createObject(ActiveQuery::class, [get_called_class()]);
|
return Snowflake::createObject(ActiveQuery::class, [static::class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -728,11 +728,12 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getRelate($name): mixed
|
public function getRelate($name): mixed
|
||||||
{
|
{
|
||||||
if (empty($this->_relate[$name])) {
|
if (empty($this->_relate[$name])) {
|
||||||
$this->_relate = Snowflake::getAnnotation()->getRelateMethods(get_called_class());
|
$this->_relate = Snowflake::getAnnotation()->getRelateMethods(static::class);
|
||||||
}
|
}
|
||||||
return $this->_relate[$name] ?? null;
|
return $this->_relate[$name] ?? null;
|
||||||
}
|
}
|
||||||
@@ -827,7 +828,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
parent::__set($name, $value);
|
parent::__set($name, $value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$method = annotation()->getSetMethodName(get_called_class(), $name);
|
$method = annotation()->getSetMethodName(static::class, $name);
|
||||||
if (!empty($method)) {
|
if (!empty($method)) {
|
||||||
$value = $this->{$method}($value);
|
$value = $this->{$method}($value);
|
||||||
}
|
}
|
||||||
@@ -845,7 +846,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
$value = $this->_attributes[$name] ?? null;
|
$value = $this->_attributes[$name] ?? null;
|
||||||
|
|
||||||
$loader = Snowflake::app()->getAnnotation();
|
$loader = Snowflake::app()->getAnnotation();
|
||||||
if (!empty($method = $loader->getGetMethodName(get_called_class(), $name))) {
|
if (!empty($method = $loader->getGetMethodName(static::class, $name))) {
|
||||||
return $this->{$method}(...[$value]);
|
return $this->{$method}(...[$value]);
|
||||||
}
|
}
|
||||||
if (array_key_exists($name, $this->_attributes)) {
|
if (array_key_exists($name, $this->_attributes)) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ abstract class HttpService extends Component
|
|||||||
if (property_exists($this, $name)) {
|
if (property_exists($this, $name)) {
|
||||||
return $this->$name;
|
return $this->$name;
|
||||||
}
|
}
|
||||||
$message = sprintf('method %s::%s not exists.', get_called_class(), $name);
|
$message = sprintf('method %s::%s not exists.', static::class, $name);
|
||||||
throw new Exception($message);
|
throw new Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class BaseObject implements Configure
|
|||||||
*/
|
*/
|
||||||
#[Pure] public static function className(): string
|
#[Pure] public static function className(): string
|
||||||
{
|
{
|
||||||
return get_called_class();
|
return static::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,7 +80,7 @@ class BaseObject implements Configure
|
|||||||
if (method_exists($this, $method)) {
|
if (method_exists($this, $method)) {
|
||||||
$this->{$method}($value);
|
$this->{$method}($value);
|
||||||
} else {
|
} else {
|
||||||
$this->error('set ' . $name . ' not exists ' . get_called_class());
|
$this->error('set ' . $name . ' not exists ' . static::class);
|
||||||
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
|
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ abstract class Process extends \Swoole\Process implements SProcess
|
|||||||
*/
|
*/
|
||||||
#[Pure] private function getPrefix(): string
|
#[Pure] private function getPrefix(): string
|
||||||
{
|
{
|
||||||
return get_called_class();
|
return static::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ abstract class BaseValidator
|
|||||||
} else if (property_exists($this, $name)) {
|
} else if (property_exists($this, $name)) {
|
||||||
$this->$name = $value;
|
$this->$name = $value;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('unknown property ' . $name . ' in class ' . get_called_class());
|
throw new Exception('unknown property ' . $name . ' in class ' . static::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user