/** * @param InputInterface $input * @param OutputInterface $output * * @return int|void */ public function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $gitHooksPath = $this->paths()->getGitHooksDir(); $resourceHooksPath = $this->paths()->getGitHookTemplatesDir() . $this->grumPHP->getHooksPreset(); $resourceHooksPath = $this->paths()->getPathWithTrailingSlash($resourceHooksPath); $customHooksPath = $this->paths()->getPathWithTrailingSlash($this->grumPHP->getHooksDir()); // Some git clients do not automatically create a git hooks folder. if (!$this->filesystem->exists($gitHooksPath)) { $this->filesystem->mkdir($gitHooksPath); $output->writeln(sprintf('<fg=yellow>Created git hooks folder at: %s</fg=yellow>', $gitHooksPath)); } foreach (self::$hooks as $hook) { $gitHook = $gitHooksPath . $hook; $hookTemplate = new SplFileInfo($resourceHooksPath . $hook); if ($customHooksPath && $this->filesystem->exists($customHooksPath . $hook)) { $hookTemplate = new SplFileInfo($customHooksPath . $hook); } if (!$this->filesystem->exists($hookTemplate)) { throw new RuntimeException(sprintf('Could not find hook template for %s at %s.', $hook, $hookTemplate)); } $content = $this->parseHookBody($hook, $hookTemplate); $this->filesystem->dumpFile($gitHook, $content); $this->filesystem->chmod($gitHook, 0775); } $output->writeln('<fg=yellow>Watch out! GrumPHP is sniffing your commits!<fg=yellow>'); }
/** * @param array $configuration * * @return bool */ protected function writeConfiguration(array $configuration) { try { $yaml = Yaml::dump($configuration); $grumphpConfigName = $this->input->getOption('config'); $this->filesystem->dumpFile($grumphpConfigName, $yaml); return true; } catch (Exception $e) { // Fail silently and return false! } return false; }