Re: Class not functioning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry, and then I didn't keep it on list :-(

Shawn McKenzie wrote:
> Please reply to the list.  Just google for "php registry pattern". Here is a very basic example.  There are better OOP people here than I.
> 
> class Registry {
>     protected $_objects = array();
> 
>     function set($name, &$object) {
>         $this->_objects[$name] =& $object;
>     }
> 
>     function &get($name) {
>         return $this->_objects[$name];
>     }
> 
> }
> 
> // in main code somewhere
> $Registry = new Registry;
> $Meetgreet = new Meetgreet;
> $Notify = new Notifier;
> $Registry->set('Meetgreet';, $Meetgreet);
> $Registry->set('Notify', $Notify);
> 
> // in Meetgreet
> $Registry = new Registry;
> $Notify = $Registry->get('Notify');
> 
> I'll post a singleton when I have more time.
> 
> Allen McCabe wrote:
>> Thank you for your response! Your answer is intriguing, and I would
>> love some extrapolation!
>>  
>> Meetgreet is only needed on 1, maybe 2 pages, so including it globally
>> is not needed, and because all meetgreet business is done on a single
>> page, so it is currently uncessary (however I will admit it isn't
>> extendible this way).
>>  
>> So what is this registry pattern you speak of?
>>  
>> Thanks!
>> Allen
>>
>> On Tue, Dec 15, 2009 at 2:30 PM, Shawn McKenzie <nospam@xxxxxxxxxxxxx
>> <mailto:nospam@xxxxxxxxxxxxx>> wrote:
>>
>>     Allen McCabe wrote:
>>     > Hey all (and Nirmalya, thanks for the help!),
>>     >
>>     >
>>     > I have a question that I just can't seem to find via Google.
>>     >
>>     > I want to be able to add messages to a qeue whenever my classes
>>     complete (or
>>     > fail to complete) specific functions. I think have a call within
>>     my html to
>>     > my Notifier class to print all qeued messages (via a function
>>     'printQ').
>>     >
>>     > How do I access a globally instantiated class from within
>>     another class?
>>     >
>>     > Example:
>>     >
>>     > <?php
>>     >
>>     > // INSTANTIATE
>>     > $Meetgreet = new Meetgreet;
>>     > $Notify = new Notifier;
>>     >
>>     > ...
>>     > ...
>>     >
>>     > $Meetgreet->deleteSingle($id, 1); // This completes a function
>>     within
>>     > Meetgreet class. That function needs to be able to use the
>>     Notifier function
>>     > addtoQ(), how would this be accomplished?
>>     >
>>     > ?>
>>     > ...
>>     > ...
>>     >
>>
>>     Several ways to do it.  One would be to make the Meetgreet a singleton
>>     if it really is, and then use its static getInstance.  I would
>>     probably
>>     use a registry pattern though.
>>
>>     --
>>     Thanks!
>>     -Shawn
>>     http://www.spidean.com <http://www.spidean.com/>
>>
>>
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux