AutoRoute 2.0.0 Released, With Value Object Support
source link: http://paul-m-jones.com/post/2021/08/25/autoroute-200-released-with-value-object-support/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
AutoRoute 2.0.0 Released, With Value Object Support
I am proud to announce that I have released AutoRoute 2.0.0, now for PHP 8. As an alternative to regex and annotation-based routers, AutoRoute eliminates the need for route definitions by automatically mapping the HTTP action class hierarchy to the HTTP method verb and URL path, reflecting on typehinted action method parameters to determine the dynamic portions of the URL. It presumes that the action class names conform to a well-defined convention, and that the action method parameters indicate the dynamic portions of the URL. This makes the implementation both flexible and relatively maintenance-free.
Of special importance, you can now use value objects as action parameters, and AutoRoute will automatically instantiate them for you. This means things like self-validating value objects, including DDD Identity value objects, are now trivial to work with in your action classes.
For example, whereas you might have done something like this previously ...
// GET /company/1
class GetCompany
{
public function __invoke(int $id)
{
$companyId = new CompanyId($id);
$company = $this->serviceLayer->fetchCompany($companyId);
// ...
}
}
... AutoRoute can now instantiate the CompanyId for you from the appropriate path segment:
// GET /company/1
class GetCompany
{
public function __invoke(CompanyId $companyId)
{
$company = $this->serviceLayer->fetchCompany($companyId);
// ...
}
}
AutoRoute 2.0.0 is still faster than FastRoute, though not by as much as the 1.x series; it has dropped from about three times as fast to about two times as fast. (This is due to some internal rework to support value objects as action arguments.) Even so, remember that routing is only one small part of your HTTP user interface, and is unlikely to be a bottleneck in any case.
Recommend
-
27
README.md AutoRoute AutoRoute automatically maps incoming HTTP requests (by verb and path) to PHP action classes in a specified namespace, reflecting o...
-
12
Quick Tip - Allow A Null Value For An Object That Doesn't Normally Allow It In the PowerShell Slack channel (powershell.slack.com) a question came up along the lines of “I have...
-
8
Data Transfer Object v3 has been released Original – ...
-
12
Announcing Valuable, a library for object-safe value inspectionOver the past few weeks, we have been working on Valuable, a new crate that provides
-
4
AutoRoute Benchmarks This benchmark measures only the provided scenario. It may or may not apply to your situation, and may or may not be indicative of other scenarios. Finally, remember that routing is only one part of your HTTP use...
-
8
AutoRoute 1.x Benchmarks This benchmark measures only the provided scenario. It may or may not apply to your situation, and may or may not be indicative of other scenarios. Finally, remember that routing is only one part of your HTTP...
-
4
AutoRoute is 3x Faster Than FastRoute When I first published
-
9
I have 2 Object of the same String Buffer Class value. The string is equal () method Show Fake result Why? advertisements ...
-
3
Check if an object in a list has a certain value with drools advertisements I have some problems checking if an...
-
5
Contributor ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK