Hello,
I would like to ask several questions regarding programming in OOP PHP. Last time, I have written several classes (i.e. for cache and logging support), but I have not used namespaces. Now I would like to introduce them and I wonder if it makes any sense of creating as many namespaces as are available in other projects available on the net for free. Actually I am thinking about creating \Framework namespace, where all my classes could fit w/o worrying about name conflicts. However, someone might suggest to use some sub-namespaces, like \Framework\Cache or even \Framework\Cache\Driver\Apc. This leads to many namespaces, containing only few (or even just one) class inside. Do you see any reason for creating as many namespaces? What would you recommend?
Final question is more about design. As I have written, I have several classes that provides support for caching. One, main Cache class and some helpers. I have also written drivers for file-based cache, apc, etc. Actually there is Cache::loadDriver method, that takes care about loading proper driver. It is sufficient, to pass 'apc' string as parameter, and it will automatically load the proper driver, by simply creating an object:
$driver = 'apc';
$classname = '\Framework\Cache\' . strtoupper($driver);
$this->driver = new $classname();
My idea was to do it automatically, and not bother anyone about what to load. I think that even, when I choose to pass already instantiated object, code like above would be necessary but in other part of application. If I would like to let the user choose cache driver for application, and he would be able to click it somewhere via web panel, then still the application would need to match driver name with proper class name and namespace. But I might be wrong? What is your opinion?
I am looking forward to hear your opinions.