0

I am trying to use a library of classes within Laravel 8. I am having difficulty getting the classes to load correctly. I created a new folder within the App folder called DigiSigner, which is the external library's namespace.

App\DigiSigner
  DigiSignerClient.php
  \libs
    BaseRequest.php
    Branding.php
    ClassLoader.php
    Config.php
    Curler.php
    DigiSignerException.php
    DigiSignerResponse.php
    Document.php
    DocumentField.php
    DocumentFields.php
    ExistingField.php
    ExportObject.php
    Field.php
    SignatureRequest.php
    Signer.php

I created a controller that looks like this

class SignPDFController extends Controller
{
    public function getPDF()
    {
        $client = new DigiSignerClient('client_key');
        $request = new SignatureRequest;
        $request->setEmbedded(true);
        $request->setSendEmails(false);

        $template = Document::withID('document_id');
        $template->setTitle('Site Title');
        $request->addDocument($template);

        $signer = new Signer('[email protected]');
        $signer->setRole('Signer 1');
        $template->addSigner($signer);

        $initials = new ExistingField('key');
        $initials->setContent('VS');
        $signer->addExistingField($initials);

        $response = $client->sendSignatureRequest($request);

        foreach ($response->getDocuments() as $document) {
            foreach ($document->getSigners() as $signer) {
                $signDocumentUrl = $signer->getSignDocumentUrl();
            }
        }
    }
}

The DigiSignerClient and the SignatureRequest classes seem to load fine, but the SignatureRequest needs to load the ExportObject class to extend it.

namespace App\DigiSigner;

use App\DigiSigner\libs\ExportObject;

class SignatureRequest extends ExportObject {

I end up with an error like the following.

Error Class 'App\DigiSigner\libs\ExportObject' not found

Namespaces and use are a little fuzzy for me. If someone can point me in the right direction, I would be delighted.

3
  • what namespace is declared in the ExportObject file? Commented Dec 15, 2020 at 21:44
  • If namespaces are created properly, there should be no need for a use statement as those two classes should be in the same namespace. Commented Dec 15, 2020 at 21:45
  • The ExportOjbect has namespace App\DigiSigner; Commented Dec 15, 2020 at 22:04

2 Answers 2

1

I believe I figured it out. All the files in the subdirectory needed the namespace changed to App\DigiSigner\libs.

Sign up to request clarification or add additional context in comments.

1 Comment

Good you've found the answer yourself. If namespaces are a bit fuzzy, as it was for me once, you could read this php documentation php.net/manual/en/language.namespaces.php
0

Check ExportObject.php namespace.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.