|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drall\Model; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Input\InputInterface; |
| 6 | + |
| 7 | +class SiteDetectorOptions { |
| 8 | + |
| 9 | + private ?string $filter = NULL; |
| 10 | + |
| 11 | + private ?string $group = NULL; |
| 12 | + |
| 13 | + private ?int $limit = NULL; |
| 14 | + |
| 15 | + private ?int $offset = NULL; |
| 16 | + |
| 17 | + public function __construct() {} |
| 18 | + |
| 19 | + public static function fromInput(InputInterface $input): SiteDetectorOptions { |
| 20 | + $options = new SiteDetectorOptions(); |
| 21 | + |
| 22 | + if ( |
| 23 | + $input->hasOption('group') && |
| 24 | + $group = $input->getOption('group') ?? getenv('DRALL_GROUP') |
| 25 | + ) { |
| 26 | + $options->setGroup($group); |
| 27 | + } |
| 28 | + |
| 29 | + if ( |
| 30 | + $input->hasOption('filter') && |
| 31 | + $filter = $input->getOption('filter') |
| 32 | + ) { |
| 33 | + $options->setFilter($filter); |
| 34 | + } |
| 35 | + |
| 36 | + if ( |
| 37 | + $input->hasOption('offset') && |
| 38 | + $offset = $input->getOption('offset') |
| 39 | + ) { |
| 40 | + $options->setOffset($offset); |
| 41 | + } |
| 42 | + |
| 43 | + if ( |
| 44 | + $input->hasOption('limit') && |
| 45 | + $limit = $input->getOption('limit') |
| 46 | + ) { |
| 47 | + $options->setLimit($limit); |
| 48 | + } |
| 49 | + |
| 50 | + return $options; |
| 51 | + } |
| 52 | + |
| 53 | + public function getFilter(): ?string { |
| 54 | + return $this->filter; |
| 55 | + } |
| 56 | + |
| 57 | + public function setFilter(string $filter): static { |
| 58 | + $this->filter = $filter; |
| 59 | + return $this; |
| 60 | + } |
| 61 | + |
| 62 | + public function getGroup(): ?string { |
| 63 | + return $this->group; |
| 64 | + } |
| 65 | + |
| 66 | + public function setGroup(string $group): static { |
| 67 | + $this->group = $group; |
| 68 | + return $this; |
| 69 | + } |
| 70 | + |
| 71 | + public function getOffset(): ?int { |
| 72 | + return $this->offset; |
| 73 | + } |
| 74 | + |
| 75 | + public function setOffset(int $offset): static { |
| 76 | + $this->offset = $offset; |
| 77 | + return $this; |
| 78 | + } |
| 79 | + |
| 80 | + public function getLimit(): ?int { |
| 81 | + return $this->limit; |
| 82 | + } |
| 83 | + |
| 84 | + public function setLimit(int $limit): static { |
| 85 | + if ($limit < 1) { |
| 86 | + throw new \ValueError('Limit must be a positive integer'); |
| 87 | + } |
| 88 | + |
| 89 | + $this->limit = $limit; |
| 90 | + return $this; |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments