Skip to content

Conversation

@gessyken
Copy link
Contributor

@gessyken gessyken commented Jan 2, 2026

Add support for defining routes using PHP 8 attributes on controller classes.

Controllers can use #[Controller] attribute with prefix and middleware, and methods
can use #[Get], #[Post], #[Put], #[Delete], #[Patch] attributes to define routes.

The Router::register() method automatically discovers and registers routes from
controller classes. Includes 22 tests.

@papac
Copy link
Member

papac commented Jan 3, 2026

Why did you avoid environment loading errors. This is the best observability pattern to know if the .env.json or the .env define

@gessyken
Copy link
Contributor Author

gessyken commented Jan 3, 2026

Why did you avoid environment loading errors. This is the best observability pattern to know if the .env.json or the .env define

You're right. I added the try-catch to avoid duplicate errors in tests,
but observability is more important

Fixed - try-catch only checks if env is already loaded, but
Env::configure() exceptions will propagate if .env.json is missing

@papac
Copy link
Member

papac commented Jan 3, 2026

Ah!ok, you can reach out the env config into tests/Config for getting more information.

* @return Router
*/
public function register(string|array $controllers): Router
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$controllers = (array) $controllers;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants