I'm looking for a class pattern that helps me to obtain a global instance of Smarty and use the same during all application life. I tried to use a singleton o factory singleton pattern like this:
final class Personal_Smarty
{
static private $instance;
private function __construct() {}
static public function instance()
{
if( !isset( self::$_instance ) )
{
$smarty = new Smarty();
self::$instance = $smarty;
};
return self::$instance;
}
}
but I think it's not what I need because I need to create a Smarty instance only for once during all application life (so I don't want to be forced to create a Smarty instance for every request).
Is there a good way to do that? I'm not sure it's a good practice to do so and whether I will have problems with that. What do you think? The reason for my question is that I think that creating the smarty instance for every php script I use could be onerous (overhead), but maybe it's only my thought.