-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
extract autoloading out from bootstrap #854
Conversation
This makes a lot of sense to me - make |
👍 , I always wondered why the bootstrap and the autoload were "merged". In dev I don't use the bootstrap, even if it is longer to load. |
It would be safe to merge this in 2.3 actually. |
That introduces an infinite loop between the autoloader and the bootstrap file. So, this can only be merged with versions of the bootstrap file that does not have the require on the autoload file. Which means changing the distribution bundle first, making a release, and then change the requirement in composer here. |
and the change in the DistributionBundle also requires this, otherwise the autoloader is not loaded at all anymore. But I'm -1 on this implementation: this would mean that phpunit would now be loading the bootstrap.php.cache file as it is common to have If you want to split it, I think the front controller should be responsible for loading the autoloader and then the bootstrap file when wanted. This would solve many issues:
|
It does not as the files are only included
I don't see what you mean.
This was already the case before. This is the reason why I included the bootstrap in the autoload. |
The bootstrap file is generated by the SensioDistributionBundle, so it seems it has to be updated according to this update. |
in this case, it means that the return value is broken. If the file was already loaded and the inclusion is skipped, this would return
no it was not forced. I know many projects using |
It still not forced, people can use whatever autoload file they see fit. This is just the default way, just as it was before.
So how do you include the bootstrap file for phpunit then? Or do you suggest to never do it at all?
For whom is the return value broken? I don't see it. The new way has the return value correctly. And people using the old way, also still have the return value. |
@@ -10,4 +12,6 @@ | |||
|
|||
AnnotationRegistry::registerLoader(array($loader, 'loadClass')); | |||
|
|||
include_once __DIR__.'/bootstrap.php.cache'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be require_once to get errors on missing files, not warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why force errors? its optional. even if it cannot be included, the app still works. no need to require it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should even surpress the warning
but this would mean that they have to duplicate the autoload.php file, or switch the autoload.php file to the structure I'm suggesting to avoid loading the bootstrap.php.cache file
I don't include it. the bootstrap.php.cache file just duplicate some class definitions to perform a single loading for all of them instead of using autoloading. It is not necessary to use it (it is just a perf optimization). and not using it makes debugging easier.
web/app.php uses the return value of the file. |
also fix requiring the autoloader which must not use the _once variant because it would not be reliable to use the return value
@@ -1,25 +1,30 @@ | |||
#!/usr/bin/env php | |||
<?php | |||
|
|||
use Symfony\Bundle\FrameworkBundle\Console\Application; | |||
use Symfony\Component\Console\Input\ArgvInput; | |||
use Symfony\Component\Debug\Debug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be consistent with the other front controllers where it is at the beginning
I moved the boostrap into the frontcontrollers and only in debug mode. So it fully fixes #788 |
|
||
// Enable APC for autoloading to improve performance. | ||
// You should change the ApcClassLoader first argument to a unique prefix | ||
// in order to prevent cache key conflicts with other applications | ||
// also using APC. | ||
/* | ||
$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader); | ||
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets please not discuss this
The new version of the PR looks much better to me! |
/** | ||
* @var Composer\Autoload\ClassLoader $loader | ||
*/ | ||
$loader = require __DIR__.'/../app/autoload.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once upon a time, fabpot didn't want the front controllers to work differently. In practice, I like what you've done here. But we would need to be pretty much absolutely sure that there could never be (and has never been any reported) differences between these. Can we be that sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see what difference you mean that could be related to this line? They all load autoload.php.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is including bootstrap.php.cache
in app.php
and autoload.php
in app_dev.php
. You're right that both ultimately include app/autoload.php
, but the risk (if it's even real) is that your bootstrap.php.cache
is somehow out of sync with your source files, so things work in app_dev.php
(with the true source files), but don't in app.php
(which uses the compiled versions). Practically speaking, vendor files are only updated with Composer, which includes the script to re-update bootstrap.php.cache
, so I'm not sure it's a real issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, ezpublish, for example, already does this (loading a different file based on the environment): https://github.com/ezsystems/ezpublish-community/blob/master/web/index.php#L24. If they haven't had issues, I would think we also would be ok.
$input = new ArgvInput(); | ||
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); | ||
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; | ||
|
||
if ($debug) { | ||
Debug::enable(); | ||
} else { | ||
include_once __DIR__.'/bootstrap.php.cache'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would even not include the bootstrap for the console as it is less important anyway (and as you removed it from phpunit as well, that's not inconsistent either).
Thank you @Tobion. |
This PR was merged into the 5.0.x-dev branch. Discussion ---------- remove autoloading from bootstrap file Continuation of symfony/symfony-standard#854 to remove the obsolete mix of bootstrap and autoloading. @fabpot it would be good to merge this in 5.0, even if you just created the first relase of it. 5.x is also the dependency in the standard edition now. Commits ------- d1148b7 remove autoloading from bootstrap file
Fixes https://github.com/symfony/symfony-standard/issues/788#issuecomment-98993898 and symfony/symfony#14776 (comment).
opcache.validate_timestamps=0
in production there is no point in using the bootstrap.require
instead ofrequire_once
for the autoloader to rely on the return value andinclude_once
instead ofrequire_once
for the bootstrap as the app is also working without it