Ejemplo n.º 1
0
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $dryRun = false;
     $diff = false;
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'd':
                 $dryRun = true;
                 break;
             case 'D':
                 $diff = true;
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
         }
     }
     $this->parser->listInputs($path);
     if (empty($path)) {
         return $this->usage();
     }
     $phpCsFixer = Console\Processus::locate('php-cs-fixer');
     $configurationFile = resolve('hoa://Library/Devtools/Resource/PHPCSFixer/ConfigurationFile.php');
     if (empty($phpCsFixer)) {
         throw new Console\Exception('php-cs-fixer binary is not found.', 0);
     }
     $arguments = ['fix', '--config-file' => $configurationFile];
     if (true === $dryRun) {
         $arguments[] = '--dry-run';
     }
     if (true === $diff) {
         $arguments[] = '--diff';
     }
     $arguments[] = $path;
     $processus = new Console\Processus($phpCsFixer, $arguments);
     $processus->on('input', function () {
         return false;
     });
     $processus->on('output', function (Core\Event\Bucket $bucket) {
         echo $bucket->getData()['line'], "\n";
         return;
     });
     $processus->run();
     return;
 }
Ejemplo n.º 2
0
 /**
  * Use pager set in the environment (i.e. $_ENV['PAGER']).
  *
  * @param   string  $output    Output (from the output buffer).
  * @param   int     $mode      Mode (from the output buffer).
  * @param   string  $type      Type. Please, see self::LESS or self::MORE.
  * @return  string
  */
 public static function pager($output, $mode, $type = null)
 {
     static $process = null;
     if ($mode & PHP_OUTPUT_HANDLER_START) {
         $pager = null !== $type ? Console\Processus::locate($type) : (isset($_ENV['PAGER']) ? $_ENV['PAGER'] : null);
         if (null === $pager) {
             return $output;
         }
         $process = new Console\Processus($pager, null, [['pipe', 'r']]);
         $process->open();
     }
     $process->writeAll($output);
     if ($mode & PHP_OUTPUT_HANDLER_FINAL) {
         $process->close();
     }
     return null;
 }