Re: liveuser singelton changes

From: Date: Tue, 11 Oct 2005 10:27:40 +0000
Subject: Re: liveuser singelton changes
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21354@lists.php.net to get a copy of this message
could you please open a bug report on this? thx, Lukas Jeroen Houben wrote:
Jeroen Houben wrote:
Hi, I've read the changelog for the new Liveuser release 0.16.7 Could somebody please explain me in more detail what the changes are in the singleton() method ? I noticed $lu = Liveuser::singleton($conf) does not return an instance anymore, but it's not clear to me (from the changelog or the API docs) how I would now create a new instance. Jeroen
Okay so a simple $lu = Liveuser::singleton($conf, 'somename'); will do the trick. The API docs however state that the signature be an array. This should be changed to string. Also, I think it would be nice if a simple call to $lu = Liveuser::singleton($conf) would still work. I think you could do this by changing the method slightly:
    function &singleton(&$conf, $signature = null)
    {
        static $instances;
        if (!isset($instances)) {
            $instances = array();
        }
        if (is_null($signature)) {
            if (empty($instances)) {
                $signature = uniqid();
            } else {
                $signature = key($instances);
            }
    } elseif (!array_key_exists($signature, $instances)) {
            $instances[$signature] =& LiveUser::factory($conf);
        }
        return $instances[$signature];
    }
This would create a default signature and I think BC could be preserved this way. Jeroen


« previous php.pear.general (#21354) next »