简体   繁体   English

在 Laravel 8 中使用具有不同命名空间的类

[英]Using classes with different namespaces in Laravel 8

I am trying to use a library of classes within Laravel 8. I am having difficulty getting the classes to load correctly.我正在尝试使用 Laravel 8 中的类库。我很难让类正确加载。 I created a new folder within the App folder called DigiSigner, which is the external library's namespace.我在 App 文件夹中创建了一个名为 DigiSigner 的新文件夹,它是外部库的命名空间。

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我创建了一个看起来像这样的 controller

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('user@email.com');
        $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. DigiSignerClientSignatureRequest类似乎可以正常加载,但SignatureRequest需要加载ExportObject class 来扩展它。

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找不到错误 Class 'App\DigiSigner\libs\ExportObject'

Namespaces and use are a little fuzzy for me.命名空间和使用对我来说有点模糊。 If someone can point me in the right direction, I would be delighted.如果有人能指出我正确的方向,我会很高兴。

Check ExportObject.php namespace.检查 ExportObject.php 命名空间。

I believe I figured it out.我相信我想通了。 All the files in the subdirectory needed the namespace changed to App\DigiSigner\libs.子目录中的所有文件都需要将命名空间更改为 App\DigiSigner\libs。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM