diff --git a/application/Espo/Core/Binding/Binder.php b/application/Espo/Core/Binding/Binder.php index a8d37f4690..e58294a1f9 100644 --- a/application/Espo/Core/Binding/Binder.php +++ b/application/Espo/Core/Binding/Binder.php @@ -46,7 +46,7 @@ class Binder * @param $key An interface or interface with a parameter name (`Interface $name`). * @param $implementationClassName An implementation class name. */ - public function bindImplementation(string $key, string $implementationClassName) : self + public function bindImplementation(string $key, string $implementationClassName): self { if (!$key || $key[0] === '$') { throw new LogicException("Can't binding a parameter name globally."); @@ -66,7 +66,7 @@ class Binder * @param $key An interface or interface with a parameter name (`Interface $name`). * @param $serviceName A service name. */ - public function bindService(string $key, string $serviceName) : self + public function bindService(string $key, string $serviceName): self { if (!$key || $key[0] === '$') { throw new LogicException("Can't binding a parameter name globally."); @@ -86,7 +86,7 @@ class Binder * @param $key An interface or interface with a parameter name (`Interface $name`). * @param $callback A callback that will resolve a dependency. */ - public function bindCallback(string $key, callable $callback) : self + public function bindCallback(string $key, callable $callback): self { if (!$key || $key[0] === '$') { throw new LogicException("Can't binding a parameter name globally."); @@ -105,7 +105,7 @@ class Binder * * @param $className A context. */ - public function for(string $className) : ContextualBinder + public function for(string $className): ContextualBinder { return new ContextualBinder($this->data, $className); } diff --git a/application/Espo/Core/Binding/Binding.php b/application/Espo/Core/Binding/Binding.php index 1da7fbe2a5..67efc8379b 100644 --- a/application/Espo/Core/Binding/Binding.php +++ b/application/Espo/Core/Binding/Binding.php @@ -51,7 +51,7 @@ class Binding $this->value = $value; } - public function getType() : int + public function getType(): int { return $this->type; } @@ -61,7 +61,7 @@ class Binding return $this->value; } - public static function createFromImplementationClassName(string $implementationClassName) : self + public static function createFromImplementationClassName(string $implementationClassName): self { if (!$implementationClassName) { throw new LogicException("Bad binding."); @@ -70,7 +70,7 @@ class Binding return new self(self::IMPLEMENTATION_CLASS_NAME, $implementationClassName); } - public static function createFromServiceName(string $serviceName) : self + public static function createFromServiceName(string $serviceName): self { if (!$serviceName) { throw new LogicException("Bad binding."); @@ -79,12 +79,12 @@ class Binding return new self(self::CONTAINER_SERVICE, $serviceName); } - public static function createFromValue($value) : self + public static function createFromValue($value): self { return new self(self::VALUE, $value); } - public static function createFromCallback(callable $callback) : self + public static function createFromCallback(callable $callback): self { return new self(self::CALLBACK, $callback); } diff --git a/application/Espo/Core/Binding/BindingContainer.php b/application/Espo/Core/Binding/BindingContainer.php index 748d97d1af..8e9bd2f80e 100644 --- a/application/Espo/Core/Binding/BindingContainer.php +++ b/application/Espo/Core/Binding/BindingContainer.php @@ -35,14 +35,14 @@ use LogicException; class BindingContainer { - protected $data; + private $data; - public function __construct(BindingLoader $loader) + public function __construct(BindingData $data) { - $this->data = $loader->load(); + $this->data = $data; } - public function has(?ReflectionClass $class, ReflectionParameter $param) : bool + public function has(?ReflectionClass $class, ReflectionParameter $param): bool { if ($this->getInternal($class, $param) === null) { return false; @@ -51,7 +51,7 @@ class BindingContainer return true; } - public function get(?ReflectionClass $class, ReflectionParameter $param) : Binding + public function get(?ReflectionClass $class, ReflectionParameter $param): Binding { if (!$this->has($class, $param)) { throw new LogicException("BindingContainer: Can't get not existing binding."); @@ -60,7 +60,7 @@ class BindingContainer return $this->getInternal($class, $param); } - protected function getInternal(?ReflectionClass $class, ReflectionParameter $param) : ?Binding + private function getInternal(?ReflectionClass $class, ReflectionParameter $param): ?Binding { $className = null; diff --git a/application/Espo/Core/Binding/BindingData.php b/application/Espo/Core/Binding/BindingData.php index 82702b246d..d61cec0c75 100644 --- a/application/Espo/Core/Binding/BindingData.php +++ b/application/Espo/Core/Binding/BindingData.php @@ -52,12 +52,12 @@ class BindingData $this->context->$className->$key = $binding; } - public function addGlobal(string $key, Binding $binding) + public function addGlobal(string $key, Binding $binding): void { $this->global->$key = $binding; } - public function hasContext(string $className, string $key) : bool + public function hasContext(string $className, string $key): bool { if (!property_exists($this->context, $className)) { return false; @@ -70,7 +70,7 @@ class BindingData return true; } - public function getContext(string $className, string $key) : Binding + public function getContext(string $className, string $key): Binding { if (!$this->hasContext($className, $key)) { throw new LogicException("No data."); @@ -79,7 +79,7 @@ class BindingData return $this->context->$className->$key; } - public function hasGlobal(string $key) : bool + public function hasGlobal(string $key): bool { if (!property_exists($this->global, $key)) { return false; @@ -88,7 +88,7 @@ class BindingData return true; } - public function getGlobal(string $key) : Binding + public function getGlobal(string $key): Binding { if (!$this->hasGlobal($key)) { throw new LogicException("No data."); @@ -97,21 +97,21 @@ class BindingData return $this->global->$key; } - public function getGlobalKeyList() : array + public function getGlobalKeyList(): array { return array_keys( get_object_vars($this->global) ); } - public function getContextList() : array + public function getContextList(): array { return array_keys( get_object_vars($this->context) ); } - public function getContextKeyList(string $context) : array + public function getContextKeyList(string $context): array { return array_keys( get_object_vars($this->context->$context ?? (object) []) diff --git a/application/Espo/Core/Binding/BindingLoader.php b/application/Espo/Core/Binding/BindingLoader.php index bc0fea83c0..c03349311f 100644 --- a/application/Espo/Core/Binding/BindingLoader.php +++ b/application/Espo/Core/Binding/BindingLoader.php @@ -31,5 +31,5 @@ namespace Espo\Core\Binding; interface BindingLoader { - public function load() : BindingData; + public function load(): BindingData; } diff --git a/application/Espo/Core/Binding/BindingProcessor.php b/application/Espo/Core/Binding/BindingProcessor.php new file mode 100644 index 0000000000..1608b5bfeb --- /dev/null +++ b/application/Espo/Core/Binding/BindingProcessor.php @@ -0,0 +1,35 @@ +data->addContext( $this->className, @@ -108,7 +108,7 @@ class ContextualBinder * @param $key An interface, parameter name (`$name`) or interface with a parameter name (`Interface $name`). * @param $callback A callback that will resolve a dependency. */ - public function bindCallback(string $key, callable $callback) : self + public function bindCallback(string $key, callable $callback): self { $this->data->addContext( $this->className, diff --git a/application/Espo/Core/Binding/DefaultBinding.php b/application/Espo/Core/Binding/DefaultBinding.php index 6d78065bfa..d1d03dd75a 100644 --- a/application/Espo/Core/Binding/DefaultBinding.php +++ b/application/Espo/Core/Binding/DefaultBinding.php @@ -29,9 +29,9 @@ namespace Espo\Core\Binding; -class DefaultBinding +class DefaultBinding implements BindingProcessor { - public function process(Binder $binder) + public function process(Binder $binder): void { $binder->bindService( 'Espo\\Core\\InjectableFactory', diff --git a/application/Espo/Core/Binding/EspoBindingLoader.php b/application/Espo/Core/Binding/EspoBindingLoader.php index 497c15c4ad..f90f950f54 100644 --- a/application/Espo/Core/Binding/EspoBindingLoader.php +++ b/application/Espo/Core/Binding/EspoBindingLoader.php @@ -42,7 +42,7 @@ class EspoBindingLoader implements BindingLoader $this->moduleNameList = $module->getOrderedList(); } - public function load() : BindingData + public function load(): BindingData { $data = new BindingData(); @@ -59,7 +59,7 @@ class EspoBindingLoader implements BindingLoader return $data; } - private function loadModule(Binder $binder, string $moduleName) + private function loadModule(Binder $binder, string $moduleName): void { $className = 'Espo\\Modules\\' . $moduleName . '\\Binding'; @@ -70,7 +70,7 @@ class EspoBindingLoader implements BindingLoader (new $className())->process($binder); } - private function loadCustom(Binder $binder) + private function loadCustom(Binder $binder): void { $className = 'Espo\\Custom\\Binding'; diff --git a/application/Espo/Core/Container/ContainerBuilder.php b/application/Espo/Core/Container/ContainerBuilder.php index c5f15b5ead..c0e9e506f9 100644 --- a/application/Espo/Core/Container/ContainerBuilder.php +++ b/application/Espo/Core/Container/ContainerBuilder.php @@ -160,7 +160,7 @@ class ContainerBuilder ) ); - $bindingContainer = new BindingContainer($bindingLoader); + $bindingContainer = new BindingContainer($bindingLoader->load()); return new $this->containerClassName( $this->containerConfigurationClassName, $this->loaderClassNames, $this->services, $bindingContainer diff --git a/tests/unit/Espo/Core/Binding/BindingContainerTest.php b/tests/unit/Espo/Core/Binding/BindingContainerTest.php index 139a7cf638..d70c75568e 100644 --- a/tests/unit/Espo/Core/Binding/BindingContainerTest.php +++ b/tests/unit/Espo/Core/Binding/BindingContainerTest.php @@ -116,7 +116,7 @@ class BindingContainerTest extends \PHPUnit\Framework\TestCase protected function createContainer() { - return new BindingContainer($this->loader); + return new BindingContainer($this->loader->load()); } public function testHasTrue()