Repository navigation
Releases: emmadesilva/microserve
Release list
v2.0.0 - New major release
What's Changed
- Refactor Response class to buffer headers by @caendesilva in #5
- Change response send methods to return self instead of void by @caendesilva in #7
- Use static returns instead of self by @caendesilva in #8
- Update
Response::make()to automatically send responses by @caendesilva in #10 - Update the Application class to send the response instead of the make method by @caendesilva in #12
- Create HtmlResponse class by @caendesilva in #13
- Microserve v2.0 by @caendesilva in #11
Full Changelog: v1.0.5...v2.0.0
Release Notes for v2.0
Breaking/Major Changes
- Breaking: The
ResponseInterface::send()method now returnsstaticinstead ofvoid. This change affects the interface and all implementing classes. - Major: The Application class now automatically sends the response returned by the Kernel.
New Features
- Headers are now buffered in the Response class instead of being sent immediately.
- New protected
sendHeaders()method added to the Response class for sending all buffered headers. - New
HtmlResponseclass added for handling HTML responses with appropriate headers.
Improvements
- The
Response::send()andJsonResponse::send()methods now return$this, allowing for method chaining and providing more flexibility when working with responses. - The application now automatically sends the response returned by the Kernel, removing the need to call
send()manually. This fixes a common "gotcha" where users forget to callsend()after creating a response. - Type hints now use
staticreturns instead ofselfto more accurately reflect the return type of the methods. - More flexibility in manipulating headers throughout the response lifecycle.
- Better alignment with common practices in modern PHP frameworks.
Upgrade Guide
If you're upgrading from v1.x to v2.0, here are the key changes you need to be aware of:
Response::send() Method Return Type
-
The
send()method in theResponseInterfacenow has a return type ofstatic. This is a breaking change as it requires all implementing classes to update their method signature. -
If you have any custom classes implementing
ResponseInterface, you must update theirsend()method to returnstatic:public function send(): static { // Your implementation return $this; }
Please review your codebase for any implementations of ResponseInterface and update them accordingly. This change is made to allow for method chaining and provide more flexibility when working with responses, and to allow for working with sent responses in a more fluent way.
Response Creation and Sending
The Application class is now responsible for sending the response after the kernel handles the request, meaning you should no longer call send() manually after creating a response.
Example of updated usage:
// In your HttpKernel or similar class
public function handle(Request $request): Response
{
return Response::make(200, 'OK', ['body' => 'Hello World!']);
// OR: return new Response(200, 'OK', ['body' => 'Hello World!']);
}
// In your application entry point
$app = new Application(new MyHttpKernel());
$app->handle(); // This will now send the responsePlease review your codebase for any cases where you send responses manually, as it's no longer necessary to call send() after creating a response. The application will automatically send the response returned by the kernel.
Header Sending Changes
- The
withHeaders()method now adds headers to a buffer instead of sending them immediately. If you were relying on immediate header sending, you may need to adjust your code. - Headers are now sent when the
send()method is called on the Response object. Make sure you're callingsend()at the appropriate time in your application lifecycle. - If you've extended the Response or JsonResponse classes, you may need to update your implementations to work with the new buffered header approach.
- Update any tests that were checking for immediate header sending. You may need to use reflection or mock the header functions to test the new buffering behavior.
New HtmlResponse Class
A new HtmlResponse class has been added to handle HTML responses. This class automatically sets the appropriate Content-Type and Content-Length headers for HTML content. If you're returning HTML responses, consider using this new class:
use Desilva\Microserve\HtmlResponse;
// In your HttpKernel or similar class
public function handle(Request $request): Response
{
return new HtmlResponse(200, 'OK', ['body' => '<html><body>Hello World!</body></html>']);
}Conclusion
If you encounter any issues during the upgrade process, please open an issue on the GitHub repository.
v1.0.5 - End of Life Notice for v1.x
v1.0.4 - Clean up repository
Full Changelog: v1.0.3...v1.0.4
v1.0.3 - Update code style
Full Changelog: v1.0.2...v1.0.3
v1.0.2 - Update code style
Full Changelog: v1.0.1...v1.0.2
v1.0.1 - Add test suite
v1.0.0 - Initial Release
What's Changed
- Apply fixes from StyleCI by @caendesilva in #2
New Contributors
- @caendesilva made their first contribution in #2
Full Changelog: https://github.com/caendesilva/microserve/commits/v1.0.0