-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from cs278/polyfill-workaround
Workaround polyfill not being loaded
- Loading branch information
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters