# code-snippets/3.10.0/vendor/typisttech/imposter-plugin/src/ImposterPlugin.php

Code Snippets, version 3.10.0. 71 lines.

- Page: https://pluginprobe.com/plugins/code-snippets/3.10.0/code/vendor/typisttech/imposter-plugin/src/ImposterPlugin.php
- Raw: https://pluginprobe.com/plugins/code-snippets/3.10.0/raw/vendor/typisttech/imposter-plugin/src/ImposterPlugin.php
- Modified: 2025-10-16T19:08:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-snippets/3.10.0/code/vendor/typisttech/imposter-plugin/src/ImposterPlugin.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace TypistTech\Imposter\Plugin;

use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Package\CompletePackage;
use Composer\Package\RootPackageInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;

class ImposterPlugin implements PluginInterface, EventSubscriberInterface
{
    /**
     * {@inheritDoc}
     */
    public function activate(Composer $composer, IOInterface $io)
    {
        $package = $composer->getPackage();
        if ($package instanceof RootPackageInterface) {
            AutoloadMerger::run($package);
        }

        if ($package instanceof CompletePackage) {
            $scripts = array_merge_recursive([
                ScriptEvents::POST_INSTALL_CMD => [
                    '@composer dump-autoload --optimize',
                ],
                ScriptEvents::POST_UPDATE_CMD => [
                    '@composer dump-autoload --optimize',
                ],
            ], $package->getScripts());

            $package->setScripts($scripts);
        }
    }

    /**
     * {@inheritDoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            ScriptEvents::PRE_AUTOLOAD_DUMP => [
                ['transform', PHP_INT_MAX - 1000],
            ],
        ];
    }

    public function transform(Event $event): void
    {
        Transformer::run(
            $event->getIO()
        );
    }

    public function deactivate(Composer $composer, IOInterface $io)
    {
        // Do nothing.
    }

    public function uninstall(Composer $composer, IOInterface $io)
    {
        // Do nothing.
    }
}

```
