v1.1.0 #1

Merged
anthony merged 3 commits from dev into master 2023-08-04 01:28:44 +00:00
3 changed files with 39 additions and 7 deletions
Showing only changes of commit 882fbe4713 - Show all commits

View File

@ -23,12 +23,11 @@ These formats are supported for now: `http`, `curl`, `wget`.
## Planned features ## Planned features
- support as many as possible/necessary of authentication kinds (_currently no ones_); - support as many as possible/necessary of authentication kinds (_currently no ones_);
- support as many as possible/necessary of body formats (_currently json and formdata_); - support as many as possible/necessary of body formats (_currently only `json` and `formdata`_);
- documentation generation support (markdown) with responce examples (if present); - documentation generation support (markdown) with responce examples (if present);
- maybe some another convert formats (like httpie or something...); - maybe some another convert formats (like httpie or something...);
- replace `{{vars}}` from folder; - replace `{{vars}}` from folder;
- replace `{{vars}}` from environment; - replace `{{vars}}` from environment;
- performance measurement;
- better logging; - better logging;
- tests, phpcs, psalm, etc.; - tests, phpcs, psalm, etc.;
- web version. - web version.

View File

@ -21,7 +21,7 @@ foreach ($paths as $path) {
is_null($file) && throw new RuntimeException('Unable to locate autoload.php file.'); is_null($file) && throw new RuntimeException('Unable to locate autoload.php file.');
try { try {
(new Processor($argv))->start(); (new Processor($argv))->convert();
} catch (Exception $e) { } catch (Exception $e) {
fwrite(STDERR, sprintf('ERROR: %s%s', $e->getMessage(), PHP_EOL)); fwrite(STDERR, sprintf('ERROR: %s%s', $e->getMessage(), PHP_EOL));
die(1); die(1);

View File

@ -54,6 +54,16 @@ class Processor
*/ */
protected array $collections = []; protected array $collections = [];
/**
* @var int Initial timestamp
*/
protected int $init_time;
/**
* @var int Initial RAM usage
*/
protected int $init_ram;
/** /**
* Constructor * Constructor
* *
@ -61,6 +71,8 @@ class Processor
*/ */
public function __construct(protected array $argv) public function __construct(protected array $argv)
{ {
$this->init_time = hrtime(true);
$this->init_ram = memory_get_usage(true);
} }
/** /**
@ -181,22 +193,43 @@ class Processor
* *
* @throws Exception * @throws Exception
*/ */
public function start(): void public function convert(): void
{ {
$this->parseArgs(); $this->parseArgs();
$this->initOutputDirectory(); $this->initOutputDirectory();
$this->initConverters(); $this->initConverters();
$this->initCollections(); $this->initCollections();
$count = count($this->collections);
$current = 1;
$success = 0;
print(implode(PHP_EOL, array_merge($this->version(), $this->copyright())) . PHP_EOL . PHP_EOL); print(implode(PHP_EOL, array_merge($this->version(), $this->copyright())) . PHP_EOL . PHP_EOL);
foreach ($this->collections as $collectionName => $collection) { foreach ($this->collections as $collectionName => $collection) {
print("Converting '$collectionName':" . PHP_EOL); printf("Converting '%s' (%d/%d):%s", $collectionName, $current, $count, PHP_EOL);
foreach ($this->converters as $type => $exporter) { foreach ($this->converters as $type => $exporter) {
print("\t-> " . strtolower($type)); printf(' > %s', strtolower($type));
$outputPath = sprintf('%s%s%s', $this->outputPath, DIRECTORY_SEPARATOR, $collectionName); $outputPath = sprintf('%s%s%s', $this->outputPath, DIRECTORY_SEPARATOR, $collectionName);
$exporter->convert($collection, $outputPath); $exporter->convert($collection, $outputPath);
printf("\t- OK: %s%s", $exporter->getOutputPath(), PHP_EOL); printf(' - OK: %s%s', $exporter->getOutputPath(), PHP_EOL);
} }
print(PHP_EOL);
++$current;
++$success;
} }
$this->printStats($success, $current);
}
/**
* Outputs some statistics
*
* @param int $success
* @param int $count
* @return void
*/
protected function printStats(int $success, int $count): void
{
$time = (hrtime(true) - $this->init_time) / 1_000_000;
$ram = (memory_get_peak_usage(true) - $this->init_ram) / 1024 / 1024;
printf('Converted %d of %d in %.3f ms using %.3f MiB RAM', $success, $count, $time, $ram);
} }
/** /**