Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.
Popular code excerpts may be moved to "Code Snippets" by the moderators.
Well ... the main omissions are the CodeBlocks class and the RegistryException class. I think better error messages would be nice. And I think I would call ifNameExists() and ifObjectExists() something simpler like has() and hasInstance().
public function ifNameExists($name) {
return array_key_exists($name, $this->objects);
}
/*
* @function
* "ifObjectExists"
*
* @param $object (object) #Object you wish to check for
* @return boolean #T/F based on search
*/
public function ifObjectExists($object) {
return in_array($object, $this->objects);
}
I'm not trying to seem mean or anything; however, why would one want to use a Registry class? I have always wondered this, if you can give me a good reason, I might implement on into my current project.
Note: I asked the same thing about a Session Handler but as you'll soon find out, I ended up making my own I use over the PHP Session handler. (To be posted in Coding Critique - Not Finished)
The Registry provides a means of loose coupling objects. Tight, or Hard coupling is bad between objects that are not going to be coupled in every possible circumstance, so instead we use a registry to provide us with a respository of, usually, singleton objects that can be used through the application.
Using a registry among other things means that you don't need to pass one object from object A to object B, then from object B to object C etc. You just keep a reference to it in the registry.
You can often use a registry to "register" an object for re-use rather than usiing a singleton too. Registries are extremely useful, and they come in many variants.