TYPO3  7.6
class-alias-loader/src/Plugin.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\ClassAliasLoader;
3 
4 /*
5  * This file is part of the class alias loader package.
6  *
7  * (c) Helmut Hummel <info@helhum.io>
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12 
13 use Composer\Composer;
14 use Composer\IO\IOInterface;
15 use Composer\Plugin\PluginInterface;
16 use Composer\EventDispatcher\EventSubscriberInterface;
17 
21 class Plugin implements PluginInterface, EventSubscriberInterface
22 {
26  protected $composer;
27 
31  protected $io;
32 
39  public function activate(Composer $composer, IOInterface $io)
40  {
41  $this->composer = $composer;
42  $this->io = $io;
43  }
44 
63  public static function getSubscribedEvents()
64  {
65  return array(
66  'post-autoload-dump' => array('onPostAutoloadDump')
67  );
68  }
69 
76  public function onPostAutoloadDump(\Composer\Script\Event $event)
77  {
78  $flags = $event->getFlags();
79  $config = $event->getComposer()->getConfig();
80  $optimizeAutoloadFiles = !empty($flags['optimize']) || $config->get('optimize-autoloader') || $config->get('classmap-authoritative');
81 
82  $aliasMapGenerator = new ClassAliasMapGenerator(
83  $event->getComposer(),
84  $event->getIO(),
85  $optimizeAutoloadFiles
86  );
87 
88  return $aliasMapGenerator->generateAliasMap();
89  }
90 
91 }