jeudi 26 novembre 2015

Laravel 5 Service Container: instance lifecycle

So currently, I have this code:

    if($app->bound(HproseHolder::class)) {
        $app->forgetInstance(HproseHolder::class);
    }
    $app->instance(HproseHolder::class, new HproseHolder($ctx["optional"]));
    assert(
        \Hprose::get("wpHash") == $ctx["optional"]["wpHash"],
        "WebPack hash does not match!"
    );

Once my WebPack key changes, the assertion is triggered.

Basically, I have Laravel running as a server, so I do not have a per-request lifecycle. Everything works, from request to response - but, when I try to use a facade to access global data, I am hitting an issue.

As you can see in my code above, I am checking for the presence of am instance and am trying to forget the instance. But...this somehow does not work.

What is the right way to forget an instance within the Service Container?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire