Skip to content

Commit

Permalink
Fixed overwrite issue
Browse files Browse the repository at this point in the history
Fixed the issue which allowed devs to overwrite the service and group
  • Loading branch information
EmilJimenez21 authored and nekufa committed Oct 1, 2024
1 parent 6cbd335 commit 177c37f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ public function disconnect(): self

public function service(string $name, string $description, string $version): Service
{
$this->services[$name] = new Service($this, $name, $description, $version);
if (!array_key_exists($name, $this->services)) {
$this->services[$name] = new Service($this, $name, $description, $version);
}

return $this->services[$name];
}
Expand Down
17 changes: 13 additions & 4 deletions src/Service/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ private function stats(): array

public function addGroup(string $name): ServiceGroup
{
$this->groups[$name] = new ServiceGroup($this, $name);
if (!array_key_exists($name, $this->groups)) {
$this->groups[$name] = new ServiceGroup($this, $name);
}

return $this->groups[$name];
}
Expand All @@ -134,6 +136,10 @@ public function addEndpoint(
$queue_group = $options['queue_group'];
}

if (array_key_exists($name, $this->endpoints)) {
throw new \LogicException("Endpoint $name already is defined");
}

$this->endpoints[$name] = new ServiceEndpoint(
$this,
$name,
Expand All @@ -145,9 +151,12 @@ public function addEndpoint(

public function reset(): void
{
array_map(function (ServiceEndpoint $endpoint) {
$endpoint->resetStats();
}, $this->endpoints);
array_map(
function (ServiceEndpoint $endpoint) {
$endpoint->resetStats();
},
$this->endpoints
);
}

private function registerVerbs(): void
Expand Down
4 changes: 3 additions & 1 deletion src/Service/ServiceGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public function __construct(

public function addGroup(string $name): ServiceGroup
{
$this->groups[$name] = new ServiceGroup($this->service, $this->name . '.' . $name);
if (!array_key_exists($name, $this->groups)) {
$this->groups[$name] = new ServiceGroup($this->service, $this->name . '.' . $name);
}

return $this->groups[$name];
}
Expand Down

0 comments on commit 177c37f

Please sign in to comment.