Giter VIP home page Giter VIP logo

Comments (4)

DeepDiver1975 avatar DeepDiver1975 commented on June 2, 2024

It works well enough, but I don't think overriding protected methods is good practice... If the methods change in the original lib my workaround will stop working.

This is the reason why protected methods exists - to allow overriding them.

Your approach is the recommended way and it is done like that in many places.

We also use this concept to change the behavior in many other scenarios as well.

from openid-connect-php.

ricklambrechts avatar ricklambrechts commented on June 2, 2024

Nice idea!

We are using the following for Laravel:

class OpenIDConnectClient extends BaseOpenIDConnectClient
{

    protected function startSession(): void
    {
        // Laravel magic in the background :)
    }

    protected function commitSession(): void
    {
        Session::save();
    }

    /**
     * @param string $key
     */
    protected function getSessionKey($key): mixed
    {
        if (!Session::has($key)) {
            return false;
        }

        return Session::get($key);
    }

    /**
     * @param string $key
     * @param mixed $value mixed
     */
    protected function setSessionKey($key, $value): void
    {
        Session::put($key, $value);
    }

    /**
     * @param string $key
     */
    protected function unsetSessionKey($key): void
    {
        Session::remove($key);
    }

    /**
     * Overwrite the redirect method to use Laravel's abort method.
     * Sometimes the error 'Cannot modify header information - headers already sent' was thrown.
     * By using Laravel's abort method, this error is prevented.
     * @param string $url
     * @return void
     */
    public function redirect($url): void
    {
        App::abort(302, '', ['Location' => $url]);
    }
}

from openid-connect-php.

DeepDiver1975 avatar DeepDiver1975 commented on June 2, 2024

refs https://github.com/owncloud/openidconnect/blob/a50aeabd4730a64e5a579b0537eabffb1c680de3/lib/Client.php#L322-L349

from openid-connect-php.

nicolus avatar nicolus commented on June 2, 2024

This is the reason why protected methods exists - to allow overriding them.

Fair enough, I'll stick to what we have then.

Thanks !

@ricklambrechts : I'll steal some of that, it's a bit better than my version ;-)

from openid-connect-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.