Laravel-Blade
Laravel-Blade copied to clipboard
I would like to get a Singleton instance always.
I want to get a singleton instance, that is; I instantiate the Blade Class once (automatically) and then use a static function like Blade::instance() to get the object instantiated already. In this way, I won't have to worry about new Objects being made everytime.
F3 uses the following function to get the desired effect. Can I somehow manage to do the same here?
static function instance() {
if (!Registry::exists($class=get_called_class())) {
$ref=new Reflectionclass($class);
$args=func_get_args();
Registry::set($class,
$args?$ref->newinstanceargs($args):new $class);
}
return Registry::get($class);
}
Why don't you just use a container and inject it, if you don't want to "worry about new objects being made every time"?