/** * @param \Composer\Script\Event $event */ protected function insertComposerModeConstant(\Composer\Script\Event $event) { $composer = $event->getComposer(); $pluginConfig = Config::load($composer); if (!$pluginConfig->get('composer-mode')) { return; } $composerConfig = $composer->getConfig(); $vendorDir = $composerConfig->get('vendor-dir'); $autoloadFile = $vendorDir . '/autoload.php'; $io = $event->getIO(); if (!file_exists($autoloadFile)) { throw new \RuntimeException(sprintf('Could not adjust autoloader: The file %s was not found.', $autoloadFile)); } $io->write('<info>Inserting TYPO3_COMPOSER_MODE constant</info>'); $contents = file_get_contents($autoloadFile); $constant = "if (!defined('TYPO3_COMPOSER_MODE')) {\n"; $constant .= "\tdefine('TYPO3_COMPOSER_MODE', TRUE);\n"; $constant .= "}\n\n"; // Regex modifiers: // "m": \s matches newlines // "D": $ matches at EOF only // Translation: insert before the last "return" in the file $contents = preg_replace('/\\n(?=return [^;]+;\\s*$)/mD', "\n" . $constant, $contents); file_put_contents($autoloadFile, $contents); }
/** * Read plugin configuration */ protected function initializeConfiguration() { $this->pluginConfig = Config::load($this->composer); }
/** * @param CommandEvent $event * @return Config */ protected static function getConfig(CommandEvent $event) { return Config::load($event->getComposer()); }
/** * PluginImplementation constructor. * * @param Event $event * @param IncludeFile $includeFile * @param ScriptDispatcher $scriptDispatcher */ public function __construct(Event $event, ScriptDispatcher $scriptDispatcher = null, IncludeFile $includeFile = null) { $this->event = $event; $this->scriptDispatcher = $scriptDispatcher ?: new ScriptDispatcher($event); $this->includeFile = $includeFile ?: new IncludeFile($event->getIO(), array(new BaseDirToken($event->getIO(), Typo3PluginConfig::load($event->getComposer())), new WebDirToken($event->getIO(), Typo3PluginConfig::load($event->getComposer())), new ActiveTypo3ExtensionsToken($event->getIO(), $event->getComposer(), Config::load($event->getIO(), $event->getComposer()->getConfig()))), new Filesystem()); }