/** * Install the package. * * @since 0.1.0 * * @param InstalledRepositoryInterface $repo The repository from where the package was fetched. * @param PackageInterface $package The package to install. * * @throws InvalidArgumentException If the package name does not match the required pattern. */ public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { $path = $this->getInstallPath($package); if ($this->io->isVerbose()) { $this->io->write(sprintf(_('Symlinking PHP Composter action %1$s'), $path), true); } parent::install($repo, $package); foreach ($this->getHooks($package) as $prioritizedHook => $method) { $array = explode('.', $prioritizedHook); if (count($array) > 1) { list($priority, $hook) = $array; } else { $hook = $array[0]; $priority = 10; } if ($this->io->isVeryVerbose()) { $this->io->write(sprintf(_('Adding method "%1$s" to hook "%2$s" with priority %3$s'), $method, $hook, $priority), true); } HookConfig::addEntry($hook, $method, $priority); } }
/** * Generate the config file. * * @since 0.1.0 * * @return string Generated Config file. */ public static function getConfig() { $output = '<?php' . PHP_EOL; $output .= '// PHP Composter configuration file.' . PHP_EOL; $output .= '// Do not edit, this file is generated automatically.' . PHP_EOL; $output .= '// Timestamp: ' . date('Y/m/d H:m:s') . PHP_EOL; $output .= PHP_EOL; $output .= 'return array(' . PHP_EOL; foreach (static::getGitHookNames() as $hook) { $entries = HookConfig::getEntries($hook); $output .= ' \'' . $hook . '\' => array(' . PHP_EOL; foreach ($entries as $priority => $methods) { $output .= ' ' . $priority . ' => array(' . PHP_EOL; foreach ($methods as $method) { $output .= ' \'' . $method . '\',' . PHP_EOL; } $output .= ' ),' . PHP_EOL; } $output .= ' ),' . PHP_EOL; } $output .= ');' . PHP_EOL; return $output; }