Closed alganet closed 13 years ago
Great idea!
I've planned to use class_alias to make the lazy autodefining works, but it is impossible to use lsb with class_alias, since it's only a namespace-import-like feature.
Since I don't want to use eval() on Respect, I'm closing this issue and archiving this idea.
Config supports only INI-based configuration files for a lot of reasons: they're fast to parse (using the native php INI parser), easy to read and very simple in structure.
INIs simplicity allows Config to reach a very sophisticated -yet minimalistic- approach to lazy loading. Each object defined is represented by an instantiator that, when executed, loads and creates the real full object and its dependencies.
Take for instance this INI file:
If you ask for a Container for
$container->baz
, a chain reaction of lazy loading instantiators will eventually reach [foo].A similar pure PHP file could be:
This will instantiate every object independent of which is requested by the $container upon using, which is not optimal.
A very elegant solution would be porting this entire configuration to a lazy-loaded-aware namespace:
A possible implementation would be a single Respect\Config\Lazy\Container class. This class would register a autoloader that automatically applies an alias to everything that begins with Respect\Config\Lazy\ pointing to Respect\Config\Instantiator.
The code remais the same, except for the new namespace at the top that sort of transports the entire context to a lazy-loaded sandbox.
I'm up to implement this on the few weeks. Any thoughts on that?