|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * This is mostly taken from ddelnano/dredd-hooks-php |
| 6 | + */ |
| 7 | + |
| 8 | +use Dredd\Server; |
| 9 | +use Dredd\Hooks; |
| 10 | + |
| 11 | +ini_set('implicit_flush', 'on'); |
| 12 | +ini_set('output_buffering', 'off'); |
| 13 | + |
| 14 | + |
| 15 | +$loaded = false; |
| 16 | +foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) { |
| 17 | + if (file_exists($file)) { |
| 18 | + require $file; |
| 19 | + $loaded = true; |
| 20 | + break; |
| 21 | + } |
| 22 | +} |
| 23 | +if (!$loaded) { |
| 24 | + die( |
| 25 | + 'You need to set up the project dependencies using the following commands:' . PHP_EOL . |
| 26 | + 'wget http://getcomposer.org/composer.phar' . PHP_EOL . |
| 27 | + 'php composer.phar install' . PHP_EOL |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +// Load Laravel |
| 32 | +$app = require $devPath . '/bootstrap/app.php'; |
| 33 | +$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); |
| 34 | + |
| 35 | +// Get options from the command line |
| 36 | +$options = getopt('', [ |
| 37 | + 'host:', |
| 38 | + 'port:', |
| 39 | + 'force', |
| 40 | +]); |
| 41 | + |
| 42 | +// Second argument is the single kernel file |
| 43 | +$dreddKernel = $argv[1]; |
| 44 | +$dreddKernelFile = file_get_contents($dreddKernel); |
| 45 | + |
| 46 | +$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7); |
| 47 | + |
| 48 | +try { |
| 49 | + $stmts = $parser->parse($dreddKernelFile); |
| 50 | + // $stmts is an array of statement nodes |
| 51 | +} catch (PhpParser\Error $e) { |
| 52 | + echo 'Parse Error: ', $e->getMessage(); |
| 53 | +} |
| 54 | + |
| 55 | +$namespace = ''; |
| 56 | +$class = ''; |
| 57 | + |
| 58 | +if ($stmts[0] instanceof PhpParser\Node\Stmt\Namespace_) { |
| 59 | + $namespace = implode('\\', $stmts[0]->name->parts); |
| 60 | + foreach ($stmts[0]->stmts as $statement) { |
| 61 | + if ($statement instanceof PhpParser\Node\Stmt\Class_) { |
| 62 | + $class = $statement->name; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +$kernelClass = $namespace . '\\' . $class; |
| 68 | +$kernel = new $kernelClass; |
| 69 | + |
| 70 | +$kernel->handle(new \Netsells\Dredd\Hook()); |
| 71 | + |
| 72 | +$host = array_key_exists('host', $options) |
| 73 | + ? $options['host'] |
| 74 | + : '127.0.0.1'; |
| 75 | +$port = array_key_exists('port', $options) |
| 76 | + ? $options['port'] |
| 77 | + : 61321; |
| 78 | + |
| 79 | +$server = new Server($host, $port); |
| 80 | + |
| 81 | +fprintf(STDOUT, "Starting server\n"); |
| 82 | +flush(); |
| 83 | + |
| 84 | +$server->run(array_key_exists('force', $options)); |
0 commit comments