The thing about a real Service Locator (as opposed to a class loader) is that a Service Locator can create fully instansiated classes -- meaning passing (and even creating) the parameters for the constructor.
You can certainly use that get() method above as/in the __autoload() function as well -- just as Todd_Z says -- so it can do double duty.
So here is the
programming project, because I like where this thing is going. You know, it is often better to start building from scratch to get clean solution). I am going to throw out some requirements and we will see if we can code a nice Service Locator.
- Be able to register a list of parameters to pass to the constructor (we may need eval() for that)
- Be able to specify that a parameter is another "registered" object that we get() an instance of to pass as a parameter (think of a Model object that need a DB connection object passed to its constructor)
- Allow get() to get objects as singletons or multiple instances
- Allow instances to be accessed by a name that is not the class name.
- Have the class name to file name mapping be configurable when you create the Service Locator (not everyone likes your naming style

)
- Keeping Lazy Loading so that if we never get() the class it is never instansiated (say an error redirect occurs before the get()).
- Make it so it is easy to use as __autoload() or spl_autoload().
- How does PHP5 make our job easier or the interface nicer?
- Do we want to add a settable list of paths that get() will search -- like Todd_Z does as an option?