Ejemplo n.º 1
0
 public function main()
 {
     $root = '.';
     $address = '127.0.0.1:8888';
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'r':
                 $root = $v;
                 break;
             case 'a':
                 $address = $v;
                 break;
             case 'h':
             case '?':
                 return $this->usage();
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
         }
     }
     if (false === is_dir($root)) {
         throw new Console\Exception('Root %s is not a directory.', 0, $root);
     }
     $processus = new Console\Processus(PHP_BINARY, ['-S' => $address, '-t' => $root]);
     $processus->on('input', function () {
         return false;
     });
     $processus->on('output', function (Event\Bucket $bucket) {
         echo $bucket->getData()['line'], "\n";
     });
     echo 'Server is listening ', $root, ' on ', $address, '.', "\n\n";
     $processus->run();
     return;
 }
Ejemplo n.º 2
0
 /**
  * Main method.
  *
  * @return int
  */
 function main()
 {
     $operation = 0;
     $location = null;
     $updateServer = Updater::DEFAULT_UPDATE_SERVER;
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'f':
                 $operation = static::OPERATION_FETCH | Updater::FORMAT_PHAR;
                 break;
             case 'z':
                 $operation = static::OPERATION_FETCH | Updater::FORMAT_ZIP;
                 break;
             case 'a':
                 $operation = static::OPERATION_APPLY;
                 $location = $v;
                 break;
             case 's':
                 $updateServer = $v;
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
                 break;
         }
     }
     $updateServer = rtrim($updateServer, '/') . '/';
     if (0 !== (static::OPERATION_FETCH & $operation)) {
         $updatesDotJson = Updater::getUpdateUrl($updateServer);
         $versions = @file_get_contents($updatesDotJson);
         if (empty($versions)) {
             throw new Exception\Console('Oh no! We are not able to check if a new version exists… ' . 'Contact us at http://sabre.io/ ' . '(tried URL %s).', 0, $updatesDotJson);
         }
         $versions = json_decode($versions, true);
         /**
          * Expected format:
          *     {
          *         "1.0.1": {
          *             "phar": "https://…",
          *             "zip" : "https://…"
          *         },
          *         "1.0.0": {
          *             "phar": "https://…",
          *             "zip" : "https://…"
          *         },
          *         …
          *     }
          */
         $versionsToFetch = Updater::filterVersions($versions, Version::VERSION, $operation);
         $windowWidth = Window::getSize()['x'];
         $progress = function ($percent) use($windowWidth) {
             Cursor::clear('↔');
             $message = 'Downloading… ';
             $barWidth = $windowWidth - mb_strlen($message);
             if ($percent <= 0) {
                 $color = '#c74844';
             } elseif ($percent <= 25) {
                 $color = '#cb9a3d';
             } elseif ($percent <= 50) {
                 $color = '#dcb11e';
             } elseif ($percent <= 75) {
                 $color = '#aed633';
             } else {
                 $color = '#54b455';
             }
             echo $message;
             Cursor::colorize('foreground(' . $color . ') background(' . $color . ')');
             echo str_repeat('|', $percent * $barWidth / 100);
             Cursor::colorize('normal');
         };
         foreach ($versionsToFetch as $versionNumber => $versionUrl) {
             list(, $versionUrlBasename) = Uri\split($versionUrl);
             $fileIn = new File\Read($versionUrl, File::MODE_READ, null, true);
             $fileOut = new File\Write(SABRE_KATANA_PREFIX . '/data/share/update/' . $versionUrlBasename);
             echo "\n", 'Fetch version ', $versionNumber, ' from ', $versionUrl, "\n", 'Waiting…', "\n";
             $fileIn->on('connect', function () {
                 Cursor::clear('↔');
                 echo 'Downloading… ';
             });
             $fileIn->on('progress', function (Core\Event\Bucket $bucket) use($progress) {
                 static $previousPercent = 0;
                 $data = $bucket->getData();
                 $current = $data['transferred'];
                 $max = $data['max'];
                 $percent = $current * 100 / $max;
                 $delta = $percent - $previousPercent;
                 if (1 <= $delta) {
                     $previousPercent = $percent;
                     $progress($percent);
                 }
             });
             $fileIn->open();
             $fileOut->writeAll($fileIn->readAll());
             echo "\n", 'Fetched at ', $fileOut->getStreamName(), '.', "\n";
         }
         return 0;
     } elseif (static::OPERATION_APPLY === $operation) {
         if (false === file_exists($location)) {
             throw new Exception\Console('Update %s is not found.', 1, $location);
         }
         $processus = new Console\Processus(Core::getPHPBinary(), [$location, '--extract' => SABRE_KATANA_PREFIX, '--overwrite']);
         $processus->on('input', function () {
             return false;
         });
         $processus->on('output', function (Core\Event\Bucket $bucket) {
             echo $bucket->getData()['line'], "\n";
         });
         $processus->run();
         if (true === $processus->isSuccessful()) {
             echo 'sabre/katana updated!', "\n";
         } else {
             echo 'Something wrong happened!', "\n";
         }
         return $processus->getExitCode();
     } else {
         return $this->usage();
     }
 }
Ejemplo n.º 3
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.º 4
0
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $dryRun = false;
     $classes = [];
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'n':
                 foreach ($this->parser->parseSpecialValue($v) as $namespace) {
                     $namespace = trim(str_replace('.', '\\', $namespace), '\\');
                     if (false === ($pos = strpos($namespace, '\\'))) {
                         throw new Console\Exception('Namespace %s is too short.', 0, $namespace);
                     }
                     $tail = substr($namespace, strpos($namespace, '\\') + 1);
                     $root = resolve('hoa://Library/' . str_replace('\\', '/', $tail));
                     $classes = array_merge($classes, static::findClasses($root, $namespace));
                 }
                 break;
             case 'c':
                 foreach ($this->parser->parseSpecialValue($v) as $class) {
                     $classes[] = $class;
                 }
                 break;
             case 'd':
                 $dryRun = $v;
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
         }
     }
     if (empty($classes)) {
         return $this->usage();
     }
     foreach ($classes as $i => $class) {
         $classes[$i] = str_replace('.', '\\', $class);
     }
     $generator = new \Atoum\PraspelExtension\Praspel\Generator();
     $generator->setTestNamespacer(function ($namespace) {
         $parts = explode('\\', $namespace);
         return implode('\\', array_slice($parts, 0, 2)) . '\\Test\\Praspel\\Unit' . (isset($parts[2]) ? '\\' . implode('\\', array_slice($parts, 2)) : '');
     });
     $phpBinary = Core::getPHPBinary() ?: Console\Processus::localte('php');
     $envVariable = '__HOA_ATOUM_PRASPEL_EXTENSION_' . md5(Core::uuid());
     $reflection = null;
     $buffer = null;
     $reflectionner = new Console\Processus($phpBinary);
     $reflectionner->on('input', function (Core\Event\Bucket $bucket) use($envVariable) {
         $bucket->getSource()->writeAll('<?php' . "\n" . 'require_once \'' . dirname(__DIR__) . DS . '.bootstrap.atoum.php\';' . "\n" . '$class = getenv(\'' . $envVariable . '\');' . "\n" . 'if (class_exists(\'\\mageekguy\\atoum\\scripts\\runner\', false)) {' . "\n" . '    \\atoum\\scripts\\runner::disableAutorun();' . "\n" . '}' . "\n" . '$reflection = new \\Atoum\\PraspelExtension\\Praspel\\Reflection\\RClass($class);' . "\n" . 'echo serialize($reflection), "\\n";');
         return false;
     });
     $reflectionner->on('output', function (Core\Event\Bucket $bucket) use(&$buffer) {
         $data = $bucket->getData();
         $buffer .= $data['line'] . "\n";
         return;
     });
     $reflectionner->on('stop', function () use(&$buffer, &$reflection) {
         $handle = @unserialize($buffer);
         if (false === $handle) {
             echo $buffer, "\n";
             return;
         }
         $reflection = $handle;
         return;
     });
     foreach ($classes as $class) {
         $status = $class . ' (in ';
         echo '  ⌛ ', $status;
         putenv($envVariable . '=' . $class);
         $buffer = null;
         $reflection = null;
         $reflectionner->run();
         $output = $generator->generate($reflection);
         $parts = explode('\\', $class);
         $paths = resolve('hoa://Library/' . $parts[1] . '/' . 'Test/Praspel/Unit/' . implode('/', array_slice($parts, 2)) . '.php', false, true);
         $max = 0;
         $thePath = 0;
         foreach ($paths as $path) {
             $length = Ustring\Search::lcp($reflection->getFilename(), $path);
             if ($length > $max) {
                 $thePath = $path;
             }
         }
         $statusTail = (40 < strlen($thePath) ? '…' . substr($thePath, -39) : $thePath) . ')';
         echo $statusTail;
         $status .= $statusTail;
         if (false === $reflection->isInstantiable()) {
             Console\Cursor::clear('↔');
             echo '  ⚡️ ', $status, '; not instantiable.', "\n";
             continue;
         }
         $dirname = dirname($thePath);
         if (false === is_dir($dirname)) {
             if (false === $dryRun) {
                 mkdir($dirname, 0755, true);
             } else {
                 echo "\n", static::info('Creating directory: ' . $dirname . '.');
             }
         }
         if (false === $dryRun) {
             file_put_contents($thePath, $output);
         } else {
             echo "\n", static::info('Content of the ' . $thePath . ':'), "\n";
             Console\Cursor::colorize('foreground(yellow)');
             echo '    ┏', "\n", '    ┃  ', str_replace("\n", "\n" . '    ┃  ', trim($output)), "\n", '    ┗', "\n";
             Console\Cursor::colorize('foreground(normal)');
         }
         Console\Cursor::clear('↔');
         echo '  ', Console\Chrome\Text::colorize('✔︎', 'foreground(green)'), ' ', $status, "\n";
     }
     return;
 }