Re: Singleton behaviour of LiveUser_Admin??

Tim Daeleman <[email protected]>
Newsgroups gmane.comp.php.pear.liveuser
Message-ID <[email protected]>
>>Hi,
>>
>>
>>thanks to your help I got the singleton behaviour for LiveUser working.
>>
>>-- 
>>i.e.
>>$conf = ...full config array...;
>>$oLU = LiveUser::singleton($conf);
>>
>>and inside a class definition then call:
>>
>>$this->oLU = LiveUser::singleton($emptyConf);
>>
>>has me referencing the same LU object.
> 
> 
> we fixed this in CVS and you can now do:
> 
> $LU = LiveUser::singleton($conf);
> LU2 = LiveUser::singleton();
> 
> 
>>-- 
>>
>>When I try to do the same with the LiveUser_Admin class it doesn't work.
>>The reason for this is that I have to submit a autoInit option set to 
>>true for LiveUser_Admin to ork (don't ask me why).
>>
>>So the first part works:
>>
>>-- 
>>$conf = ...full config array...;
>>$oLUA = LiveUser_Admin::singleton($conf);
>>
>>But when I am in a class definition and call
>>
>>$this->oLUA = LiveUser_Admin::singleton($emptyConf);
> 
> 
>>It doesn't work, the already instantiated LU_Admin object isn't "found".
>>And because I don't have access to the config array within the class 
>>definition I can't resubmit it. Just setting $emptyConf["autoInit"] = 
>>true breaks everything even more.
>>
>>Any idea how I can get this to work?? Again I don't want to throw around 
>>config arrays and LU objects.
> 
> 
> Uhm .. that should work.
> 
> this is the implementation .. i dont know how it could give you the 
> original instance again ..
> 
>      function &singleton($conf)
>      {
>          static $instance;
> 
>          if (!isset($instance)) {
>              $obj = &LiveUser_Admin::factory($conf);
>              $instance =& $obj;.
>          }
> 
>          return $instance;
>      }
> 
> 
> does it try to create a new instance with the empty config array?
> 


I haven't had the time yet to debug my code to answer your question. But 
I for new solved it by doing something terrible, I created a 
$_GLOBAL['lu_admin_config'] array (only in the situations when the 
current logged in user has admin rights).

The issue I was describing (without the global stuff) is, I suppose, the 
fact that when I have to add the auto_init "true" value before the the 
admin instance is instantiated "completely". If I don't have it auto 
init it creates an instance without perm and auth parts instanstiated.

cheers,

Tim
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.