コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
 /**
  * Execute the "scan" command
  *
  * @param  InputInterface $input Input object
  * @param  OutputInterface $output Output object
  * @throws \Psecio\Iniscan\Exceptions\FormatNotFoundException
  * @throws \Exception
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getOption('path');
     $failOnly = $input->getOption('fail-only');
     $format = $input->getOption('format');
     $context = $input->getOption('context');
     $threshold = $input->getOption('threshold');
     $version = $input->getOption('php');
     $outputPath = $input->getOption('output');
     if ($format === 'html' && $outputPath === null) {
         throw new \InvalidArgumentException('Output path must be set for format "HTML"');
     }
     $context = $context !== null ? explode(', ', $context) : array();
     // If we're not given a version, assume the current version
     if ($version === null) {
         $version = PHP_VERSION;
     }
     // 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, $threshold, $version);
     $results = $scan->execute();
     $deprecated = $scan->getMarked();
     $options = array('path' => $path, 'failOnly' => $failOnly, 'deprecated' => $deprecated, 'verbose' => $input->getOption('verbose'), 'output' => $outputPath);
     $format = $format === null ? 'console' : $format;
     $formatClass = "\\Psecio\\Iniscan\\Command\\ScanCommand\\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($results);
 }