Hirak\Prestissimo\Plugin::activate PHP Method

activate() public method

public activate ( Composer\Composer $composer, Composer\IO\IOInterface $io )
$composer Composer\Composer
$io Composer\IO\IOInterface
    public function activate(Composer $composer, IO\IOInterface $io)
    {
        // @codeCoverageIgnoreStart
        // guard for self-update problem
        if (__CLASS__ !== 'Hirak\\Prestissimo\\Plugin') {
            return $this->disable();
        }
        // @codeCoverageIgnoreEnd
        // load all classes
        foreach (self::$pluginClasses as $class) {
            class_exists(__NAMESPACE__ . '\\' . $class);
        }
        $this->io = $io;
        $this->config = $composer->getConfig();
        $this->package = $composer->getPackage();
        if (array_key_exists('argv', $GLOBALS)) {
            foreach ($GLOBALS['argv'] as $arg) {
                switch ($arg) {
                    case 'create-project':
                    case 'update':
                    case 'outdated':
                    case 'require':
                        $this->prefetchComposerRepositories();
                        break 2;
                    case 'install':
                        if (file_exists('composer.json') && !file_exists('composer.lock')) {
                            $this->prefetchComposerRepositories();
                        }
                        break 2;
                }
            }
        }
    }

Usage Example

Example #1
0
 public function testOnPostDependenciesSolving()
 {
     $plugin = new Plugin();
     $plugin->activate($this->composerp->reveal(), $this->iop->reveal());
     $evp = $this->prophesize('Composer\\Installer\\InstallerEvent');
     $evp->getOperations()->willReturn($this->createDummyOperations());
     // on enabled
     $plugin->onPostDependenciesSolving($evp->reveal());
     // on disabled
     $plugin->disable();
     $evp = $this->prophesize('Composer\\Installer\\InstallerEvent');
     $evp->getOperations()->shouldNotBeCalled();
     $plugin->onPostDependenciesSolving($evp->reveal());
 }