ref
This commit is contained in:
@@ -29,16 +29,14 @@
|
||||
|
||||
namespace Espo\Classes\AppInfo;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Module,
|
||||
Binding\EspoBindingLoader,
|
||||
Binding\Binding as BindingItem,
|
||||
Console\Command\Params,
|
||||
};
|
||||
use Espo\Core\Binding\Binding as BindingItem;
|
||||
use Espo\Core\Binding\EspoBindingLoader;
|
||||
use Espo\Core\Console\Command\Params;
|
||||
use Espo\Core\Utils\Module;
|
||||
|
||||
class Binding
|
||||
{
|
||||
private $module;
|
||||
private Module $module;
|
||||
|
||||
public function __construct(Module $module)
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ class Binder
|
||||
* Bind an interface to an implementation.
|
||||
*
|
||||
* @param string $key An interface or interface with a parameter name (`Interface $name`).
|
||||
* @param string $implementationClassName An implementation class name.
|
||||
* @param class-string<object> $implementationClassName An implementation class name.
|
||||
*/
|
||||
public function bindImplementation(string $key, string $implementationClassName): self
|
||||
{
|
||||
@@ -117,7 +117,7 @@ class Binder
|
||||
* Bind an interface to a factory.
|
||||
*
|
||||
* @param string $key An interface or interface with a parameter name (`Interface $name`).
|
||||
* @param string $factoryClassName A factory class name.
|
||||
* @param class-string<Factory> $factoryClassName A factory class name.
|
||||
*/
|
||||
public function bindFactory(string $key, string $factoryClassName): self
|
||||
{
|
||||
@@ -134,7 +134,7 @@ class Binder
|
||||
/**
|
||||
* Creates a contextual binder and pass it as an argument of a callback.
|
||||
*
|
||||
* @param string $className A context.
|
||||
* @param class-string<object> $className A context.
|
||||
* @param Closure(ContextualBinder): void $callback A callback with a `ContextualBinder` argument.
|
||||
*/
|
||||
public function inContext(string $className, Closure $callback): self
|
||||
@@ -149,7 +149,7 @@ class Binder
|
||||
/**
|
||||
* Creates a contextual binder.
|
||||
*
|
||||
* @param string $className A context.
|
||||
* @param class-string<object> $className A context.
|
||||
*/
|
||||
public function for(string $className): ContextualBinder
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ class BindingContainerBuilder
|
||||
* Bind an interface to an implementation.
|
||||
*
|
||||
* @param string $key An interface or interface with a parameter name (`Interface $name`).
|
||||
* @param string $implementationClassName An implementation class name.
|
||||
* @param class-string<object> $implementationClassName An implementation class name.
|
||||
*/
|
||||
public function bindImplementation(string $key, string $implementationClassName): self
|
||||
{
|
||||
@@ -98,7 +98,7 @@ class BindingContainerBuilder
|
||||
* Bind an interface to a factory.
|
||||
*
|
||||
* @param string $key An interface or interface with a parameter name (`Interface $name`).
|
||||
* @param string $factoryClassName A factory class name.
|
||||
* @param class-string<Factory> $factoryClassName A factory class name.
|
||||
*/
|
||||
public function bindFactory(string $key, string $factoryClassName): self
|
||||
{
|
||||
@@ -110,7 +110,7 @@ class BindingContainerBuilder
|
||||
/**
|
||||
* Creates a contextual binder and pass it as an argument of a callback.
|
||||
*
|
||||
* @param string $className A context.
|
||||
* @param class-string<object> $className A context.
|
||||
* @param Closure(ContextualBinder): void $callback A callback with a `ContextualBinder` argument.
|
||||
*/
|
||||
public function inContext(string $className, Closure $callback): self
|
||||
|
||||
@@ -57,6 +57,9 @@ class BindingData
|
||||
$this->global->$key = $binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<object> $className
|
||||
*/
|
||||
public function hasContext(string $className, string $key): bool
|
||||
{
|
||||
if (!property_exists($this->context, $className)) {
|
||||
@@ -70,6 +73,9 @@ class BindingData
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<object> $className
|
||||
*/
|
||||
public function getContext(string $className, string $key): Binding
|
||||
{
|
||||
if (!$this->hasContext($className, $key)) {
|
||||
@@ -108,10 +114,11 @@ class BindingData
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @return class-string<object>[]
|
||||
*/
|
||||
public function getContextList(): array
|
||||
{
|
||||
/** @var class-string<object>[] */
|
||||
return array_keys(
|
||||
get_object_vars($this->context)
|
||||
);
|
||||
|
||||
@@ -34,8 +34,12 @@ use LogicException;
|
||||
class ContextualBinder
|
||||
{
|
||||
private BindingData $data;
|
||||
/** @var class-string<object> */
|
||||
private string $className;
|
||||
|
||||
/**
|
||||
* @param class-string<object> $className
|
||||
*/
|
||||
public function __construct(BindingData $data, string $className)
|
||||
{
|
||||
$this->data = $data;
|
||||
@@ -46,7 +50,7 @@ class ContextualBinder
|
||||
* Bind an interface to an implementation.
|
||||
*
|
||||
* @param string $key An interface or interface with a parameter name (`Interface $name`).
|
||||
* @param string $implementationClassName An implementation class name.
|
||||
* @param class-string<object> $implementationClassName An implementation class name.
|
||||
*/
|
||||
public function bindImplementation(string $key, string $implementationClassName): self
|
||||
{
|
||||
@@ -142,7 +146,7 @@ class ContextualBinder
|
||||
* Bind an interface to a factory.
|
||||
*
|
||||
* @param string $key An interface or interface with a parameter name (`Interface $name`).
|
||||
* @param string $factoryClassName A factory class name.
|
||||
* @param class-string<Factory> $factoryClassName A factory class name.
|
||||
*/
|
||||
public function bindFactory(string $key, string $factoryClassName): self
|
||||
{
|
||||
|
||||
@@ -45,7 +45,6 @@ class EspoBindingLoader implements BindingLoader
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
|
||||
$binder = new Binder($data);
|
||||
|
||||
(new Binding())->process($binder);
|
||||
|
||||
@@ -29,34 +29,26 @@
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\ClassFinder,
|
||||
InjectableFactory,
|
||||
ORM\Entity as BaseEntity,
|
||||
Binding\BindingContainer,
|
||||
Binding\BindingData,
|
||||
Binding\Binder,
|
||||
};
|
||||
use Espo\Core\Binding\Binder;
|
||||
use Espo\Core\Binding\BindingContainer;
|
||||
use Espo\Core\Binding\BindingData;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\ORM\Entity as BaseEntity;
|
||||
use Espo\Core\Utils\ClassFinder;
|
||||
|
||||
use Espo\ORM\{
|
||||
Entity,
|
||||
EntityManager,
|
||||
EntityFactory as EntityFactoryInterface,
|
||||
Value\ValueAccessorFactory,
|
||||
};
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityFactory as EntityFactoryInterface;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Value\ValueAccessorFactory;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class EntityFactory implements EntityFactoryInterface
|
||||
{
|
||||
private ClassFinder $classFinder;
|
||||
|
||||
private Helper $helper;
|
||||
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private ?EntityManager $entityManager = null;
|
||||
|
||||
private ?ValueAccessorFactory $valueAccessorFactory = null;
|
||||
|
||||
public function __construct(ClassFinder $classFinder, Helper $helper, InjectableFactory $injectableFactory)
|
||||
@@ -67,11 +59,11 @@ class EntityFactory implements EntityFactoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?class-string<\Espo\ORM\Entity>
|
||||
* @return ?class-string<Entity>
|
||||
*/
|
||||
private function getClassName(string $entityType): ?string
|
||||
{
|
||||
/** @var ?class-string<\Espo\ORM\Entity> */
|
||||
/** @var ?class-string<Entity> */
|
||||
return $this->classFinder->find('Entities', $entityType);
|
||||
}
|
||||
|
||||
@@ -117,7 +109,8 @@ class EntityFactory implements EntityFactoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $defs
|
||||
* @param class-string<Entity> $className
|
||||
* @param array<string, mixed> $defs
|
||||
*/
|
||||
private function getBindingContainer(string $className, string $entityType, array $defs): BindingContainer
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user