Skip to content
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

[FrameworkBundle][Notifier] Fix service registration (MessageBird + TurboSms) #53418

Merged

Conversation

smnandre
Copy link
Contributor

@smnandre smnandre commented Jan 4, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #
License MIT

Inside the registerNotifierConfiguration method, the $classToServices map (TransportFactoryClass => serviceId) used the Transport class (instead of the TransportFactory) for MessageBird and TurboSms.

The services are registered in Ressources/config/notifier_transports.php (with the correct Factory classes).

This map is then used in this loop:

foreach ($classToServices as $class => $service) {
  $package = substr($service, \strlen('notifier.transport_factory.'));

  if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier', $package), $class, $parentPackages, true)) {
      $container->removeDefinition($service);
      $container->removeAlias(str_replace('-', '', $service)); // @deprecated to be removed in 6.0
  }
}

So i'm not sure it's considered a bug as IRL checking the Factory class or the Transport class did not make any difference as i read it.... but it's worth a fix for the future :)

So i target 5.4 with no certitude :)

@smnandre
Copy link
Contributor Author

smnandre commented Jan 4, 2024

(fabbot unrelated)

@OskarStark
Copy link
Contributor

Good catch, to avoid such mistakes we could check inside the loop if class instanceof AbstractFactory, but that would be on runtime, and I don't think its worth

WDYT @nicolas-grekas ?

@smnandre
Copy link
Contributor Author

smnandre commented Jan 5, 2024

Maybe naive but is something like that possible ?

-foreach ($classToServices as $class => $service) {
+foreach ($classToServices as $service) {
    $package = substr($service, \strlen('notifier.transport_factory.'));

-    if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier', $package), $class, $parentPackages)) {
+    if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier', $package), $container->getDefinition($service)->getClass(), $parentPackages)) {
        $container->removeDefinition($service);
    }
  }

And then keep only the ids (that may be collected thanks to the tag too i guess?)

@carsonbot carsonbot changed the title [Notifier] Fix FrameworkExtension services (MessageBird + TurboSms) [FrameworkBundle][Notifier] Fix FrameworkExtension services (MessageBird + TurboSms) Jan 5, 2024
@OskarStark OskarStark changed the title [FrameworkBundle][Notifier] Fix FrameworkExtension services (MessageBird + TurboSms) [FrameworkBundle][Notifier] Fix service registration (MessageBird + TurboSms) Jan 5, 2024
@nicolas-grekas
Copy link
Member

Maybe naive but is something like that possible ?

Possible, can you give it a try on 7.1?

(that may be collected thanks to the tag too i guess?)

That'd require a compiler pass. Which is maybe not a bad idea since it would allow registering external notifiers/etc.
To be confirmed there's a use case for that.

@nicolas-grekas
Copy link
Member

Thank you @smnandre.

@nicolas-grekas nicolas-grekas merged commit e3d9fd2 into symfony:5.4 Jan 5, 2024
9 of 11 checks passed
@smnandre
Copy link
Contributor Author

smnandre commented Jan 5, 2024

Possible, can you give it a try on 7.1?

Yep, i open a PR if that seems ok ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants