protected function execute(InputInterface $input, OutputInterface $output) { $stopwatch = new Stopwatch(); $stopwatch->start(__CLASS__); $file = new Path(); if ($input->getOption('root_dir') !== '.') { $this->rootDir = $file->toAbsolutePath($input->getOption('root_dir'), $this->rootDir); } $config = $this->loadConfiguration($input, $this->rootDir); $this->logger = $config->isVerbose() && !$config->isTestEnv() ? new ConsoleLogger($output) : new NullLogger(); $this->executeApi($config); $event = $stopwatch->stop(__CLASS__); $time = number_format($event->getDuration() / 1000, 3); $mem = number_format($event->getMemory() / (1024 * 1024), 2); $this->logger->info(sprintf('elapsed time: <info>%s</info> sec memory: <info>%s</info> MB', $time, $mem)); return 0; }
protected function ensureJsonPath($option, $rootDir, Path $file) { $realpath = $file->getRealWritingFilePath($option, $rootDir); $realFilePath = $file->getRealPath($realpath, $rootDir); if ($realFilePath !== false && !$file->isRealFileWritable($realFilePath)) { throw new InvalidConfigurationException('json_path is not writable'); } $realDir = $file->getRealDir($realpath, $rootDir); if (!$file->isRealDirWritable($realDir)) { throw new InvalidConfigurationException('json_path is not writable'); } return $realpath; }
/** * Ensure json_path is valid. * * @param string $option json_path option. * @param string $rootDir Path to project root directory. * @param Path $file Path object. * * @return string Valid json_path. * * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */ protected function ensureJsonPath($option, $rootDir, Path $file) { // normalize $realpath = $file->getRealWritingFilePath($option, $rootDir); // validate file $realFilePath = $file->getRealPath($realpath, $rootDir); if ($realFilePath !== false && !$file->isRealFileWritable($realFilePath)) { throw new InvalidConfigurationException('json_path is not writable'); } // validate parent dir $realDir = $file->getRealDir($realpath, $rootDir); if (!$file->isRealDirWritable($realDir)) { throw new InvalidConfigurationException(sprintf('json_path is not writable %s', $realDir)); } return $realpath; }