Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
php-version: '8.4'
coverage: none
- run: composer update --prefer-dist --no-interaction --no-progress
- run: vendor/bin/pint --test
- run: vendor/bin/laranail-pint --test

rector:
name: Rector
Expand Down
4 changes: 2 additions & 2 deletions config/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
],

'dompdf' => [
'paper' => env('LARANAIL_PDF_DOMPDF_PAPER', 'a4'),
'paper' => env('LARANAIL_PDF_DOMPDF_PAPER', 'a4'),
'orientation' => env('LARANAIL_PDF_DOMPDF_ORIENTATION', 'portrait'),

/*
Expand All @@ -61,7 +61,7 @@
*/
'options' => [
'isRemoteEnabled' => env('LARANAIL_PDF_DOMPDF_REMOTE', false),
'defaultFont' => 'DejaVu Sans',
'defaultFont' => 'DejaVu Sans',
],
],

Expand Down
6 changes: 3 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
__DIR__ . '/src',
__DIR__ . '/tests',
])
// Pinned to the php84 set, matching the ^8.4.1 floor this package inherits from
// laranail/console. The pin is the point rather than the level: it stops anything
Expand All @@ -21,6 +21,6 @@
typeDeclarations: true,
)
->withSkip([
__DIR__.'/tests/Fixtures',
__DIR__ . '/tests/Fixtures',
])
->withImportNames(removeUnusedImports: true);
32 changes: 16 additions & 16 deletions src/Commands/DoctorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Simtabi\Laranail\Pdf\Commands;

use Simtabi\Laranail\Console\Tools\Commands\Command;
use Simtabi\Laranail\Console\Tools\Commands\Concerns\SupportsNamespacedNames;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Throwable;
use Simtabi\Laranail\Pdf\DriverRegistry;
use Simtabi\Laranail\Pdf\Exceptions\PdfException;
use Simtabi\Laranail\Pdf\Support\DriverReport;
use Simtabi\Laranail\Pdf\Support\PdfConfig;
use Simtabi\Laranail\Pdf\Support\UrlGuard;
use Throwable;
use Simtabi\Laranail\Pdf\Support\PdfConfig;
use Simtabi\Laranail\Pdf\Support\DriverReport;
use Simtabi\Laranail\Pdf\Exceptions\PdfException;
use Simtabi\Laranail\Console\Tools\Commands\Command;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Console\Tools\Commands\Concerns\SupportsNamespacedNames;

/**
* Answers what is actually wrong, not what the config file looks like.
Expand Down Expand Up @@ -52,7 +52,7 @@ public function handle(DriverRegistry $registry, UrlGuard $guard, PdfConfig $con
}

if ($reports === []) {
$this->error('No matching driver. Registered: '.implode(', ', $registry->names()).'.');
$this->error('No matching driver. Registered: ' . implode(', ', $registry->names()) . '.');

return self::FAILURE;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ private function probe(RendersHtml $driver, DriverReport $report): DriverReport
private function inspectSecurity(UrlGuard $guard, PdfConfig $config): array
{
return [
'allowed_hosts' => $config->strings('security.allowed_hosts'),
'allowed_hosts' => $config->strings('security.allowed_hosts'),
'block_private_addresses' => $config->bool('security.block_private_addresses', true),
// Not a config read but an actual question put to the guard, so a
// rule that stops covering this stops claiming to.
Expand All @@ -133,15 +133,15 @@ private function inspectSecurity(UrlGuard $guard, PdfConfig $config): array
}

/**
* @param list<DriverReport> $reports
* @param array<string, mixed> $security
* @param list<DriverReport> $reports
* @param array<string, mixed> $security
*/
private function render(string $default, array $reports, array $security): void
{
$this->table(
['Driver', 'Available', 'Capabilities', 'Probe', 'Why not'],
array_map(static fn (DriverReport $r): array => [
$r->name.($r->name === $default ? ' (default)' : ''),
$r->name . ($r->name === $default ? ' (default)' : ''),
$r->available ? 'yes' : 'no',
$r->describeCapabilities(),
$r->describeProbe(),
Expand All @@ -155,20 +155,20 @@ private function render(string $default, array $reports, array $security): void
/** @var list<string> $hosts */
$hosts = $security['allowed_hosts'];

$this->line(' allowed hosts: '.($hosts === [] ? 'any' : implode(', ', $hosts)));
$this->line(' private blocked: '.($security['block_private_addresses'] === true ? 'yes' : 'NO'));
$this->line(' allowed hosts: ' . ($hosts === [] ? 'any' : implode(', ', $hosts)));
$this->line(' private blocked: ' . ($security['block_private_addresses'] === true ? 'yes' : 'NO'));

if ($security['metadata_endpoint_refused'] !== true) {
$this->warn(
' The cloud metadata endpoint (169.254.169.254) is reachable by the URL renderer. '
.'If any caller can influence the URL, that is credential disclosure.',
. 'If any caller can influence the URL, that is credential disclosure.',
);
}

if ($hosts === []) {
$this->line(
' <comment>Note:</comment> the private-address check is lexical, so a hostname resolving to an '
.'internal address still passes it. Fill in allowed_hosts if callers can influence the URL.',
. 'internal address still passes it. Fill in allowed_hosts if callers can influence the URL.',
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Simtabi\Laranail\Pdf\Commands;

use Simtabi\Laranail\Pdf\DriverRegistry;
use Simtabi\Laranail\Console\Tools\Commands\Command;
use Simtabi\Laranail\Console\Tools\Commands\Concerns\SupportsNamespacedNames;
use Simtabi\Laranail\Pdf\DriverRegistry;

/**
* Publishes the config and says what is still needed.
Expand All @@ -29,7 +29,7 @@ final class InstallCommand extends Command
public function handle(DriverRegistry $registry): int
{
$this->callSilently('vendor:publish', array_filter([
'--tag' => 'pdf-config',
'--tag' => 'pdf-config',
'--force' => (bool) $this->option('force'),
]));

Expand All @@ -46,7 +46,7 @@ public function handle(DriverRegistry $registry): int
}

$missing[] = $name;
$this->line(" <comment>✗</comment> {$name} — ".$driver->unavailableReason());
$this->line(" <comment>✗</comment> {$name} — " . $driver->unavailableReason());
}

if ($missing === []) {
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/RenderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Simtabi\Laranail\Pdf\Commands;

use Simtabi\Laranail\Console\Tools\Commands\Command;
use Simtabi\Laranail\Console\Tools\Commands\Concerns\SupportsNamespacedNames;
use Simtabi\Laranail\Pdf\Exceptions\PdfException;
use Simtabi\Laranail\Pdf\PdfManager;
use Simtabi\Laranail\Pdf\Exceptions\PdfException;
use Simtabi\Laranail\Pdf\ValueObjects\PdfDocument;
use Simtabi\Laranail\Console\Tools\Commands\Command;
use Simtabi\Laranail\Pdf\ValueObjects\RenderOptions;
use Simtabi\Laranail\Console\Tools\Commands\Concerns\SupportsNamespacedNames;

/**
* Render one thing to one file, from the shell.
Expand Down Expand Up @@ -110,6 +110,6 @@ private function describeSize(string $path): string

$bytes = filesize($path);

return $bytes === false ? 'unknown size' : number_format($bytes / 1024, 1).' KB';
return $bytes === false ? 'unknown size' : number_format($bytes / 1024, 1) . ' KB';
}
}
2 changes: 1 addition & 1 deletion src/Contracts/Capabilities/MergesPdfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
interface MergesPdfs extends PdfDriver
{
/**
* @param list<string> $paths
* @param list<string> $paths
*/
public function merge(array $paths, ?RenderOptions $options = null): PdfDocument;
}
12 changes: 6 additions & 6 deletions src/DriverRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Simtabi\Laranail\Pdf;

use Closure;
use Simtabi\Laranail\Pdf\Enums\Capability;
use Illuminate\Contracts\Container\Container;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\ConvertsDocuments;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\MergesPdfs;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersUrl;
use Simtabi\Laranail\Pdf\Contracts\PdfDriver;
use Simtabi\Laranail\Pdf\Enums\Capability;
use Simtabi\Laranail\Pdf\Exceptions\DriverNotFound;
use Simtabi\Laranail\Pdf\Exceptions\UnsupportedCapability;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\MergesPdfs;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersUrl;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\ConvertsDocuments;

/**
* Resolves a driver by name, and refuses to hand back one that cannot do the
Expand Down Expand Up @@ -51,7 +51,7 @@ public function __construct(
/**
* Register a driver factory under a name.
*
* @param Closure(Container): PdfDriver $factory
* @param Closure(Container): PdfDriver $factory
*/
public function extend(string $name, Closure $factory): self
{
Expand Down
8 changes: 4 additions & 4 deletions src/Drivers/DompdfDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Simtabi\Laranail\Pdf\Drivers;

use Throwable;
use Dompdf\Dompdf;
use Dompdf\Options;
use RuntimeException;
use GuzzleHttp\Psr7\Utils;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Exceptions\RenderFailed;
use Simtabi\Laranail\Pdf\ValueObjects\PdfDocument;
use Simtabi\Laranail\Pdf\ValueObjects\RenderOptions;
use Throwable;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;

/**
* Dompdf — HTML only, in-process, no external service.
Expand Down Expand Up @@ -58,7 +58,7 @@ final class DompdfDriver extends Driver implements RendersHtml
];

/**
* @param array<string, mixed> $options passed to Dompdf\Options
* @param array<string, mixed> $options passed to Dompdf\Options
*/
public function __construct(
private readonly array $options = [],
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Simtabi\Laranail\Pdf\Drivers;

use Simtabi\Laranail\Pdf\Contracts\PdfDriver;
use Simtabi\Laranail\Pdf\Enums\Capability;
use Simtabi\Laranail\Pdf\Contracts\PdfDriver;
use Simtabi\Laranail\Pdf\Exceptions\DriverUnavailable;

/**
Expand Down
26 changes: 13 additions & 13 deletions src/Drivers/GotenbergDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
namespace Simtabi\Laranail\Pdf\Drivers;

use Closure;
use Throwable;
use Gotenberg\Stream;
use Gotenberg\Gotenberg;
use Gotenberg\Modules\ChromiumPdf;
use Gotenberg\Stream;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamInterface;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\ConvertsDocuments;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\MergesPdfs;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersUrl;
use Simtabi\Laranail\Pdf\Exceptions\InvalidSource;
use Simtabi\Laranail\Pdf\Exceptions\RenderFailed;
use Psr\Http\Message\RequestInterface;
use Simtabi\Laranail\Pdf\Support\UrlGuard;
use Simtabi\Laranail\Pdf\Exceptions\RenderFailed;
use Simtabi\Laranail\Pdf\Exceptions\InvalidSource;
use Simtabi\Laranail\Pdf\ValueObjects\PdfDocument;
use Simtabi\Laranail\Pdf\ValueObjects\RenderOptions;
use Throwable;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\MergesPdfs;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersUrl;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\ConvertsDocuments;

/**
* Gotenberg — the driver that can do everything.
Expand Down Expand Up @@ -126,7 +126,7 @@ function () use ($path, $options): RequestInterface {
['path' => $path],
),
$options,
basename($path, '.'.pathinfo($path, PATHINFO_EXTENSION)).'.pdf',
basename($path, '.' . pathinfo($path, PATHINFO_EXTENSION)) . '.pdf',
);
}

Expand Down Expand Up @@ -169,8 +169,8 @@ function () use ($paths, $options): RequestInterface {
/**
* Build the request, send it, and return the response body.
*
* @param Closure():RequestInterface $build
* @param array<string, mixed> $context
* @param Closure():RequestInterface $build
* @param array<string, mixed> $context
*/
private function send(Closure $build, string $operation, array $context = []): StreamInterface
{
Expand Down Expand Up @@ -240,7 +240,7 @@ private function applyPaperSize(ChromiumPdf $builder, RenderOptions $options): C
}

/**
* @param Closure():StreamInterface $resolver
* @param Closure():StreamInterface $resolver
*/
private function document(Closure $resolver, RenderOptions $options, ?string $fallback = null): PdfDocument
{
Expand Down
14 changes: 7 additions & 7 deletions src/Drivers/PaperSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ final class PaperSize
{
/** @var array<string, array{float, float}> */
private const array SIZES = [
'a3' => [11.7, 16.5],
'a4' => [8.27, 11.7],
'a5' => [5.83, 8.27],
'a6' => [4.13, 5.83],
'letter' => [8.5, 11.0],
'legal' => [8.5, 14.0],
'a3' => [11.7, 16.5],
'a4' => [8.27, 11.7],
'a5' => [5.83, 8.27],
'a6' => [4.13, 5.83],
'letter' => [8.5, 11.0],
'legal' => [8.5, 14.0],
'tabloid' => [11.0, 17.0],
'ledger' => [17.0, 11.0],
'ledger' => [17.0, 11.0],
];

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Enums/Capability.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Simtabi\Laranail\Pdf\Enums;

use Simtabi\Laranail\Pdf\Contracts\Capabilities\ConvertsDocuments;
use Simtabi\Laranail\Pdf\Contracts\PdfDriver;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\MergesPdfs;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersUrl;
use Simtabi\Laranail\Pdf\Contracts\PdfDriver;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\RendersHtml;
use Simtabi\Laranail\Pdf\Contracts\Capabilities\ConvertsDocuments;

/**
* The four things a PDF driver might be able to do.
Expand Down Expand Up @@ -43,10 +43,10 @@ public static function of(PdfDriver $driver): array
public function contract(): string
{
return match ($this) {
self::Html => RendersHtml::class,
self::Url => RendersUrl::class,
self::Html => RendersHtml::class,
self::Url => RendersUrl::class,
self::Office => ConvertsDocuments::class,
self::Merge => MergesPdfs::class,
self::Merge => MergesPdfs::class,
};
}

Expand All @@ -58,10 +58,10 @@ public function isImplementedBy(PdfDriver $driver): bool
public function label(): string
{
return match ($this) {
self::Html => 'HTML to PDF',
self::Url => 'URL to PDF',
self::Html => 'HTML to PDF',
self::Url => 'URL to PDF',
self::Office => 'Office document to PDF',
self::Merge => 'Merge PDFs',
self::Merge => 'Merge PDFs',
};
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/DriverNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class DriverNotFound extends PdfException
{
/**
* @param list<string> $registered
* @param list<string> $registered
*/
public static function named(string $name, array $registered): self
{
Expand Down
Loading