Created
August 30, 2012 14:27
-
-
Save simensen/3529607 to your computer and use it in GitHub Desktop.
Get the PSR-0 autoload definitions by a post-update/post-install Composer script.
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
<?php | |
namespace Dflydev\ClasspathResourceLocator\Composer\Scripts; | |
use Composer\Script\Event; | |
use Composer\Autoload\AutoloadGenerator; | |
use Composer\Repository\CompositeRepository; | |
class RefreshClasspath | |
{ | |
public static function refreshClasspath(Event $event) | |
{ | |
$composer = $event->getComposer(); | |
$config = $composer->getConfig(); | |
$localRepos = new CompositeRepository($composer->getRepositoryManager()->getLocalRepositories()); | |
$package = $composer->getPackage(); | |
$installationManager = $composer->getInstallationManager(); | |
$autoloadGenerator = new AutoloadGenerator; | |
$packageMap = $autoloadGenerator->buildPackageMap($installationManager, $package, $localRepos->getPackages()); | |
$autoloads = $autoloadGenerator->parseAutoloads($packageMap); | |
// | |
// Do something here to cache $autoloads somewhere that | |
// my classes can find it and will always be available. | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment