| 1 | <?php |
||
| 21 | final class ZoneContext implements Context |
||
| 22 | { |
||
| 23 | /** @var RepositoryInterface */ |
||
| 24 | private $zoneRepository; |
||
| 25 | |||
| 26 | public function __construct(RepositoryInterface $zoneRepository) |
||
| 27 | { |
||
| 28 | $this->zoneRepository = $zoneRepository; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @Transform /^"([^"]+)" zone$/ |
||
| 33 | * @Transform /^zone "([^"]+)"$/ |
||
| 34 | * @Transform /^zone named "([^"]+)"$/ |
||
| 35 | * @Transform :zone |
||
| 36 | * @Transform :otherZone |
||
| 37 | */ |
||
| 38 | public function getZone(string $codeOrName): ZoneInterface |
||
| 39 | { |
||
| 40 | $zone = $this->zoneRepository->findOneBy(['code' => $codeOrName]); |
||
| 41 | if (null !== $zone) { |
||
| 42 | return $zone; |
||
| 43 | } |
||
| 44 | |||
| 45 | $zone = $this->zoneRepository->findOneBy(['name' => $codeOrName]); |
||
| 46 | Assert::notNull( |
||
| 47 | $zone, |
||
| 48 | 'Zone does not exist.' |
||
| 49 | ); |
||
| 50 | |||
| 51 | return $zone; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @Transform /^rest of the world$/ |
||
| 56 | */ |
||
| 57 | public function getRestOfTheWorldZone(): ZoneInterface |
||
| 67 | } |
||
| 68 |