Skip to content

Allow invoices and notices to be loaded by contents, not only via-files #10

@MwSpaceLLC

Description

@MwSpaceLLC

Ciao Ale scusa il disturbo.
Abbiamo aggiornato l'applicazione per lavorare esclusivamente con un Filesystem Bucket,
Ci siamo accorti che possiamo passare solamente il contenuto del file e NON la dir.

Esempio funsione load() in FileSdIBase per invio fatture:

       /**
         * Load Signed Invoice from Bucket
         */
        $fileSdI->load(Storage::get($signdir));
        $response = new RispostaSdIRiceviFile($client->RiceviFile($fileSdI));

la funzione GET ci ritorna il contenuto di un file nel Bucket 'PRIVATE': non accessibile.

Ma nella funzione load() file_get_contents ovviamente non può essere instanziato.

    public function load( $invoice )
    {
        if ($invoice instanceOf \Taocomp\Einvoicing\AbstractDocument) {
            $this->NomeFile = $invoice->getFilename();
            $this->File = $invoice->asXML();
        } else if (true === is_readable($invoice)) {
            $this->NomeFile = basename($invoice);
            $this->File = file_get_contents($invoice);
            $this->removeBOM();
        } else {
            throw new \Exception("Invalid file or object '$invoice'");
        }

        return $this;
    }

Anche noi abbiamo dovuto modificare delle librerie perchè non possono più accedere ai file direttamente.

ora, Come facciamo ? Io posso anche modificare la classe, ma le modifiche le perderei all'aggiornamento.

Potresti aggiungere per esempio loadContents() ???
Io l'ho dovuta aggiungere manualmente in DUE FILE:

  • FileSdI.php

    /**
     * @param $filename
     * @param $filecontents
     * @return $this|FileSdIBase
     * @throws \Exception
     */
    public function loadContents($filename, $filecontents)
    {
        parent::loadContents($filename, $filecontents);

        $xml = simplexml_load_string($filecontents);

        if (!$xml->IdentificativoSdI) {
            throw new \Exception("Cannot find 'IdentificativoSdI' File Contents");
        }

        $this->IdentificativoSdI = $xml->IdentificativoSdI;

        return $this;

    }
  • FileSdIBase.php

    /**
     * @param $filename
     * @param $filecontents
     * @return $this
     * @throws \Exception
     */
    public function loadContents($filename, $filecontents)
    {
        $this->NomeFile = $filename;
        $this->File = $filecontents;
        $this->removeBOM();

        return $this;
    }

Ovviamente se l'aggiungi, magari su tutte le funzioni che richiedono una dir file di avere anche la possibilità di passare direttamente anche il contenuto. 😘😘

Aspetto tue, Salutissimi!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions