1
0
Fork 0

Added "pre-autoload-dump" event.

This event is fired before the autoload file is generated, for either
an install or update command.
pull/1871/head
Taylor Otwell 2013-05-06 09:37:21 -05:00
parent 8a06e461e5
commit 60cd875cc2
5 changed files with 25 additions and 3 deletions

View File

@ -30,6 +30,8 @@ Composer fires the following named events during its execution process:
- **post-package-update**: occurs after a package is updated.
- **pre-package-uninstall**: occurs before a package has been uninstalled.
- **post-package-uninstall**: occurs after a package has been uninstalled.
- **pre-autoload-dump**: occurs before the autoloader is dumped, either
during `install`/`update`, or via the `dump-autoload` command.
- **post-autoload-dump**: occurs after the autoloader is dumped, either
during `install`/`update`, or via the `dump-autoload` command.

View File

@ -283,9 +283,13 @@
"type": ["array", "string"],
"description": "Occurs after a package has been uninstalled, contains one or more Class::method callables or shell commands."
},
"pre-autoload-dump": {
"type": ["array", "string"],
"description": "Occurs before the autoloader is dumped, contains one or more Class::method callables or shell commands."
},
"post-autoload-dump": {
"type": ["array", "string"],
"description": "Occurs after a the autoloader is dumped, contains one or more Class::method callables or shell commands."
"description": "Occurs after the autoloader is dumped, contains one or more Class::method callables or shell commands."
}
}
},

View File

@ -39,6 +39,8 @@ class AutoloadGenerator
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
{
$this->eventDispatcher->dispatch(ScriptEvents::PRE_AUTOLOAD_DUMP);
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
$basePath = $filesystem->normalizePath(getcwd());

View File

@ -110,6 +110,15 @@ class ScriptEvents
*/
const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
/**
* The PRE_AUTOLOAD_DUMP event occurs before the autoload file is generated.
*
* The event listener method receives a Composer\Script\Event instance.
*
* @var string
*/
const PRE_AUTOLOAD_DUMP = 'pre-autoload-dump';
/**
* The POST_AUTOLOAD_DUMP event occurs after the autoload file has been generated.
*

View File

@ -619,10 +619,15 @@ EOF;
$this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
}
public function testEventIsDispatchedAfterAutoloadDump()
public function testPreAndPostEventsAreDispatchedDuringAutoloadDump()
{
$this->eventDispatcher
->expects($this->once())
->expects($this->at(0))
->method('dispatch')
->with(ScriptEvents::PRE_AUTOLOAD_DUMP, false);
$this->eventDispatcher
->expects($this->at(1))
->method('dispatch')
->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);