itsgoingd / slim-facades

"Static" interface for various Slim features
74 stars 9 forks source link

Singleton #2

Closed fdisotto closed 10 years ago

fdisotto commented 10 years ago

Hi, how can I use singleton ($app->container->singleton) with facades?

itsgoingd commented 10 years ago

Hey, I've updated the readme with info about creating custom facades.

In your case, you wold register custom singleton via:

$app->container->singleton('my_singleton', function(){ return new MySingleton(); });

Then create a facade class for this component:

class MyFacade extends SlimFacades\Facade
{
    // return the name of the component from the DI container
    protected static function getFacadeAccessor() { return 'my_singleton'; }
}
fdisotto commented 10 years ago

Now I've understand how to use these facades :)