mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 23:16:03 +00:00
binder inContextd
This commit is contained in:
@@ -30,10 +30,11 @@
|
||||
namespace Espo\Core\Binding;
|
||||
|
||||
use LogicException;
|
||||
use Closure;
|
||||
|
||||
class Binder
|
||||
{
|
||||
private $data;
|
||||
private BindingData $data;
|
||||
|
||||
public function __construct(BindingData $data)
|
||||
{
|
||||
@@ -130,6 +131,21 @@ class Binder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a contextual binder and pass it as an argument of a callback.
|
||||
*
|
||||
* @param string $className A context.
|
||||
* @param Closure(ContextualBinder): void $callback A callback with a `ContextualBinder` argument.
|
||||
*/
|
||||
public function inContext(string $className, Closure $callback): self
|
||||
{
|
||||
$contextualBinder = new ContextualBinder($this->data, $className);
|
||||
|
||||
$callback($contextualBinder);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a contextual binder.
|
||||
*
|
||||
|
||||
@@ -109,7 +109,7 @@ class BindingContainerBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a contextual binder.
|
||||
* Creates a contextual binder and pass it as an argument of a callback.
|
||||
*
|
||||
* @param string $className A context.
|
||||
* @param Closure(ContextualBinder): void $callback A callback with a `ContextualBinder` argument.
|
||||
|
||||
@@ -179,6 +179,22 @@ class BindingContainerTest extends \PHPUnit\Framework\TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testHasContextTrue0()
|
||||
{
|
||||
$this->binder
|
||||
->inContext('Espo\\Context', function (ContextualBinder $binder): void {
|
||||
$binder->bindService('Espo\\Test', 'test');
|
||||
});
|
||||
|
||||
$class = $this->createClassMock('Espo\\Context');
|
||||
|
||||
$param = $this->createParamMock('test', 'Espo\\Test');
|
||||
|
||||
$this->assertTrue(
|
||||
$this->createContainer()->has($class, $param)
|
||||
);
|
||||
}
|
||||
|
||||
public function testHasContextTrue1()
|
||||
{
|
||||
$this->binder
|
||||
|
||||
Reference in New Issue
Block a user