Skip to content

Commit

Permalink
fixed reserved keywords for programtic usage
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalkaoz committed Dec 24, 2018
1 parent 2347b09 commit 625fde9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $driver = $container[IPFS\Driver\Cli::class];
//$driver = $container[IPFS\Driver\Http::class];
$client = new IPFS\Client($driver);

$reponse = $client->execute((new \IPFS\Api\Basics())->version());
$response = $client->execute((new \IPFS\Api\Basics())->version());

var_dump($response);
```
Expand Down
8 changes: 7 additions & 1 deletion src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public function getAction(): string
$parts = explode('\\', $this->method);
$shortName = array_pop($parts);

return CaseFormatter::camelToColon(str_replace('::', ':', $shortName));
$name = CaseFormatter::camelToColon(str_replace('::', ':', $shortName));

// correct some naming workaround due to reserved keywords
$name = str_replace('basics:', '', $name);
$name = str_replace('cobject:', 'object:', $name);

return $name;
}

public function getArguments(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function buildCommand(Command $command): array
{
return array_merge(
[$this->binary],
explode(':', str_replace('basics:', '', $command->getAction())),
explode(':', $command->getAction()),
$this->parseParameters($command)
);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/spec/Command/CommandSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ public function it_can_convert_the_method_to_an_action()
{
$this->getAction()->shouldBe('command:spec:foo:bar:bazz');
}

public function it_will_revert_reserved_keywords_workaround()
{
$this->beConstructedWith('cobject' . '::fooBarBazz');

$this->getAction()->shouldBe('object:foo:bar:bazz');
}

public function it_will_strip_basic_commands()
{
$this->beConstructedWith('basics' . '::fooBarBazz');

$this->getAction()->shouldBe('foo:bar:bazz');
}
}

0 comments on commit 625fde9

Please sign in to comment.