Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d854732143 | |||
|
9b021296eb
|
|||
|
d581afa793
|
|||
| 95ca655eb0 | |||
|
25887a47d3
|
|||
|
1f7816c917
|
|||
|
fb7b4baa32
|
|||
|
2c4eedbf8b
|
|||
| c790adf611 | |||
|
c6094566b4
|
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types = 1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PmConverter\Processor;
|
use PmConverter\Processor;
|
||||||
|
|
||||||
@@ -20,8 +20,13 @@ 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.');
|
||||||
|
|
||||||
|
$processor = new Processor($argv);
|
||||||
try {
|
try {
|
||||||
(new Processor($argv))->convert();
|
$processor->convert();
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
fwrite(STDERR, sprintf('ERROR: %s%s', $e->getMessage(), PHP_EOL));
|
||||||
|
print(implode(PHP_EOL, $processor->usage()));
|
||||||
|
die(1);
|
||||||
} 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);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ abstract class AbstractConverter implements ConverterContract
|
|||||||
*/
|
*/
|
||||||
protected function setVariables(): static
|
protected function setVariables(): static
|
||||||
{
|
{
|
||||||
if ($this->collection->variable) {
|
if (isset($this->collection?->variable)) {
|
||||||
foreach ($this->collection->variable as $var) {
|
foreach ($this->collection->variable as $var) {
|
||||||
$this->vars["{{{$var->key}}}"] = $var->value;
|
$this->vars["{{{$var->key}}}"] = $var->value;
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ abstract class AbstractConverter implements ConverterContract
|
|||||||
*/
|
*/
|
||||||
protected function interpolate(string $content): string
|
protected function interpolate(string $content): string
|
||||||
{
|
{
|
||||||
if (empty($this->vars) && $this->env->hasVars()) {
|
if (empty($this->vars) && !empty($this->env) && $this->env->hasVars()) {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class WgetRequest extends AbstractRequest
|
|||||||
$output[] = http_build_query($params);
|
$output[] = http_build_query($params);
|
||||||
return $output;
|
return $output;
|
||||||
default:
|
default:
|
||||||
return ["\t$this->body"];
|
return ["\t'$this->body' \ "];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,6 @@ class WgetRequest extends AbstractRequest
|
|||||||
$this->prepareHeaders(),
|
$this->prepareHeaders(),
|
||||||
$this->prepareBody()
|
$this->prepareBody()
|
||||||
);
|
);
|
||||||
$output[] = rtrim(array_pop($output), '\ ');
|
|
||||||
$output[] = "\t'$this->url'";
|
$output[] = "\t'$this->url'";
|
||||||
return implode(PHP_EOL, array_merge($output, ['']));
|
return implode(PHP_EOL, array_merge($output, ['']));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types = 1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace PmConverter;
|
namespace PmConverter;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Processor
|
|||||||
/**
|
/**
|
||||||
* Converter version
|
* Converter version
|
||||||
*/
|
*/
|
||||||
public const VERSION = '1.2.0';
|
public const VERSION = '1.2.3';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[] Paths to collection files
|
* @var string[] Paths to collection files
|
||||||
@@ -167,6 +167,9 @@ class Processor
|
|||||||
if (empty($this->collectionPaths)) {
|
if (empty($this->collectionPaths)) {
|
||||||
throw new InvalidArgumentException('there are no collections to convert');
|
throw new InvalidArgumentException('there are no collections to convert');
|
||||||
}
|
}
|
||||||
|
if (empty($this->outputPath)) {
|
||||||
|
throw new InvalidArgumentException('-o is required');
|
||||||
|
}
|
||||||
if (empty($this->formats)) {
|
if (empty($this->formats)) {
|
||||||
$this->formats = [ConvertFormat::Http->name => ConvertFormat::Http];
|
$this->formats = [ConvertFormat::Http->name => ConvertFormat::Http];
|
||||||
}
|
}
|
||||||
@@ -226,6 +229,9 @@ class Processor
|
|||||||
*/
|
*/
|
||||||
protected function initEnv(): void
|
protected function initEnv(): void
|
||||||
{
|
{
|
||||||
|
if (!isset($this->envFile)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$content = file_get_contents(FileSystem::normalizePath($this->envFile));
|
$content = file_get_contents(FileSystem::normalizePath($this->envFile));
|
||||||
$content = json_decode($content, flags: JSON_THROW_ON_ERROR);
|
$content = json_decode($content, flags: JSON_THROW_ON_ERROR);
|
||||||
if (!property_exists($content, 'environment') || empty($content?->environment)) {
|
if (!property_exists($content, 'environment') || empty($content?->environment)) {
|
||||||
@@ -285,7 +291,7 @@ class Processor
|
|||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
protected function version(): array
|
public function version(): array
|
||||||
{
|
{
|
||||||
return ["Postman collection converter v" . self::VERSION];
|
return ["Postman collection converter v" . self::VERSION];
|
||||||
}
|
}
|
||||||
@@ -293,7 +299,7 @@ class Processor
|
|||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
protected function copyright(): array
|
public function copyright(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Anthony Axenov (c) ' . date('Y') . ", MIT license",
|
'Anthony Axenov (c) ' . date('Y') . ", MIT license",
|
||||||
@@ -304,7 +310,7 @@ class Processor
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function usage(): array
|
public function usage(): array
|
||||||
{
|
{
|
||||||
return array_merge($this->version(), [
|
return array_merge($this->version(), [
|
||||||
'Usage:',
|
'Usage:',
|
||||||
|
|||||||
Reference in New Issue
Block a user