简体   繁体   English

手动将软件包附加到Laravel(由于防火墙而无法使用作曲家)

[英]Manually attach package to Laravel (unable to use composer due to firewall)

I can't use composer to handle my dependencies due to the corporate firewall. 由于公司防火墙,我无法使用作曲家来处理我的依赖项。 At the moment I'm trying to use Barry vd Heuvel's DomPDF wrapper for Laravel and tried to: 目前,我正在尝试将Barry vd Heuvel的DomPDF包装器用于Laravel,并尝试:

  1. Download the zipfile from Github (master) 从Github下载zip文件(主版)
  2. Updated composer.json (not sure if its needed, but did it anyway) and added "barryvdh/laravel-dompdf": "*" in the require container. 更新了composer.json (不确定是否需要它,但还是这样做了),并在require容器中添加了"barryvdh/laravel-dompdf": "*"
  3. Create the folder structure: vendor/barryvdh/laravel-dompdf 创建文件夹结构: vendor/barryvdh/laravel-dompdf
  4. Place all files from the package in there ( config -folder, src -folder and the files .gitignore , composer.json and readme.md ) 将包中的所有文件放在那里( config -folder, src -folder和文件.gitignorecomposer.jsonreadme.md
  5. Add the service provider and facade in my app.php . 在我的app.php添加服务提供者和外观。 Service provider is listed as Barryvdh\\DomPDF\\ServiceProvider::class and the facade is aliased like 'PDF' => Barryvdh\\DomPDF\\Facade::class 服务提供商列为Barryvdh\\DomPDF\\ServiceProvider::class ,而外观的别名类似于'PDF' => Barryvdh\\DomPDF\\Facade::class
  6. Ran composer dump-autoload composer dump-autoload

After refreshing the browser I'm getting Class 'Barryvdh\\DomPDF\\ServiceProvider' not found . 刷新浏览器后,我Class 'Barryvdh\\DomPDF\\ServiceProvider' not found I also tried to run php artisan cache:clear and php artisan dump-autoload but the last one fails over the fact it can't find Barryvdh\\DomPDF\\ServiceProvider . 我还尝试运行php artisan cache:clearphp artisan dump-autoload但是最后一个失败了,因为它找不到Barryvdh\\DomPDF\\ServiceProvider

What have I forgotten to do to make it work? 我忘了做什么才能使它正常工作?

Update I've tried the suggested answer from Wouter J and the composer.json now looks like: 更新我已经尝试了Wouter J的建议答案,并且composer.json现在看起来像:

..
"autoload": {
    "classmap": [
      "database"
    ],
    "psr-4": {
      "App\\": "app/",
      "Barryvdh\\DomPDF\\": "vendor/barryvdh/laravel-dompdf/src"
    },
..

I've verified if the composer dump-autoload had any effect but I think it had. 我已经验证了作曲家dump-autoload是否有任何作用,但我认为它有作用。 Because the entry is now also listed in vendor/composer/autoload_psr4.php like: 因为该条目现在也已在vendor/composer/autoload_psr4.php列出,例如:

return array(
 // more entries
 'Barryvdh\\DomPDF\\' => array($vendorDir . '/barryvdh/laravel-dompdf/src'),
 'App\\' => array($baseDir . '/app'),
);

I believe at this point this is working, but the Facade isn't responding. 我相信目前这是可行的,但是Facade没有响应。 When I try to call something like PDF::loadView(...) and I let PhpStorm import the class ( vendor/barryvdh/laravel-dompdf/src/PDF.php ) it throws an error I can't call the method loadView statically. 当我尝试调用类似PDF::loadView(...) ,我让PhpStorm导入了类( vendor/barryvdh/laravel-dompdf/src/PDF.php ),它引发了错误,我无法调用loadView方法静态。 According to the documentation I should be able to call it like this: 根据文档,我应该可以这样称呼它:

$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');

But that results in Non-static method Barryvdh\\DomPDF\\PDF::loadView() should not be called statically, assuming $this from incompatible context on my end. 但这会导致Non-static method Barryvdh\\DomPDF\\PDF::loadView() should not be called statically, assuming $this from incompatible contextNon-static method Barryvdh\\DomPDF\\PDF::loadView() should not be called statically, assuming $this from incompatible context

Suggestions? 建议?

Composer autoload still doesn't know anything about how to download the package. Composer自动加载仍然对如何下载软件包一无所知。 You have to configure autoloading like this: 您必须像这样配置自动加载:

{
    "autoload": {
        "psr-4": { "Namespace\\Of\\The\\Package\\": "vendor/the/package" }
    }
}

I know this question is old, but since I don't see any solution, here is mine: I had exactly the same problem. 我知道这个问题很旧,但是由于我没有找到任何解决方案,因此这是我的问题:我遇到了完全相同的问题。 Was able to solve by running composer dumpautoload on my localhost and then copied the folder 'vendor/composer' to the shared hosting without an SSH access. 可以通过在本地主机上运行composer dumpautoload来解决,然后将文件夹“ vendor / composer”复制到共享主机中,而无需使用SSH访问。 Hope this will help someone in similar situation. 希望这对处于类似情况的人有所帮助。

The problem addresses that application don't know about DomPDF\\ServiceProvidor or anything related to DomPDF because barryvdh/laravel-dompdf itself depends dpmpdf/dompdf package which is still missing and does not comes with barryvdh/laravel-dompdf 该问题解决了应用程序不了解DomPDF\\ServiceProvidor或与DomPDF相关的任何barryvdh/laravel-dompdf因为barryvdh/laravel-dompdf本身依赖于dpmpdf/dompdf程序包,该程序包仍然缺少并且不附带barryvdh/laravel-dompdf

the package dompdf/dompdf also depends on several extension ie 软件包dompdf/dompdf也依赖于几个扩展名,即

PHP version 5.3.0 or higher
DOM extension
GD extension
MBString extension
php-font-lib
php-svg-lib

have a look at package here https://packagist.org/packages/dompdf/dompdf download this and put in your vendor directory then update your composer dumpautoload it should be working 在这里查看软件包https://packagist.org/packages/dompdf/dompdf下载此软件包并将其放在供应商目录中,然后更新您的composer dumpautoload它应该可以工作

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

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