Laravel IoC outside Laravel

I am using this repo as the basis for a new CLI PHP project using Eloquent as the ORM.
When you create the new Eloquent capsule you have the option to setAsGlobal which makes the DB capsule accessible from anywhere in the code.
Does that mean there's a Laravel Container being used? Or is this just affecting the DB object?
I'd been using pimple as a container, but if Laravel already has a container I can bind to via Eloquent, that would be a lot simpler-- I want to bind a log writer, the Eloquent capsule, and probably a settings object to the global container so I can access it from anywhere.
Answer:
No it does not use Laravels Container. If you look at the method in the trait: (github.com)
public function setAsGlobal()
{
    static::$instance = $this;
}
You can see that it just sets a static property on the class containing the current instance so it will be reused for subsequent calls.
Previous
Next Post »
0 Komentar