Skip to content

Releases: emmadesilva/microserve

v2.0.0 - New major release

Choose a tag to compare

@emmadesilva emmadesilva released this 14 Jul 19:42
a1fca65

What's Changed

Full Changelog: v1.0.5...v2.0.0

Release Notes for v2.0

Breaking/Major Changes

  • Breaking: The ResponseInterface::send() method now returns static instead of void. 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 HtmlResponse class added for handling HTML responses with appropriate headers.

Improvements

  • The Response::send() and JsonResponse::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 call send() after creating a response.
  • Type hints now use static returns instead of self to 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

  1. The send() method in the ResponseInterface now has a return type of static. This is a breaking change as it requires all implementing classes to update their method signature.

  2. If you have any custom classes implementing ResponseInterface, you must update their send() method to return static:

    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 response

Please 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

  1. 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.
  2. Headers are now sent when the send() method is called on the Response object. Make sure you're calling send() at the appropriate time in your application lifecycle.
  3. If you've extended the Response or JsonResponse classes, you may need to update your implementations to work with the new buffered header approach.
  4. 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

Choose a tag to compare

@emmadesilva emmadesilva released this 14 Jul 19:39
5cd786b

What's Changed

Full Changelog: v1.0.4...v1.0.5

v1.0.4 - Clean up repository

Choose a tag to compare

@emmadesilva emmadesilva released this 14 Jul 10:17
d4bf1ed

Full Changelog: v1.0.3...v1.0.4

v1.0.3 - Update code style

Choose a tag to compare

@emmadesilva emmadesilva released this 14 Jul 10:15
2740242

Full Changelog: v1.0.2...v1.0.3

v1.0.2 - Update code style

Choose a tag to compare

@emmadesilva emmadesilva released this 14 Jul 09:41
032c3f1

Full Changelog: v1.0.1...v1.0.2

v1.0.1 - Add test suite

Choose a tag to compare

@emmadesilva emmadesilva released this 13 Jul 21:12
11ca57c

What's Changed

Full Changelog: v1.0.0...v1.0.1

v1.0.0 - Initial Release

Choose a tag to compare

@emmadesilva emmadesilva released this 04 Jun 12:09

What's Changed

New Contributors

Full Changelog: https://github.com/caendesilva/microserve/commits/v1.0.0