Group.php 721 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Knuckles\Camel\Output;
  3. use Illuminate\Support\Arr;
  4. use Knuckles\Camel\BaseDTO;
  5. class Group extends BaseDTO
  6. {
  7. public string $name;
  8. public ?string $description;
  9. /**
  10. * @var \Knuckles\Camel\Output\EndpointData[] $endpoints
  11. */
  12. public array $endpoints = [];
  13. public static function createFromSpec(array $spec): Group
  14. {
  15. $spec['endpoints'] = array_map(
  16. fn($endpoint) => new EndpointData($endpoint), $spec['endpoints']
  17. );
  18. return new Group($spec);
  19. }
  20. public function has(EndpointData $endpoint)
  21. {
  22. return boolval(Arr::first($this->endpoints, fn(EndpointData $e) => $e->endpointId() === $endpoint->endpointId()));
  23. }
  24. }