Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Database\Note;
|
||||
namespace Database\Annotation;
|
||||
|
||||
|
||||
use Attribute;
|
||||
@@ -11,9 +11,9 @@ use Exception;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
|
||||
namespace Database\Note;
|
||||
namespace Database\Annotation;
|
||||
|
||||
|
||||
use Note\Attribute;
|
||||
use Kiri\Annotation\Attribute;
|
||||
use Database\Base\Relate;
|
||||
use Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Class Relation
|
||||
* @package Note\Model
|
||||
* @package Annotation\Model
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute
|
||||
{
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Database\Note;
|
||||
namespace Database\Annotation;
|
||||
|
||||
|
||||
use Note\Attribute;
|
||||
use Kiri\Annotation\Attribute;
|
||||
use Database\Base\Setter;
|
||||
use Exception;
|
||||
|
||||
@@ -198,7 +198,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$an = Kiri::app()->getNote();
|
||||
$an = Kiri::app()->getAnnotation();
|
||||
$an->injectProperty($this);
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if ($this->hasNote($name)) {
|
||||
return $this->runNote($name, $this->_attributes[$name]);
|
||||
if ($this->hasAnnotation($name)) {
|
||||
return $this->runAnnotation($name, $this->_attributes[$name]);
|
||||
}
|
||||
return $this->_attributes[$name] ?? NULL;
|
||||
}
|
||||
@@ -692,7 +692,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
* @param string $type
|
||||
* @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);
|
||||
}
|
||||
@@ -919,7 +919,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function getNote(string $type = self::GET): array
|
||||
protected function getAnnotation(string $type = self::GET): array
|
||||
{
|
||||
return $this->_annotations[$type] ?? [];
|
||||
}
|
||||
@@ -930,7 +930,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
* @param string $type
|
||||
* @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])) {
|
||||
return FALSE;
|
||||
@@ -22,7 +22,7 @@ use Kiri\Abstracts\Config;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Kiri\Exception\NotFindClassException;
|
||||
use Kiri\Kiri;
|
||||
use Note\Inject;
|
||||
use Kiri\Annotation\Inject;
|
||||
use ReflectionException;
|
||||
use Server\Events\OnWorkerExit;
|
||||
use Server\Events\OnWorkerStop;
|
||||
@@ -68,11 +68,7 @@ class Connection extends Component
|
||||
public array $attributes = [];
|
||||
|
||||
|
||||
/**
|
||||
* @var Schema
|
||||
*/
|
||||
#[Inject(Schema::class)]
|
||||
public Schema $_schema;
|
||||
private ?Schema $_schema = null;
|
||||
|
||||
|
||||
/**
|
||||
@@ -86,12 +82,6 @@ class Connection extends Component
|
||||
$this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
|
||||
$this->eventProvider->on(Rollback::class, [$this, 'rollback'], 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
|
||||
*/
|
||||
@@ -8,7 +8,6 @@ use Exception;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Abstracts\Providers;
|
||||
use Kiri\Application;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Server\Events\OnWorkerStart;
|
||||
@@ -20,8 +19,6 @@ use Server\Events\OnWorkerStart;
|
||||
class DatabasesProviders extends Providers
|
||||
{
|
||||
|
||||
private array $_pooLength = ['min' => 0, 'max' => 1];
|
||||
|
||||
|
||||
/**
|
||||
* @param Application $application
|
||||
@@ -29,10 +26,6 @@ class DatabasesProviders extends Providers
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
|
||||
@@ -40,14 +33,11 @@ class DatabasesProviders extends Providers
|
||||
/**
|
||||
* @param $name
|
||||
* @return Connection
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get($name): Connection
|
||||
{
|
||||
$config = $this->_settings($this->getConfig($name));
|
||||
|
||||
return Kiri::getDi()->get(Connection::class)->configure($config);
|
||||
return Kiri::app()->get($name);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,10 +51,15 @@ class DatabasesProviders extends Providers
|
||||
if (empty($databases)) {
|
||||
return;
|
||||
}
|
||||
$connection = Kiri::getDi()->get(Connection::class);
|
||||
foreach ($databases as $database) {
|
||||
/** @var Connection $connection */
|
||||
$connection->configure($database)->fill();
|
||||
|
||||
$app = Kiri::app();
|
||||
foreach ($databases as $key => $database) {
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -195,7 +195,7 @@ trait QueryTrait
|
||||
* @param string $column
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotEmpty(string $column): static
|
||||
public function whereAnnotationmpty(string $column): static
|
||||
{
|
||||
$this->where[] = $column . ' <> \'\'';
|
||||
return $this;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Database\\": "src/"
|
||||
"Database\\": "./"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user