This commit is contained in:
2021-07-21 15:13:38 +08:00
parent 271dd20c16
commit 452f2e8766
2 changed files with 15 additions and 12 deletions
+14 -11
View File
@@ -24,6 +24,7 @@ use Database\Relation;
use Database\SqlBuilder;
use Database\Traits\HasBase;
use Exception;
use JetBrains\PhpStorm\Pure;
use ReflectionException;
use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config;
@@ -42,6 +43,7 @@ use validator\Validator;
* @property bool $isCreate
* @method rules()
* @method static tableName()
* @property Application $application
*/
abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
{
@@ -70,19 +72,12 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/** @var null|string */
protected ?string $primary = NULL;
/**
* @var array
*/
private array $_annotations = [];
/**
* @var Application|null
*/
protected ?Application $container;
/**
* @var bool
*/
@@ -107,6 +102,15 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/
private array $_with = [];
/**
* @return Application
*/
#[Pure] public function getApplication(): Application
{
return Snowflake::app();
}
/**
* @param $data
* @return ActiveRecord
@@ -154,7 +158,6 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/
public function init()
{
$this->container = Snowflake::app();
$an = Snowflake::app()->getAnnotation();
$an->injectProperty($this);
}
@@ -773,7 +776,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/**
* @param $name
* @param string|null $name
* @param string $method
* @return string|null
* @throws Exception
@@ -856,7 +859,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
* @param string $type
* @return array
*/
protected function getAnnotation($type = self::GET): array
protected function getAnnotation(string $type = self::GET): array
{
return $this->_annotations[$type] ?? [];
}
@@ -867,7 +870,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
* @param string $type
* @return bool
*/
protected function hasAnnotation($name, $type = self::GET): bool
protected function hasAnnotation($name, string $type = self::GET): bool
{
if (!isset($this->_annotations[$type])) {
return false;
+1 -1
View File
@@ -95,7 +95,7 @@ class Snowflake
* @param $name
* @return bool
*/
public static function has($name): bool
#[Pure] public static function has($name): bool
{
return static::$service->has($name);
}