Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Commit 0e8094a

Browse files
committed
feature #854 extract autoloading out from bootstrap (Tobion)
This PR was squashed before being merged into the 2.8 branch (closes #854). Discussion ---------- extract autoloading out from bootstrap Fixes https://github.com/symfony/symfony-standard/issues/788#issuecomment-98993898 and symfony/symfony#14776 (comment). - by default class aggregation is still used as it is probably beneficial by default for most people (no opcache at all or stats enabled) - People that do not want to use the aggregation, can simply comment the line. They do not have to rewrite code. E.g. when using opcache with `opcache.validate_timestamps=0` in production there is no point in using the bootstrap. - No debugging hell anymore as the class aggregation is only done in in no-debug mode - All environments still use the same code path, i.e. load autoload first. The only difference is the inlusion of the aggregation. - This way we can also simplify the bootstrap generation in the distribution bundle in the next major version of it. - several imrprovements like using `require` instead of `require_once` for the autoloader to rely on the return value and `include_once` instead of `require_once` for the bootstrap as the app is also working without it Commits ------- 747a384 extract autoloading out from bootstrap
2 parents 4d44fcf + 747a384 commit 0e8094a

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

app/autoload.php

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use Doctrine\Common\Annotations\AnnotationRegistry;
44
use Composer\Autoload\ClassLoader;
55

6+
error_reporting(error_reporting() & ~E_USER_DEPRECATED);
7+
68
/**
79
* @var ClassLoader $loader
810
*/

app/console

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
#!/usr/bin/env php
22
<?php
33

4+
use Symfony\Bundle\FrameworkBundle\Console\Application;
5+
use Symfony\Component\Console\Input\ArgvInput;
6+
use Symfony\Component\Debug\Debug;
7+
48
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
59
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
610
//umask(0000);
711

812
set_time_limit(0);
913

10-
require_once __DIR__.'/bootstrap.php.cache';
14+
/**
15+
* @var Composer\Autoload\ClassLoader $loader
16+
*/
17+
$loader = require __DIR__.'/../app/autoload.php';
1118
require_once __DIR__.'/AppKernel.php';
1219

13-
use Symfony\Bundle\FrameworkBundle\Console\Application;
14-
use Symfony\Component\Console\Input\ArgvInput;
15-
use Symfony\Component\Debug\Debug;
16-
1720
$input = new ArgvInput();
1821
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
1922
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
2023

2124
if ($debug) {
2225
Debug::enable();
26+
} else {
27+
include_once __DIR__.'/bootstrap.php.cache';
2328
}
2429

2530
$kernel = new AppKernel($env, $debug);

app/phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
66
backupGlobals="false"
77
colors="true"
8-
bootstrap="bootstrap.php.cache"
8+
bootstrap="autoload.php"
99
>
1010
<testsuites>
1111
<testsuite name="Project Test Suite">

web/app.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22

3-
use Symfony\Component\ClassLoader\ApcClassLoader;
43
use Symfony\Component\HttpFoundation\Request;
54

6-
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
5+
/**
6+
* @var Composer\Autoload\ClassLoader $loader
7+
*/
8+
$loader = require __DIR__.'/../app/autoload.php';
9+
include_once __DIR__.'/bootstrap.php.cache';
710

811
// Enable APC for autoloading to improve performance.
912
// You should change the ApcClassLoader first argument to a unique prefix
1013
// in order to prevent cache key conflicts with other applications
1114
// also using APC.
1215
/*
13-
$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
16+
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
1417
$loader->unregister();
1518
$apcLoader->register(true);
1619
*/

web/app_dev.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
1919
}
2020

21-
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
21+
/**
22+
* @var Composer\Autoload\ClassLoader $loader
23+
*/
24+
$loader = require __DIR__.'/../app/autoload.php';
2225
Debug::enable();
2326

2427
require_once __DIR__.'/../app/AppKernel.php';

0 commit comments

Comments
 (0)