utilities-php /
router
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | |||
| 4 | namespace Utilities\Router; |
||
| 5 | |||
| 6 | use Utilities\Router\Traits\ControllerDefaultTrait; |
||
| 7 | use Utilities\Router\Utils\Assistant; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * AnonymousController class |
||
| 11 | * |
||
| 12 | * @link https://github.com/utilities-php/router |
||
| 13 | * @author Shahrad Elahi (https://github.com/shahradelahi) |
||
| 14 | * @license https://github.com/utilities-php/router/blob/master/LICENSE (MIT License) |
||
| 15 | */ |
||
| 16 | class AnonymousController |
||
| 17 | { |
||
| 18 | |||
| 19 | use ControllerDefaultTrait; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string|null |
||
| 23 | */ |
||
| 24 | protected ?string $key = null; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * AnonymousController constructor. |
||
| 28 | * |
||
| 29 | * @param mixed ...$args |
||
| 30 | */ |
||
| 31 | public function __construct(mixed ...$args) |
||
| 32 | { |
||
| 33 | call_user_func_array([$this, '__process'], [Router::createRequest(), ...$args]); |
||
| 34 | $this->key = is_string($args[0]) ? $args[0] : 'anonymous@' . __CLASS__; |
||
| 35 | Assistant::passDataToMethod($this, $this->key); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Create an instance of the controller for the application |
||
| 40 | * |
||
| 41 | * @param string $slug The slug of the controller |
||
| 42 | * @param string $class The class name |
||
| 43 | * @param string $uri The uri to be matched |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | public static function __create(string $slug, string $class, string $uri): array |
||
| 47 | { |
||
| 48 | return [ |
||
| 49 | $slug => [ |
||
| 50 | 'controller' => $class, |
||
| 51 | 'uri' => str_ends_with($uri, '/') ? substr($uri, 0, -1) : $uri |
||
| 52 | ] |
||
| 53 | ]; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get controller key |
||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public function __routeKeyName(): string |
||
| 62 | { |
||
| 63 | return $this->key; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 64 | } |
||
| 65 | |||
| 66 | } |