8000 Support Symfony Messenger by ro0NL · Pull Request #134 · msgphp/msgphp · GitHub
[go: up one dir, main page]

Skip to content

Support Symfony Messenger #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wire handlers
  • Loading branch information
ro0NL committed Apr 27, 2018
commit acd2de3a977db6581d85570ee0f8b56320389697
8 changes: 3 additions & 5 deletions src/Domain/Infra/DependencyInjection/BundleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static function initDomain(ContainerBuilder $container): void
}

if (class_exists(ConsoleEvents::class)) {
$container->register(ConsoleInfra\MessageSubscriber::class)
->setPublic(false);

$container->register(ConsoleInfra\Context\ClassContextFactory::class)
->setPublic(false)
->setAbstract(true)
Expand All @@ -40,11 +43,6 @@ public static function initDomain(ContainerBuilder $container): void
->setPublic(false);

$container->setAlias(ConsoleInfra\Context\ClassContextElementFactoryInterface::class, new Alias(ConsoleInfra\Context\ClassContextElementFactory::class, false));

$messageSubscriber = $container->register(ConsoleInfra\MessageSubscriber::class)
->ad

if ()
}

if (class_exists(DoctrineOrmVersion::class)) {
Expand Down
34 changes: 19 additions & 15 deletions src/Domain/Infra/DependencyInjection/ContainerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,31 @@ public static function configureDoctrineOrmRepositories(ContainerBuilder $contai

public static function configureCommandMessages(ContainerBuilder $container, array $classMapping, array $commands): void
{
if (!self::hasBundle($container, SimpleBusCommandBusBundle::class)) {
return;
}
$configure = function (string $tag) use ($container, $classMapping) {
foreach ($container->findTaggedServiceIds($tag) as $id => $attr) {
foreach ($attr as $attr) {
if (!isset($attr[$attrName = 'handles'])) {
continue;
}

foreach ($container->findTaggedServiceIds($tag = 'command_handler') as $id => $attr) {
foreach ($attr as $attr) {
if (!isset($attr[$attrName = 'handles'])) {
continue;
}
if ($commands[$command = $attr[$attrName]] ?? false) {
if (isset($classMapping[$command])) {
$container->getDefinition($id)
->addTag($tag, [$attrName => $classMapping[$command]]);
}

if ($commands[$command = $attr[$attrName]] ?? false) {
if (isset($classMapping[$command])) {
$container->getDefinition($id)
->addTag($tag, [$attrName => $classMapping[$command]]);
continue;
}

continue;
$container->removeDefinition($id);
}

$container->removeDefinition($id);
}
};

$configure('messenger.message_handler');

if (self::hasBundle($container, SimpleBusCommandBusBundle::class)) {
$configure('command_handler');
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/UserBundle/DependencyInjection/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Form\Form;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Validator\Validation;
use Twig\Environment as TwigEnvironment;

Expand Down Expand Up @@ -66,7 +67,7 @@ public function load(array $configs, ContainerBuilder $container): void
}

// message infra
if (ContainerHelper::hasBundle($container, SimpleBusCommandBusBundle::class)) {
if (interface_exists(MessageBusInterface::class) || ContainerHelper::hasBundle($container, SimpleBusCommandBusBundle::class)) {
$loader->load('message.php');

ContainerHelper::removeIf($container, !$container->has(Repository\UserRepositoryInterface::class), [
Expand Down
13 changes: 8 additions & 5 deletions src/UserBundle/Resources/config/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
->load($ns = 'MsgPhp\\User\\Command\\Handler\\', $handlers = $baseDir.'/Command/Handler/*Handler.php')
;

if ($simpleCommandBusEnabled) {
foreach (glob($handlers) as $file) {
$services->get($handler = $ns.basename($file, '.php'))->tag('command_handler', [
'handles' => $reflector($handler)->getMethod('__invoke')->getParameters()[0]->getClass()->getName(),
]);
foreach (glob($handlers) as $file) {
$service = $services->get($handler = $ns.basename($file, '.php'));
$handles = $reflector($handler)->getMethod('__invoke')->getParameters()[0]->getClass()->getName();

$service->tag('messenger.message_handler', ['handles' => $handles]);

if ($simpleCommandBusEnabled) {
$service->tag('command_handler', ['handles' => $handles]);
}
}
};
0