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

ensure we return null rather than void in SyliusPluginTrait::getContainerExtension #8979

Merged
merged 1 commit into from
Nov 24, 2017

Conversation

lsmith77
Copy link
Contributor

@lsmith77 lsmith77 commented Nov 21, 2017

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets
License MIT

I am not entirely sure what is going on here.
It seems for one that when I implemented a proper Di extension in FOSSyliusImportExportPlugin I suddenly ended up with

  [Payum\Core\Exception\InvalidArgumentException]
  The storage factory with such name filesystem already registered

Which in turn seems to be caused by suddenly \Payum\Bundle\PayumBundle\PayumBundle::build being called twice.

Messing around I eventually ended up at:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Return value of FriendsOfSylius\SyliusImportExportPlugin\FOSSyliusImportExportPlugin::getContainerExtension() must implement interface Symfony\Component\DependencyInjection\Extension\ExtensionInterface or be null, none returned in /Users/lsmith/htdocs/SyliusImportExportPlugin/vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Application/SyliusPluginTrait.php:71

Which led me to this PR and which magically fixed all the issues I had once I removed all my debug code.

@lsmith77 lsmith77 changed the title ensure we return null rather than void in \Sylius\Bundle\CoreBundle\A… ensure we return null rather than void in SyliusPluginTrait::getContainerExtension Nov 21, 2017
@lsmith77
Copy link
Contributor Author

lsmith77 commented Nov 21, 2017

Ok .. it seems like the issue is a bit deeper.

I run the following:

  • (cd tests/Application && bin/console config:dump fos_sylius_import_export -e=test)
    • results in The storage factory with such name filesystem already registered
  • (cd tests/Application && bin/console config:dump framework -e=test)
    • results in the expected output
  • (cd tests/Application && bin/console config:dump fos_sylius_import_export -e=test)
    • results in the expected output if I have this PR checked out

I assume this is because if the cache is filled (though I don't think my test app actually has the cache enabled .. so wtf?) then it doesn't end up calling the PayumBundle::build() method twice ..

@lsmith77
Copy link
Contributor Author

@makasim ok its getting stranger .. with the following change the issue with Payum goes way:

diff --git a/PayumBundle.php b/PayumBundle.php
index e49ad44..144ffd3 100644
--- a/PayumBundle.php
+++ b/PayumBundle.php
@@ -17,6 +17,11 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
 
 class PayumBundle extends Bundle
 {
+    public function getContainerExtension()
+    {
+        return new PayumExtension();
+    }
+
     public function build(ContainerBuilder $container)
     {
         parent::build($container);

@lsmith77
Copy link
Contributor Author

an alternative fix is

diff --git a/DependencyInjection/PayumExtension.php b/DependencyInjection/PayumExtension.php
index f997b6a..2cd4a5b 100644
--- a/DependencyInjection/PayumExtension.php
+++ b/DependencyInjection/PayumExtension.php
@@ -272,7 +272,7 @@ class PayumExtension extends Extension implements PrependExtensionInterface
         if (empty($factoryName)) {
             throw new InvalidArgumentException(sprintf('The storage factory %s has empty name', get_class($factory)));
         }
-        if (array_key_exists($factoryName, $this->storagesFactories)) {
+        if (array_key_exists($factoryName, $this->storagesFactories) && $this->storagesFactories[$factoryName] != $factory) {
             throw new InvalidArgumentException(sprintf('The storage factory with such name %s already registered', $factoryName));
         }
         

@lsmith77 lsmith77 force-pushed the fix_missing_extension branch from 3b32eed to ebcbbec Compare November 21, 2017 21:10
@lsmith77 lsmith77 changed the base branch from master to 1.0 November 21, 2017 21:10
@makasim
Copy link
Contributor

makasim commented Nov 22, 2017

@makasim ok its getting stranger .. with the following change the issue with Payum goes way:

@lsmith77 That might be merged. I'd like to know what is going there.

@lsmith77
Copy link
Contributor Author

lsmith77 commented Nov 22, 2017

@makasim it looks to me like the PayumBundle::build() is called method twice .. now why that is the case I don't know. In that case we end up with that exception.

@makasim
Copy link
Contributor

makasim commented Nov 22, 2017

@lsmith77 Yeah, obviously. I might have a similar case in enqueue. I'll try to debug it there. Hope it is the same issue.

@lsmith77 lsmith77 closed this Nov 24, 2017
@lsmith77 lsmith77 reopened this Nov 24, 2017
@lsmith77
Copy link
Contributor Author

finally had some more time to look into this .. the issue is that the config:dump command runs another build() on all bundles .. as such I think PayumBundle::build() needs to be refactored to deal with this.

Again however, the change in this PR should still be applied to Sylius.

@@ -68,6 +68,8 @@ public function getContainerExtension(): ?ExtensionInterface
if ($this->containerExtension) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just return $this->containerExtension ?: null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah .. I guess that makes things a bit more compact and readable

@lsmith77 lsmith77 force-pushed the fix_missing_extension branch from ebcbbec to 5d62895 Compare November 24, 2017 10:06
@lsmith77
Copy link
Contributor Author

the errors seem unrelated to the change ...

…pplication\SyliusPluginTrait::getContainerExtension
@lsmith77 lsmith77 force-pushed the fix_missing_extension branch from 5d62895 to ed6f759 Compare November 24, 2017 15:18
@lsmith77
Copy link
Contributor Author

rebased .. and green

@lchrusciel lchrusciel merged commit 3e1dfcc into Sylius:1.0 Nov 24, 2017
@lchrusciel
Copy link
Member

Thanks Lukas!

@lsmith77 lsmith77 deleted the fix_missing_extension branch November 25, 2017 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants