Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-08 18:49:06 +08:00
parent 614b601afa
commit ef3e874c0c
55 changed files with 29 additions and 92 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace Database\Note; namespace Database\Annotation;
use Attribute; use Attribute;
@@ -11,9 +11,9 @@ use Exception;
/** /**
* Class Get * Class Get
* @package Note\Model * @package Annotation\Model
*/ */
#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Note\Attribute #[Attribute(Attribute::TARGET_METHOD)] class Get extends \Annotation\Attribute
{ {
@@ -1,17 +1,17 @@
<?php <?php
namespace Database\Note; namespace Database\Annotation;
use Note\Attribute; use Kiri\Annotation\Attribute;
use Database\Base\Relate; use Database\Base\Relate;
use Exception; use Exception;
/** /**
* Class Relation * Class Relation
* @package Note\Model * @package Annotation\Model
*/ */
#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute #[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute
{ {
+2 -2
View File
@@ -1,10 +1,10 @@
<?php <?php
namespace Database\Note; namespace Database\Annotation;
use Note\Attribute; use Kiri\Annotation\Attribute;
use Database\Base\Setter; use Database\Base\Setter;
use Exception; use Exception;
+7 -7
View File
@@ -198,7 +198,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/ */
public function init() public function init()
{ {
$an = Kiri::app()->getNote(); $an = Kiri::app()->getAnnotation();
$an->injectProperty($this); $an->injectProperty($this);
} }
@@ -429,7 +429,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/ */
public function getConnection(): Connection public function getConnection(): Connection
{ {
return Kiri::app()->get('db')->get($this->connection); return Kiri::app()->get($this->connection);
} }
@@ -679,8 +679,8 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/ */
public function getAttribute(string $name) public function getAttribute(string $name)
{ {
if ($this->hasNote($name)) { if ($this->hasAnnotation($name)) {
return $this->runNote($name, $this->_attributes[$name]); return $this->runAnnotation($name, $this->_attributes[$name]);
} }
return $this->_attributes[$name] ?? NULL; return $this->_attributes[$name] ?? NULL;
} }
@@ -692,7 +692,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
* @param string $type * @param string $type
* @return mixed * @return mixed
*/ */
protected function runNote(string $name, mixed $value, string $type = self::GET): mixed protected function runAnnotation(string $name, mixed $value, string $type = self::GET): mixed
{ {
return call_user_func($this->_annotations[$type][$name], $value); return call_user_func($this->_annotations[$type][$name], $value);
} }
@@ -919,7 +919,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
* @param string $type * @param string $type
* @return array * @return array
*/ */
protected function getNote(string $type = self::GET): array protected function getAnnotation(string $type = self::GET): array
{ {
return $this->_annotations[$type] ?? []; return $this->_annotations[$type] ?? [];
} }
@@ -930,7 +930,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
* @param string $type * @param string $type
* @return bool * @return bool
*/ */
protected function hasNote($name, string $type = self::GET): bool protected function hasAnnotation($name, string $type = self::GET): bool
{ {
if (!isset($this->_annotations[$type])) { if (!isset($this->_annotations[$type])) {
return FALSE; return FALSE;
View File
+2 -23
View File
@@ -22,7 +22,7 @@ use Kiri\Abstracts\Config;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
use Kiri\Kiri; use Kiri\Kiri;
use Note\Inject; use Kiri\Annotation\Inject;
use ReflectionException; use ReflectionException;
use Server\Events\OnWorkerExit; use Server\Events\OnWorkerExit;
use Server\Events\OnWorkerStop; use Server\Events\OnWorkerStop;
@@ -68,11 +68,7 @@ class Connection extends Component
public array $attributes = []; public array $attributes = [];
/** private ?Schema $_schema = null;
* @var Schema
*/
#[Inject(Schema::class)]
public Schema $_schema;
/** /**
@@ -86,12 +82,6 @@ class Connection extends Component
$this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0); $this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$this->eventProvider->on(Rollback::class, [$this, 'rollback'], 0); $this->eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
$this->eventProvider->on(Commit::class, [$this, 'commit'], 0); $this->eventProvider->on(Commit::class, [$this, 'commit'], 0);
if (Db::transactionsActive()) {
$this->beginTransaction();
}
$this->_schema->db = $this;
} }
@@ -106,17 +96,6 @@ class Connection extends Component
} }
/**
* @param $config
* @return $this
*/
public function configure($config): static
{
Kiri::configure($this, $config);
return $this;
}
/** /**
* @throws Exception * @throws Exception
*/ */
@@ -8,7 +8,6 @@ use Exception;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Abstracts\Providers; use Kiri\Abstracts\Providers;
use Kiri\Application; use Kiri\Application;
use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Server\Events\OnWorkerStart; use Server\Events\OnWorkerStart;
@@ -20,8 +19,6 @@ use Server\Events\OnWorkerStart;
class DatabasesProviders extends Providers class DatabasesProviders extends Providers
{ {
private array $_pooLength = ['min' => 0, 'max' => 1];
/** /**
* @param Application $application * @param Application $application
@@ -29,10 +26,6 @@ class DatabasesProviders extends Providers
*/ */
public function onImport(Application $application) public function onImport(Application $application)
{ {
$application->set('db', $this);
$this->_pooLength = Config::get('databases.pool', ['min' => 0, 'max' => 1]);
$this->eventProvider->on(OnWorkerStart::class, [$this, 'createPool']); $this->eventProvider->on(OnWorkerStart::class, [$this, 'createPool']);
} }
@@ -40,14 +33,11 @@ class DatabasesProviders extends Providers
/** /**
* @param $name * @param $name
* @return Connection * @return Connection
* @throws ConfigException
* @throws Exception * @throws Exception
*/ */
public function get($name): Connection public function get($name): Connection
{ {
$config = $this->_settings($this->getConfig($name)); return Kiri::app()->get($name);
return Kiri::getDi()->get(Connection::class)->configure($config);
} }
@@ -61,10 +51,15 @@ class DatabasesProviders extends Providers
if (empty($databases)) { if (empty($databases)) {
return; return;
} }
$connection = Kiri::getDi()->get(Connection::class);
foreach ($databases as $database) { $app = Kiri::app();
/** @var Connection $connection */ foreach ($databases as $key => $database) {
$connection->configure($database)->fill(); $database = $this->_settings($database);
$connection = Kiri::getDi()->create(Connection::class, $database);
$connection->fill();
$app->set($key, $connection);
} }
} }
@@ -93,15 +88,4 @@ class DatabasesProviders extends Providers
} }
/**
* @param $name
* @return mixed
* @throws ConfigException
*/
public function getConfig($name): mixed
{
return Config::get('databases.connections.' . $name, null, true);
}
} }
View File
View File
View File
View File
View File
View File
View File
View File
@@ -195,7 +195,7 @@ trait QueryTrait
* @param string $column * @param string $column
* @return $this * @return $this
*/ */
public function whereNotEmpty(string $column): static public function whereAnnotationmpty(string $column): static
{ {
$this->where[] = $column . ' <> \'\''; $this->where[] = $column . ' <> \'\'';
return $this; return $this;
+1 -1
View File
@@ -17,7 +17,7 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Database\\": "src/" "Database\\": "./"
} }
}, },
"require-dev": { "require-dev": {
-26
View File
@@ -1,26 +0,0 @@
<?php
namespace Database;
use Database\Model;
/**
*
*/
class TestModel extends Model
{
protected string $connection = '';
protected string $table = '';
public ?string $primary = '';
}
TestModel::query()->get();