Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Updating to Hamlet 3.2 - #4152

Merged
NateBrady23 merged 5 commits into
TechEmpower:masterfrom
vasily-kartashov:master
Oct 24, 2018
Merged

NateBrady23 merged 5 commits into
TechEmpower:masterfrom
vasily-kartashov:master

Conversation

@vasily-kartashov

Copy link
Copy Markdown
Contributor

No description provided.


public function getResponse(Request $request): Response
{
if ($this->json) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Out of curiosity, might you see better results if you create two different resources that implement WebResource, like PlaintextResource and JsonResource? Having to hit this conditional on every request seems like an unnecessary expense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Generally speaking the resources in Hamlet should be organised not around formats, but around data they send back.

Resource -> checks method types, negotiates content type, produces data, defines appropriate response code, wraps data into appropriate entity

Entity -> knows how to format data and send appropriate entity-specific headers.

Response -> pretty much a collection of status code + headers + entity.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see what you're saying. Just pointing out that this HelloResource class could be broken up into two different classes instead of instantiating the same class with a json boolean and performing that extra conditional on every request. For benchmarking purposes, hundreds of thousands of requests checking on that boolean is some non-zero expense. I was thinking:

class PlaintextResource implements WebResource
{
     public function getResponse(Request $request): Response
    {
       $entity = new PlainTextEntity('Hello, World!');
        return new SimpleOKResponse($entity);
    }
}

And another for the json route. In the same way you have the db, update, and fortunes resources. Just a thought to save some ticks.

@NateBrady23
NateBrady23 merged commit 2b95cc2 into TechEmpower:master Oct 24, 2018
roberthusak pushed a commit to roberthusak/FrameworkBenchmarks that referenced this pull request Nov 6, 2018
* Updating to Hamlet 3.1

* Updating to Hamlet 3.2

* uncomment a line
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants