thephpleague / oauth2-client

Easy integration with OAuth 2.0 service providers.
http://oauth2-client.thephpleague.com
MIT License
3.64k stars 751 forks source link

Extend type hint for redirect URI #962

Closed okorneliuk closed 2 years ago

okorneliuk commented 2 years ago

I would like to have the ability to use class implementing \Stringable for redirect URI. If it makes sense, I can create a PR.

okorneliuk commented 2 years ago

This could be one of elegant ways to provide redirect URI:

<?php

namespace App\OAuth2;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class RedirectUri implements \Stringable
{
    private UrlGeneratorInterface $urlGenerator;

    public function __construct(UrlGeneratorInterface $urlGenerator)
    {
        $this->urlGenerator = $urlGenerator;
    }

    public function __toString(): string
    {
        return $this->urlGenerator->generate('oauth2_connect_callback');
    }
}
okorneliuk commented 2 years ago

Closing the issue due to missing polyfills for Stringable for PHP <7.1 and we should support >=5.6. At this point, we can cast to (string) when initialize a provider.