/** * Execute the "info" command * * @param InputInterface $input Input object * @param OutputInterface $output Output object * @throws \Exception * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $setting = $input->getOption('setting'); $options = array(); if ($setting === null) { throw new \Exception('No setting provided!'); } $scan = new \Psecio\Iniscan\Scan(); $ruleSet = $scan->getRules(); // see if we can find info about the setting $found = array(); foreach ($ruleSet as $section => $rules) { foreach ($rules as $rule) { if (isset($rule->test->key) && $rule->test->key === $setting) { if (isset($rule->info)) { $found[] = $rule; } } } } if (!empty($found)) { $outputHandler = new \Psecio\Iniscan\Command\InfoCommand\Output\Console($output, $options); return $outputHandler->render($found); } else { $output->writeLn('No information found for setting ' . $setting); } }
/** * Execute the "list" command * * @param InputInterface $input Input object * @param OutputInterface $output Output object * @throws \Psecio\Iniscan\Exceptions\FormatNotFoundException * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $format = $input->getOption('format'); $scan = new \Psecio\Iniscan\Scan(); $rules = $scan->getRules(); $options = array(); $format = $format === null ? 'console' : $format; $formatClass = "\\Psecio\\Iniscan\\Command\\ListCommand\\Output\\" . ucwords(strtolower($format)); if (!class_exists($formatClass)) { throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "' . $format . '" not found'); } $outputHandler = new $formatClass($output, $options); return $outputHandler->render($rules); }
/** * Execute the "fix" command * * @param InputInterface $input Input object * @param OutputInterface $output Output object * @throws \Exception * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $path = $input->getOption('path'); $context = array(); // if we're not given a path at all, try to figure it out if ($path === null) { $path = php_ini_loaded_file(); } if (!is_file($path)) { throw new \Exception('Path is null or not accessible: "' . $path . '"'); } $scan = new \Psecio\Iniscan\Scan($path, $context); $scan->execute(); $scan->getMarked(); $result = pathinfo($path); // to start, we need a backup of the file (overwrite if there) $backupPath = './' . $result['basename'] . '-' . date('mdy'); copy($path, $backupPath); // Now les get our rules and parse them $scan = new \Psecio\Iniscan\Scan($path, $context); $rules = get_object_vars($scan->getRules()); $output->writeLn($this->generateIniOutput($rules)); }