Skip to content

Commit 761e229

Browse files
committed
exclude_files config option to skip including unneccessary files on each request. Paths should be relative to vendor folder.
Example: ``` "config": { "exclude_files": [ "symfony/polyfill-mbstring/bootstrap.php", "symfony/polyfill-php56/bootstrap.php", ] } ```
1 parent 489396e commit 761e229

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Composer/AutoloadGenerator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function parseAutoloadsTypeFiles($paths, PackageInterface $mainPackage)
4242
*
4343
* @see https://github.com/composer/composer/blob/master/src/Composer/Autoload/AutoloadGenerator.php#L115
4444
*/
45-
public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer', $suffix = '', $staticPhpVersion = 70000)
45+
public function dumpFiles(Composer $composer, $paths, $excludePaths = [], $targetDir = 'composer', $suffix = '', $staticPhpVersion = 70000)
4646
{
4747
$installationManager = $composer->getInstallationManager();
4848
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
@@ -82,10 +82,19 @@ public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer', $
8282
}
8383
}
8484

85+
8586
$paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage);
8687

8788
$autoloads['files'] = array_merge($paths, $autoloads['files']);
8889

90+
// prepend vendor path to exclude paths
91+
foreach ($excludePaths as &$path) {
92+
$path = $vendorPath . '/' . $path;
93+
}
94+
$autoloads['files'] = array_filter($autoloads['files'], function($path) use ($excludePaths, $filesystem) {
95+
return !in_array($filesystem->normalizePath($path), $excludePaths);
96+
});
97+
8998
$includeFilesFilePath = $targetDir.'/autoload_files.php';
9099
if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
91100
file_put_contents($includeFilesFilePath, $includeFilesFileContents);

src/Plugin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ public function dumpFiles()
4747
{
4848
$extraConfig = $this->composer->getPackage()->getExtra();
4949

50-
if (!array_key_exists('include_files', $extraConfig) || !is_array($extraConfig['include_files'])) {
50+
/*if (!array_key_exists('include_files', $extraConfig) || !is_array($extraConfig['include_files'])) {
51+
return;
52+
}*/
53+
$includeFiles = !empty($extraConfig['include_files']) ? $extraConfig['include_files'] : [];
54+
$excludeFiles = !empty($extraConfig['exclude_files']) ? $extraConfig['exclude_files'] : [];
55+
if (!$includeFiles && !$excludeFiles) {
5156
return;
5257
}
5358

54-
$this->generator->dumpFiles($this->composer, $extraConfig['include_files']);
59+
//$this->generator->dumpFiles($this->composer, $extraConfig['include_files']);
60+
$this->generator->dumpFiles($this->composer, $includeFiles, $excludeFiles);
5561
}
5662
}

0 commit comments

Comments
 (0)