From 1ebdffe2a68aa6ec1f26919fc33b4f546bb9a67d Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 13 Aug 2023 23:41:54 +0800 Subject: [PATCH 1/3] Fixed again non-existent env when interpolating vars --- src/Exporters/Abstract/AbstractConverter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Exporters/Abstract/AbstractConverter.php b/src/Exporters/Abstract/AbstractConverter.php index 8115ea8..46cb256 100644 --- a/src/Exporters/Abstract/AbstractConverter.php +++ b/src/Exporters/Abstract/AbstractConverter.php @@ -32,9 +32,9 @@ abstract class AbstractConverter implements ConverterContract protected array $vars = []; /** - * @var Environment + * @var Environment|null */ - protected Environment $env; + protected ?Environment $env = null; /** * Sets an environment with vars @@ -173,11 +173,11 @@ abstract class AbstractConverter implements ConverterContract */ protected function interpolate(string $content): string { - if (empty($this->vars) && !empty($this->env) && $this->env->hasVars()) { + if (empty($this->vars) && !$this->env?->hasVars()) { return $content; } $matches = []; - if (preg_match_all('/\{\{[a-zA-Z][a-zA-Z0-9]+}}/', $content, $matches, PREG_PATTERN_ORDER) > 0) { + if (preg_match_all('/\{\{[a-zA-Z][a-zA-Z0-9]*}}/m', $content, $matches, PREG_PATTERN_ORDER) > 0) { foreach ($matches[0] as $key => $var) { if (str_contains($content, $var)) { $content = str_replace($var, $this->vars[$var] ?? $this->env[$var] ?? $var, $content); From 44f437eaf36adc07cf074c04e00f9de6515f012c Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 13 Aug 2023 23:42:24 +0800 Subject: [PATCH 2/3] Misc edits in texts and output --- README.md | 2 +- composer.json | 2 +- src/Processor.php | 25 +++++++++++-------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3e25ba1..73d23a2 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ These formats are supported for now: `http`, `curl`, `wget`. - tests, phpcs, psalm, etc.; - web version. -## Installation +## Install and upgrade ``` composer global r axenov/pm-convert diff --git a/composer.json b/composer.json index 4a1b864..d144c19 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "axenov/pm-convert", "type": "library", - "description": "Postman collection coverter", + "description": "Postman collection converter", "license": "MIT", "homepage": "https://axenov.dev/", "authors": [ diff --git a/src/Processor.php b/src/Processor.php index 9bb8cb2..1dd9c74 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -7,16 +7,15 @@ namespace PmConverter; use Exception; use InvalidArgumentException; use JsonException; -use PmConverter\Exceptions\CannotCreateDirectoryException; -use PmConverter\Exceptions\DirectoryIsNotReadableException; -use PmConverter\Exceptions\DirectoryIsNotWriteableException; -use PmConverter\Exceptions\DirectoryNotExistsException; -use PmConverter\Exporters\ConverterContract; -use PmConverter\Exporters\ConvertFormat; +use PmConverter\Exceptions\{ + CannotCreateDirectoryException, + DirectoryIsNotReadableException, + DirectoryIsNotWriteableException, + DirectoryNotExistsException}; +use PmConverter\Exporters\{ + ConverterContract, + ConvertFormat}; -/** - * - */ class Processor { /** @@ -89,9 +88,6 @@ class Processor * Parses an array of arguments came from cli * * @return void - * @throws DirectoryIsNotWriteableException - * @throws DirectoryNotExistsException - * @throws DirectoryIsNotReadableException */ protected function parseArgs(): void { @@ -285,7 +281,7 @@ class Processor { $time = (hrtime(true) - $this->initTime) / 1_000_000; $ram = (memory_get_peak_usage(true) - $this->initRam) / 1024 / 1024; - printf('Converted %d of %d in %.3f ms using %.3f MiB RAM', $success, $count, $time, $ram); + printf('Converted %d of %d in %.3f ms using %.3f MiB RAM%s', $success, $count, $time, $ram, PHP_EOL); } /** @@ -321,7 +317,7 @@ class Processor '', 'Possible ARGUMENTS:', "\t-f, --file - a PATH to single collection located in PATH to convert from", - "\t-d, --dir - a directory with collections located in COLLECTION_FILEPATH to convert from", + "\t-d, --dir - a directory with collections located in PATH to convert from", "\t-o, --output - a directory OUTPUT_PATH to put results in", "\t-e, --env - use environment file with variable values to replace in request", "\t-p, --preserve - do not delete OUTPUT_PATH (if exists)", @@ -341,6 +337,7 @@ class Processor "\t--http - generate raw *.http files (default)", "\t--curl - generate shell scripts with curl command", "\t--wget - generate shell scripts with wget command", + '', 'If no FORMATS specified then --http implied.', 'Any of FORMATS can be specified at the same time.', '', From af9c3606846a31fd4649affdb92f735e622b539d Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 13 Aug 2023 23:43:21 +0800 Subject: [PATCH 3/3] Bump version --- src/Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processor.php b/src/Processor.php index 1dd9c74..1e15f79 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -21,7 +21,7 @@ class Processor /** * Converter version */ - public const VERSION = '1.2.3'; + public const VERSION = '1.2.4'; /** * @var string[] Paths to collection files