Skip to content

Commit

Permalink
Merge pull request #36 from t-geindre/feature/remove-unused-php-exten…
Browse files Browse the repository at this point in the history
…sions

Remove unused extensions at build time
  • Loading branch information
mnapoli authored Jun 25, 2018
2 parents ab67767 + b5876b6 commit d658887
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Console/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ private function generateArchive(SymfonyStyle $io, ProgressBar $progress) : void
// Set correct permissions on the file
$this->fs->chmod('.bref/output/.bref/bin', 0755);
// Install our custom php.ini and merge it with user configuration
$this->buildPhpConfig(
$phpConfig = $this->buildPhpConfig(
__DIR__ . '/../../template/php.ini',
'.bref/output/.bref/php.ini',
$projectConfig['php']['configuration'] ?? [],
$projectConfig['php']['extensions'] ?? []
);
// Remove unused extensions
$this->removeUnusedExtensions($phpConfig);
$progress->advance();

$progress->setMessage('Installing Bref files for NodeJS');
Expand Down Expand Up @@ -253,7 +255,7 @@ private function copyProjectToOutputDirectory() : void
$directoryMirror->mirror($source, $target);
}

private function buildPhpConfig(string $sourceFile, string $targetFile, array $flags, array $extensions = [])
private function buildPhpConfig(string $sourceFile, string $targetFile, array $flags, array $extensions): array
{
$config = array_merge(
['flags' => array_merge(
Expand All @@ -273,5 +275,19 @@ private function buildPhpConfig(string $sourceFile, string $targetFile, array $f
);

(new IniWriter())->writeToFile($targetFile, $config);

return $config;
}

private function removeUnusedExtensions(array $phpConfig)
{
foreach (glob('.bref/output/.bref/bin/ext/*.so') as $extensionFile) {
if ($extensionFile === '.bref/output/.bref/bin/ext/opcache.so') {
continue;
}
if (!array_key_exists(basename($extensionFile, '.so'), $phpConfig)) {
$this->fs->remove($extensionFile);
}
}
}
}

0 comments on commit d658887

Please sign in to comment.