artisan/laravel-pdf

该软件包已被废弃,不再维护。作者建议使用 humans/laravel-pdf 软件包。

0.1.5 2020-01-22 07:33 UTC

This package is auto-updated.

Last update: 2020-02-07 23:16:02 UTC


README

Laravel PDF 是不同 PDF 软件包的工厂。以下是当前支持的驱动程序:

  • 日志
  • Laravel Snappy
  • Compose(即将发布)

安装和用法

composer require artisan/laravel-pdf

此功能使用软件包发现,但如果您已禁用软件包发现,请确保将提供者添加到您的 config/app.php 文件中。

'providers' => [
    Artisan\Pdf\PdfServiceProvider::class,
],

日志驱动程序

日志驱动程序将所有执行命令传递到日志文件中,并带有渲染文档所需的参数。

如果您不希望模拟此命令或您正在离线工作,这是一个相当好的替代方案。

Snappy 驱动程序

要使用 Snappy 驱动程序,需要 barryvdh/laravel-snappy 软件包。

composer require barryvdh/laravel-snappy

Compose 驱动程序

Compose 是构建 PDF 的 API,因此项目在设置时无需任何额外开销。

要使用 Compose 驱动程序,需要 symfony/http-client 软件包。

composer require symfony/http-client

扩展驱动程序

Pdf::extend('customdriver', function ($app) {
  return new CustomerDriver;
});

模拟

在您的测试中模拟此功能,您可以使用外观助手,或者在测试中使用 mockery。

外观

use Artisan\Pdf\Pdf;

Pdf::shouldReceive('html->stream')->once()->andReturn('Some content for the PDF.');

Mockery

use Artisan\Pdf\Manager as PdfManager;
use Artisan\Pdf\Pdf;

$pdf = Mockery::mock(PdfManager::class);
$pdf->shouldReceive('html->stream')->once()->andReturn('Some content for the PDF.');

$this->instance(Pdf::class, $pdf);