Skip to content

Commit

Permalink
Load Symfony polyfill packages when running the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cs278 committed Jul 27, 2021
1 parent 60bcc4e commit 305eb3c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ComposerPlugin implements PluginInterface, Capable
{
public function activate(Composer $composer, IOInterface $io)
{

PolyfillLoader::load($composer, $io);
}

public function deactivate(Composer $composer, IOInterface $io)
Expand Down
49 changes: 49 additions & 0 deletions src/PolyfillLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Cs278\ComposerAudit;

use Composer\Composer;
use Composer\IO\IOInterface;

/**
* Find Symfony Polyfill libraries and loads them.
*/
final class PolyfillLoader
{
public static function load(Composer $composer, IOInterface $io)
{
$packages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();
$includeFiles = [];

foreach ($packages as $package) {
if (strpos($package->getName(), 'symfony/polyfill-') === 0) {
$io->debug(sprintf('PolyfillLoader finding files in: %s', $package->getName()));
$autoload = $package->getAutoload();

if (isset($autoload['files'])) {
$installPath = $composer->getInstallationManager()->getInstallPath($package);

foreach ($autoload['files'] as $file) {
$io->debug(sprintf('PolyfillLoader found: %s %s', $package->getName(), $file));
$includeFiles[] = $installPath.\DIRECTORY_SEPARATOR.$file;
}
}
}
}

foreach ($includeFiles as $includeFile) {
if (in_array($includeFile, \get_included_files(), true)) {
$io->debug(sprintf('PolyfillLoader %s is already loaded', $includeFile));
return;
}

$io->debug(sprintf('PolyfillLoader loading: %s', $includeFile));
self::incldueFile($includeFile);
}
}

private static function incldueFile($path): void
{
require $path;
}
}

0 comments on commit 305eb3c

Please sign in to comment.