Jump to content

A few questions about my use of registry and arrayaccess


deadonarrival

Recommended Posts

I have my registry which implements arrayaccess, and a class called router which controls which page/module my system will use.

 

In my startup page I run the following.

$reg['router']->resolve();

$reg->add("module",$reg['router']->module);

 

Resolve simply gets the module and get arrays (I use mod_rewrite to put them all in one argument, resolve just splits the url up again into module=val0 key1=val1 key2=val2 etc)

 

A few questions:

1) Should I move the router module of property into the registry? Or should I just call it from the router when needed?

$reg['router']->module just seems so clumsy/

2) Should $_GET variables be part of my router? Or should I move those into my registry and remove them from my router.

3) Are there any performance overheads of using arrayaccess? I'd like to use it more, but I don't want it to slow anything down.

4) Are there any guidelines for it? Should I only use it on classes which are mostly properties?

5) Finally, is the array access an inherited thing - so to speak. If I use both registry and router with arrayaccess, could I above just use $reg['router']['module'] - do the arrays stack?

  • 3 weeks later...

1) From what I have done recently i think my router is separate from the registry (and isn't even placed in it).

2) They are in mine, but i'm not convinced it's the best way. You might be better off having a "request" class that contains all the get parameters for access and utilise that, that way it's encapsulated.

3) No

4) Take a look at Zend framework's router and front controller and request classes, and this url http://www.phpit.net/article/simple-mvc-php5

5) I believe this should work yes, as $reg['router'] will return an object that implements arrayaccess, thus allowing $router['module'] to work. Try it and see to be certain ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.