| Total Complexity | 5 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 25% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Modular extends Composite |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @inheritdoc |
||
| 17 | * |
||
| 18 | * can accept parameters. |
||
| 19 | * |
||
| 20 | * - {moduleId}: the unique module id associated to this rule. |
||
| 21 | */ |
||
| 22 | public string $notFoundMessage = 'Unknown route for module `{moduleId}`.'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string unique id to grab the module from the application that will |
||
| 26 | * parse the rules. |
||
| 27 | */ |
||
| 28 | public string $moduleId; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @inheritdoc |
||
| 32 | */ |
||
| 33 | 44 | protected function isApplicable(string $route): bool |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @inheritdoc |
||
| 41 | */ |
||
| 42 | protected function createRules() |
||
| 43 | { |
||
| 44 | $this->moduleId ?: throw new InvalidConfigException( |
||
| 45 | $this::class . '::$moduleId must be set.' |
||
| 46 | ); |
||
| 47 | |||
| 48 | $module = Yii::$app->getModule($this->moduleId); |
||
| 49 | if (!$module instanceof UrlRuleCreator) { |
||
| 50 | throw new InvalidConfigException( |
||
| 51 | "Module `{$this->moduleId}` must implement " |
||
| 52 | . UrlRuleCreator::class |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | return $module->createUrlRules($this); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @inheritdoc |
||
| 61 | */ |
||
| 62 | protected function createNotFoundException(): NotFoundHttpException |
||
| 66 | ); |
||
| 67 | } |
||
| 69 |