From 60cd875cc2623c95a8fbc06e0e0f874c7657a483 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 6 May 2013 09:37:21 -0500 Subject: [PATCH] Added "pre-autoload-dump" event. This event is fired before the autoload file is generated, for either an install or update command. --- doc/articles/scripts.md | 2 ++ res/composer-schema.json | 6 +++++- src/Composer/Autoload/AutoloadGenerator.php | 2 ++ src/Composer/Script/ScriptEvents.php | 9 +++++++++ tests/Composer/Test/Autoload/AutoloadGeneratorTest.php | 9 +++++++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/articles/scripts.md b/doc/articles/scripts.md index 58f98760b..0c5d85343 100644 --- a/doc/articles/scripts.md +++ b/doc/articles/scripts.md @@ -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. diff --git a/res/composer-schema.json b/res/composer-schema.json index 3b85d9791..972d01dac 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -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." } } }, diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 6c03ff330..fc5e55cfd 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -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()); diff --git a/src/Composer/Script/ScriptEvents.php b/src/Composer/Script/ScriptEvents.php index d8971b15a..377c56a67 100644 --- a/src/Composer/Script/ScriptEvents.php +++ b/src/Composer/Script/ScriptEvents.php @@ -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. * diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 9ead1b515..bde4b5ecb 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -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);