Skip to content

2.x Make Timber\Request not implement Timber\CoreInterface#2631

Merged
gchtr merged 1 commit into2.xfrom
2.x-request
Jan 7, 2023
Merged

2.x Make Timber\Request not implement Timber\CoreInterface#2631
gchtr merged 1 commit into2.xfrom
2.x-request

Conversation

@gchtr
Copy link
Copy Markdown
Member

@gchtr gchtr commented Aug 15, 2022

Issue

While working on fixing some PHPStan issues, I found that the Timber\Request class extends Timber\Core and implements Timber\CoreInterface.

In the current state of Timber, I don’t see any reason why it should do so. Even when it was introduced in #853, it wasn’t clearly stated why it should extend Timber\Core.

The method required by Timber\CoreInterface are added as empty functions and they look like they were added only to serve the interface. But this request helper class doesn’t have anything to do with a Timber core object that usually matches core functionality in WordPress.

Solution

Make Timber\Request not implement Timber\CoreInterface.

Impact

This might break backwards compatibility with any class that extends Timber\Request. We will have to add a note to the Upgrade Guide.

Usage Changes

None.

Considerations

We could move this to a future release and not release this breaking change in 2.x. In that case, we would have to add a return to __isset() to fix the PHPStan issue.

I’d really like to get a second opinion on this one.

Testing

No.

@gchtr gchtr added the 2.0 label Aug 15, 2022
@gchtr gchtr mentioned this pull request Nov 4, 2022
1 task
@nlemoine
Copy link
Copy Markdown
Member

nlemoine commented Nov 23, 2022

I’d really like to get a second opinion on this one.

I would personally remove that class:

IMHO, 2.0 would be a good occasion to get rid of it :) Further more, as long as the class isn't used inside Timber, I don't see any valid argument to keep it, especially now we're composer only. If a user wants a request object, let's add a quick how to in the docs:

// composer require nyholm/psr7-server

add_filter('timber/context', function($context) {
    $psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

    $creator = new \Nyholm\Psr7Server\ServerRequestCreator(
        $psr17Factory, // ServerRequestFactory
        $psr17Factory, // UriFactory
        $psr17Factory, // UploadedFileFactory
        $psr17Factory  // StreamFactory
    );

    $context['request'] = $creator->fromGlobals();

    return $context;
});

☝️Now you have a really complete ServerRequest object to play with. And the Timber Team doesn't have to worry about this class anymore.

Now, if we have to keep it, I'll all for leaving CoreInterface out of it but as you said, it's so thin we would have to enhance it which would increase the code base to maintain.

@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Nov 24, 2022

@nlemoine I’m all for removing this 👍. Thank you for providing a different solution using one of the PSR-7 libraries. I added a PR in #2683.

@gchtr gchtr merged commit fcb00e7 into 2.x Jan 7, 2023
@gchtr gchtr deleted the 2.x-request branch January 7, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants