改名
This commit is contained in:
@@ -16,6 +16,8 @@ themes/classic/views/
|
|||||||
out
|
out
|
||||||
gen
|
gen
|
||||||
|
|
||||||
|
db
|
||||||
|
|
||||||
composer.lock
|
composer.lock
|
||||||
|
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace Annotation\Model;
|
|
||||||
|
|
||||||
|
|
||||||
use Attribute;
|
|
||||||
use Exception;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Get
|
|
||||||
* @package Annotation\Model
|
|
||||||
*/
|
|
||||||
#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Annotation\Attribute
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get constructor.
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function __construct(public string $name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $class
|
|
||||||
* @param mixed|null $method
|
|
||||||
* @return bool
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function execute(mixed $class, mixed $method = null): bool
|
|
||||||
{
|
|
||||||
$annotation = Kiri::getAnnotation();
|
|
||||||
$annotation->addGets($class, $this->name, $method);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace Annotation\Model;
|
|
||||||
|
|
||||||
|
|
||||||
use Annotation\Attribute;
|
|
||||||
use Database\ActiveRecord;
|
|
||||||
use Exception;
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Relation
|
|
||||||
* @package Annotation\Model
|
|
||||||
*/
|
|
||||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Relation constructor.
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function __construct(public string $name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $class
|
|
||||||
* @param mixed|null $method
|
|
||||||
* @return bool
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function execute(mixed $class, mixed $method = null): bool
|
|
||||||
{
|
|
||||||
$annotation = Kiri::getAnnotation();
|
|
||||||
$annotation->addRelate($class, $this->name, $method);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace Annotation\Model;
|
|
||||||
|
|
||||||
|
|
||||||
use Annotation\Attribute;
|
|
||||||
use Database\ActiveRecord;
|
|
||||||
use Exception;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Set extends Attribute
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set constructor.
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function __construct(public string $name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $class
|
|
||||||
* @param mixed|null $method
|
|
||||||
* @return bool
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function execute(mixed $class, mixed $method = null): bool
|
|
||||||
{
|
|
||||||
$annotation = Kiri::getAnnotation();
|
|
||||||
$annotation->addSets($class, $this->name, $method);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+1
-1
@@ -33,7 +33,7 @@ class Command extends \Console\Command
|
|||||||
/** @var Gii $gii */
|
/** @var Gii $gii */
|
||||||
$gii = Kiri::app()->get('gii');
|
$gii = Kiri::app()->get('gii');
|
||||||
|
|
||||||
$connections = Kiri::app()->db;
|
$connections = Kiri::app()->get('db');
|
||||||
if ($dtl->exists('databases')) {
|
if ($dtl->exists('databases')) {
|
||||||
return $gii->run($connections->get($dtl->get('databases')), $dtl);
|
return $gii->run($connections->get($dtl->get('databases')), $dtl);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ class Gii
|
|||||||
return $this->makeByDatabases($make, $input);
|
return $this->makeByDatabases($make, $input);
|
||||||
}
|
}
|
||||||
$db = $this->input->get('databases', 'db');
|
$db = $this->input->get('databases', 'db');
|
||||||
$this->db = Kiri::app()->db->get($db);
|
$this->db = Kiri::app()->get('db')->get($db);
|
||||||
|
|
||||||
return $this->makeByDatabases($make, $input);
|
return $this->makeByDatabases($make, $input);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ namespace HttpServer;
|
|||||||
|
|
||||||
|
|
||||||
use Annotation\Inject;
|
use Annotation\Inject;
|
||||||
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Kiri\Abstracts\TraitApplication;
|
use Kiri\Abstracts\TraitApplication;
|
||||||
use Kiri\Application;
|
use Kiri\Application;
|
||||||
|
use Kiri\Di\Container;
|
||||||
|
use Kiri\Di\ContainerInterface;
|
||||||
|
use Kiri\Kiri;
|
||||||
use Server\RequestInterface;
|
use Server\RequestInterface;
|
||||||
use Server\ResponseInterface;
|
use Server\ResponseInterface;
|
||||||
|
|
||||||
@@ -22,14 +26,22 @@ class Controller
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Application $container
|
* @param Application $application
|
||||||
*/
|
*/
|
||||||
public function __construct(protected Application $container)
|
#[Pure] public function __construct(protected Application $application)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inject di container
|
||||||
|
*
|
||||||
|
* @var ContainerInterface|null
|
||||||
|
*/
|
||||||
|
#[Inject(ContainerInterface::class)]
|
||||||
|
public ?ContainerInterface $container = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inject request
|
* inject request
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ namespace Server;
|
|||||||
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Swoole\Coroutine\Channel;
|
use Swoole\Coroutine\Channel;
|
||||||
use const Grpc\CHANNEL_SHUTDOWN;
|
|
||||||
|
|
||||||
class ApplicationStore
|
class ApplicationStore
|
||||||
{
|
{
|
||||||
|
|||||||
+125
-3
@@ -3,8 +3,10 @@
|
|||||||
namespace Kiri\Di;
|
namespace Kiri\Di;
|
||||||
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
|
use ReflectionAttribute;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
|
use ReflectionProperty;
|
||||||
|
|
||||||
trait Attributes
|
trait Attributes
|
||||||
{
|
{
|
||||||
@@ -17,6 +19,20 @@ trait Attributes
|
|||||||
private array $_classProperty = [];
|
private array $_classProperty = [];
|
||||||
|
|
||||||
|
|
||||||
|
private array $_mapping = [
|
||||||
|
'attributeClass' => [
|
||||||
|
'className' => [
|
||||||
|
'property' => [
|
||||||
|
''
|
||||||
|
],
|
||||||
|
'method' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReflectionClass $class
|
* @param ReflectionClass $class
|
||||||
*/
|
*/
|
||||||
@@ -31,10 +47,65 @@ trait Attributes
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->_classTarget[$className][] = $attribute->newInstance();
|
$this->_classTarget[$className][] = $attribute->newInstance();
|
||||||
|
|
||||||
|
$this->setMappingClass($attribute, $className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReflectionAttribute $attribute
|
||||||
|
* @param string $class
|
||||||
|
*/
|
||||||
|
private function setMappingClass(ReflectionAttribute $attribute, string $class)
|
||||||
|
{
|
||||||
|
if (!isset($this->_mapping[$attribute->getName()])) {
|
||||||
|
$this->_mapping[$attribute->getName()] = [];
|
||||||
|
}
|
||||||
|
$this->_mapping[$attribute->getName()][$class] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReflectionAttribute $attribute
|
||||||
|
* @param string $class
|
||||||
|
* @param string $method
|
||||||
|
*/
|
||||||
|
private function setMappingMethod(ReflectionAttribute $attribute, string $class, string $method)
|
||||||
|
{
|
||||||
|
$this->setMappingClass($attribute, $class);
|
||||||
|
|
||||||
|
$mapping = $this->_mapping[$attribute->getName()][$class];
|
||||||
|
if (!isset($mapping['method'])) {
|
||||||
|
$mapping['method'] = [];
|
||||||
|
}
|
||||||
|
if (!in_array($method, $mapping['method'])) {
|
||||||
|
$mapping['method'][] = $method;
|
||||||
|
}
|
||||||
|
$this->_mapping[$attribute->getName()][$class] = $mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReflectionAttribute $attribute
|
||||||
|
* @param string $class
|
||||||
|
* @param string $property
|
||||||
|
*/
|
||||||
|
private function setMappingProperty(ReflectionAttribute $attribute, string $class, string $property)
|
||||||
|
{
|
||||||
|
$this->setMappingClass($attribute, $class);
|
||||||
|
|
||||||
|
$mapping = $this->_mapping[$attribute->getName()][$class];
|
||||||
|
if (!isset($mapping['property'])) {
|
||||||
|
$mapping['property'] = [];
|
||||||
|
}
|
||||||
|
if (!in_array($property, $mapping['property'])) {
|
||||||
|
$mapping['property'][] = $property;
|
||||||
|
}
|
||||||
|
$this->_mapping[$attribute->getName()][$class] = $mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $class
|
* @param mixed $class
|
||||||
* @return array
|
* @return array
|
||||||
@@ -65,6 +136,8 @@ trait Attributes
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->_classMethodNote[$className][$ReflectionMethod->getName()][] = $attribute->newInstance();
|
$this->_classMethodNote[$className][$ReflectionMethod->getName()][] = $attribute->newInstance();
|
||||||
|
|
||||||
|
$this->setMappingMethod($attribute, $className, $ReflectionMethod->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,19 +171,68 @@ trait Attributes
|
|||||||
{
|
{
|
||||||
$className = $class->getName();
|
$className = $class->getName();
|
||||||
$this->_classProperty[$className] = $this->_classPropertyNote[$className] = [];
|
$this->_classProperty[$className] = $this->_classPropertyNote[$className] = [];
|
||||||
foreach ($class->getProperties(\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PUBLIC |
|
foreach ($class->getProperties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PUBLIC |
|
||||||
\ReflectionProperty::IS_PROTECTED) as $ReflectionMethod) {
|
ReflectionProperty::IS_PROTECTED) as $ReflectionMethod) {
|
||||||
$this->_classProperty[$className][$ReflectionMethod->getName()] = $ReflectionMethod;
|
$this->_classProperty[$className][$ReflectionMethod->getName()] = $ReflectionMethod;
|
||||||
foreach ($ReflectionMethod->getAttributes() as $attribute) {
|
foreach ($ReflectionMethod->getAttributes() as $attribute) {
|
||||||
if (!class_exists($attribute->getName())) {
|
if (!class_exists($attribute->getName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->_classPropertyNote[$className][$ReflectionMethod->getName()] = $attribute->newInstance();
|
$this->_classPropertyNote[$className][$ReflectionMethod->getName()] = $attribute->newInstance();
|
||||||
|
|
||||||
|
$this->setMappingProperty($attribute, $className, $ReflectionMethod->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $attribute
|
||||||
|
* @param string|null $class
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function getAttributeTrees(string $attribute, string $class = null): array
|
||||||
|
{
|
||||||
|
$mapping = $this->_mapping[$attribute] ?? [];
|
||||||
|
if (empty($mapping) || empty($class)) {
|
||||||
|
return $mapping;
|
||||||
|
}
|
||||||
|
return $mapping[$class] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $attribute
|
||||||
|
* @param string $class
|
||||||
|
* @param string|null $method
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getMethodByAnnotation(string $attribute, string $class, string $method = null): array
|
||||||
|
{
|
||||||
|
$class = $this->getAttributeTrees($attribute, $class);
|
||||||
|
if (empty($class) || !isset($class['method']) || empty($method)) {
|
||||||
|
return $class['method'] ?? [];
|
||||||
|
}
|
||||||
|
return $class['method'][$method] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $attribute
|
||||||
|
* @param string $class
|
||||||
|
* @param string $method
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPropertyByAnnotation(string $attribute, string $class, string $method): array
|
||||||
|
{
|
||||||
|
$class = $this->getAttributeTrees($attribute, $class);
|
||||||
|
if (empty($class) || !isset($class['property'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return $class['property'][$method] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReflectionClass|string $class
|
* @param ReflectionClass|string $class
|
||||||
* @return array
|
* @return array
|
||||||
@@ -127,7 +249,7 @@ trait Attributes
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReflectionClass $class
|
* @param ReflectionClass $class
|
||||||
* @return \ReflectionProperty[]
|
* @return ReflectionProperty[]
|
||||||
*/
|
*/
|
||||||
#[Pure] public function getProperty(ReflectionClass $class): array
|
#[Pure] public function getProperty(ReflectionClass $class): array
|
||||||
{
|
{
|
||||||
|
|||||||
+12
-1
@@ -28,7 +28,7 @@ use Server\ResponseInterface;
|
|||||||
* Class Container
|
* Class Container
|
||||||
* @package Kiri\Di
|
* @package Kiri\Di
|
||||||
*/
|
*/
|
||||||
class Container extends BaseObject
|
class Container extends BaseObject implements ContainerInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
use Attributes;
|
use Attributes;
|
||||||
@@ -119,6 +119,17 @@ class Container extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $interface
|
||||||
|
* @param $object
|
||||||
|
*/
|
||||||
|
public function setBindings(string $interface, $object)
|
||||||
|
{
|
||||||
|
$this->_singletons[$interface] = $object;
|
||||||
|
$this->_interfaces[$interface] = get_class($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $class
|
* @param $class
|
||||||
* @param array $constrict
|
* @param array $constrict
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kiri\Di;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface ContainerInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
+463
-462
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user