contao/manager-bundle

Custom kernel breaks installation

leofeyer opened this issue · 7 comments

This is a follow-up ticket for #29.

Unfortunately, adding $projectDir as first argument leads to an exception upon install:

composer run-script post-update-cmd
> Contao\ManagerBundle\Composer\ScriptHandler::initializeApplication

 Added/updated the web/app.php file.

 // Clearing the cache for the prod environment with debug                      
 // false                                                                       

21:37:54 ERROR     [console] Error thrown while running command "--ansi cache:clear --env=prod". Message: "Too few arguments to function Contao\ManagerBundle\HttpKernel\ContaoKernel::__construct(), 2 passed in /Users/leofeyer/Sites/contao/managed-edition/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php on line 262 and exactly 3 expected" ["error" => ArgumentCountError {trace: { …} …},"command" => "--ansi cache:clear --env=prod","message" => "Too few arguments to function Contao\ManagerBundle\HttpKernel\ContaoKernel::__construct(), 2 passed in /Users/leofeyer/Sites/contao/managed-edition/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php on line 262 and exactly 3 expected"] []
21:37:54 ERROR     [console] Command "--ansi cache:clear --env=prod" exited with code "1" ["command" => "--ansi cache:clear --env=prod","code" => 1] []

  [Symfony\Component\Debug\Exception\FatalThrowableError]                      
  Type error: Too few arguments to function Contao\ManagerBundle\HttpKernel\C  
  ontaoKernel::__construct(), 2 passed in /Users/leofeyer/Sites/contao/manage  
  d-edition/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command  
  /CacheClearCommand.php on line 262 and exactly 3 expected                    

This is because the Symfony CacheClearCommand creates a temporary kernel, which of course does not know about our custom parameter.

@aschempp @ausi So I guess there is no other way then making the third argument optional?

If so, we should clearly document why we are doing it this way.

damn, exactly one of the reasons that will be removed in Symfony 4.4. And probably the reason I did not use a constructor argument for rootDir but could not remember :-(

Should we go back to setProjectDir?

Either setProjectDir() or __construct($environment, $debug, $projectDir = null). Your call.

Theoretically, I would prefer setProjectDir because that's what we always did. Or we just live with setRootDir and calculate the projectDir from there. The advantage of that would be that the entry points will be BC (even though we agreed that's not important).

On the other hand, I wonder what happens if Symfony clones the kernel in the cache warmer? Then setProjectDir is not called either, so the kernel cannot know it's location?

ausi commented

Wouldn’t using dirname(dirname(dirname(dirname(dirname(__DIR__))))) solve all these problems?
As this is the manager bundle, different directory structures are not supported anyways, right?

I'm worried that this will cause side effects, but I can't tell why, just a gut feeling… 🙍‍♂️

Fixed in 4bdf785.