lundi 21 mai 2018

Laravel: how to boot library instance once within controller/service?

I am using a custom library and I created a new Service and service provider where for it. In the boot section I am creating new instance with the library and I need that to persist within that page the user currently is, but when I use my global variable, it is not persistent and I have to create a new instance, which destory's the previous instance and I get library specific error (No digidoc in session) -> DigiDoc is created in the previous request for SOAP client.

Here is my created service

class EstDigiDocService
{
    protected $EstDigiDocService;

    /**
     * Start the service
     *
     * @return DigiDocService
     */
    public function boot()
    {
        //boot digidoc service
        return DigiDocService::instance();
    }

// A lot of more code

Now in my first function I am creating the instance like this

    /**
     * Generate BDOC
     *
     * @return
     */
    public function createBDOC($file)
    {

        $dds = $this->EstDigiDocService = $this->boot();
        // a lot of more code

Now after the BDOC has been created, user has to sign the document by clicking on a button in JS with ajax. In php I have to continue with the same Instance, otherwise it will say the error I mentioned before

Function for the signing

    /**
     * Mobile Sign
     *
     * @return Response
     */
    public function mobileSign()
    {

        $response = [];
        $dds = $this->EstDigiDocService;
        // a lot of more code

But $dds = $this->EstDigiDocService returns null. How can I initialize the instance once within the service ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2s0gD2v
via IFTTT

Aucun commentaire:

Enregistrer un commentaire