This commit is contained in:
2021-07-21 11:25:31 +08:00
parent 3b05c856ef
commit 8f6079b040
9 changed files with 201 additions and 112 deletions
+19 -8
View File
@@ -11,6 +11,7 @@ namespace Database\Base;
use Annotation\Event;
use Annotation\Inject;
use ArrayAccess;
use Database\ActiveQuery;
use Database\ActiveRecord;
@@ -71,9 +72,15 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
protected ?string $primary = NULL;
/**
* @var array
*/
private array $_annotations = [];
/**
* @var Application|null
*/
protected ?Application $container;
@@ -82,11 +89,23 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/
protected bool $isNewExample = TRUE;
/**
* @var array
*/
protected array $actions = [];
/**
* @var Relation|null
*/
#[Inject(Relation::class)]
protected ?Relation $_relation;
/**
* @var array
*/
private array $_with = [];
/**
@@ -123,19 +142,11 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/**
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public function init()
{
$this->container = Snowflake::app();
if (!Context::hasContext(Relation::class)) {
$relation = Snowflake::createObject(Relation::class);
$this->_relation = Context::setContext(Relation::class, $relation);
} else {
$this->_relation = Context::getContext(Relation::class);
}
}
+1 -2
View File
@@ -7,6 +7,7 @@ namespace Database;
use Annotation\IAnnotation;
use Exception;
use ReflectionException;
use Server\Constant;
use Snowflake\Abstracts\Providers;
use Snowflake\Application;
use Snowflake\Event;
@@ -38,7 +39,6 @@ class DatabasesProviders extends Providers
$this->_pooLength = Config::get('databases.pool', ['min' => 0, 'max' => 1]);
Event::on(Event::SERVER_TASK_START, [$this, 'createPool']);
Event::on(Event::SERVER_WORKER_START, [$this, 'createPool']);
}
@@ -80,7 +80,6 @@ class DatabasesProviders extends Providers
/**
* @param $database
* @return array
* @throws \Snowflake\Exception\ConfigException
*/
private function _settings($database): array
{