_____________
Если вам недостаточно собственных заблуждений, можно расширить их мнениями экспертов.
Нужно уважать мнение оппонета. Ведь заблуждаться - его святое право.
Настаивал, настаиваю и буду настаивать на своем. На кедровых орешках.

Цитата (chee @ 11.01.2021 - 23:12) |
зависимости нужно внедрять в реально проекте очень редко, нужно внедрять расшаренные объекты в основном |
Цитата (twin @ 12.01.2021 - 21:11) |
Но это не так сложно на самом деле, как тебе кажется. С этим любой пимпл справится. |
$injectionsMap = [
'Container' => true,
'ActionSay' => \Examples\ActionSay::class,
'ActionBus' => [
\Examples\ActionBus::class,
'storage' => \SplObjectStorage::class,
],
'ActionFactory' => [
\Examples\ActionFactory::class,
'container' => 'Container'
],
'Application' => [
\Examples\Application::class,
'actionFactory' => 'ActionFactory',
'actionBus' => 'ActionBus',
],
];
$container = (new \ABCDIC\Container)->setMaps($injectionsMap);
Цитата |
Hello world ! Hello ! |
Цитата (chee @ 12.01.2021 - 07:23) |
Я покажу свой вариант после твоего. |
class ActionFactory implements ActionFactoryInterface
{
/**
*
* @var \Psr\Container\ContainerInterface
*/
protected $container;
public function __construct(array $dta)
{
$this->container = $dta['container'];
}
public function create($id)
{
return $this->container->get($id);
}
}
class ActionBus implements ActionBusInterface
{
/**
* @var \SplObjectStorage
*/
protected $storage;
/**
* @var ActionInterface[]
*/
protected $actions;
public function __construct(array $dta)
{
$this->storage = $dta['storage'];
}
public function add(ActionInterface $action)
{
$this->actions[] = $action;
}
public function run()
{
foreach ($this->actions as $action) {
$action->execute();
}
}
}
class Application
{
/**
* @var ActionFactoryInterface
*/
protected $actionFactory;
/**
* @var ActionBusInterface
*/
protected $actionBus;
public function __construct(array $dta)
{
$this->actionFactory = $dta['actionFactory'];
$this->actionBus = $dta['actionBus'];
}
/**
* @param array $actions
*/
public function run(array $actions)
{
foreach ($actions as $action) {
$cmd = $this->actionFactory->create($action['action']);
$cmd->setOptions($action['options']);
$this->actionBus->add($cmd);
}
$this->actionBus->run();
}
}