Skip to content

Commit

Permalink
wip v8
Browse files Browse the repository at this point in the history
  • Loading branch information
mikerockett committed Oct 15, 2023
1 parent b506144 commit 441170c
Show file tree
Hide file tree
Showing 26 changed files with 159 additions and 144 deletions.
15 changes: 12 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# WeasyPrint for Laravel – Release Notes
# WeasyPrint for Laravel — Changelog

## 8.0.0 (Breaking Release) `current`

This release drops support for WeasyPrint < v59. Going forward, compatibility of this package against a particular WeasyPrint version will be based solely on CLI flags available the *latest* version of WeasyPrint. If a CLI property is added or removed in a WeasyPrint release, then it will become unsupported in a new version of the package.

## Changes:
### Changes:

- The `optimizeSize` configuration option has been removed.
- WIP
- Default config is now class-based to introduce some type-safety.
- Config may now only be tapped or overridden.
-
- All tests have been moved to Pest 2. Coverage removed for the time being.

## 7.1.0 `maintenance`, `minor`
Expand All @@ -20,6 +22,11 @@ This release adds support for WeasyPrint 58, along with two new configuration pr

This release adds support for Laravel 10 and drops support for Laravel 8. The minimum-required version of PHP is now 8.1. As there have been no significant API changes to WeasyPrint, this package continues to support v53+.

<hr />

<details>
<summary>Unsupported Versions</summary>

## 6.1.0 `no support`, `minor`

This release adds support for Laravel 9, and works just fine with WeasyPrint v54.
Expand Down Expand Up @@ -152,3 +159,5 @@ Given that v5 is a paradigm release, the following changes are considered breaki
## 1.0.0 `no support`

- Initial Release

</details>
4 changes: 2 additions & 2 deletions config/weasyprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* The amount of seconds to allow a conversion to run for.
*/
timeout: (int) env('WEASYPRINT_TIMEOUT', 120),
timeout: (int) env('WEASYPRINT_TIMEOUT', '120'),

/**
* Force the input character encoding. utf-8 is recommended.
Expand All @@ -26,7 +26,7 @@
/**
* Enable or disable HTML Presentational Hints.
*/
presentationalHints: (bool) env('WEASYPRINT_PRESENTATIONAL_HINTS', true),
presentationalHints: env('WEASYPRINT_PRESENTATIONAL_HINTS', 'true'),

/**
* Optionally set the media type to use for CSS @media.
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class GeneratePDF
}
```

**Global Helpers**
**Global Helpers:**

```php
use WeasyPrint\Contracts\Factory;
Expand Down
6 changes: 4 additions & 2 deletions src/Contracts/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ interface Factory
{
public function getWeasyPrintVersion(): string;

public function tapConfig(callable $callback): self;
public function setConfig(Config $config): self;

public function prepareSource(Source|Renderable|string $source): self;
public function tapConfig(callable $callback): self;

public function getConfig(): Config;

public function prepareSource(Source|Renderable|string $source): self;

public function getSource(): Source;

public function addAttachment(string $pathToAttachment): Factory;
Expand Down
8 changes: 4 additions & 4 deletions src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Illuminate\Support\Facades\Facade as SupportFacade;
use WeasyPrint\Contracts\Factory;
use WeasyPrint\Objects\Config;

/**
* @method static Factory mergeConfig(mixed ...$config)
* @method static Factory prepareSource(Source|Renderable|string $source)
* @method static Config getConfig()
* @method static string getWeasyPrintVersion()
* @method static Factory setConfig(Objects\Config $config)
* @method static Factory tapConfig(callable $callback)
* @method static Factory prepareSource(Objects\Source|\Illuminate\Contracts\Support\Renderable|string $source)
*/
class Facade extends SupportFacade
{
Expand Down
5 changes: 2 additions & 3 deletions src/Objects/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
use Illuminate\Support\Facades\{Response, Storage};
use Symfony\Component\HttpFoundation\StreamedResponse;

class Output
final class Output
{
public function __construct(
protected string $data
) {
}
) {}

public function download(string $filename, array $headers = [], bool $inline = false): StreamedResponse
{
Expand Down
5 changes: 2 additions & 3 deletions src/Objects/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Illuminate\Contracts\Support\Renderable;
use WeasyPrint\Exceptions\TemporaryFileException;

class Source
final class Source
{
private array $attachments = [];

public function __construct(
protected Renderable|string $source
) {
}
) {}

public function get(): Renderable|string
{
Expand Down
10 changes: 10 additions & 0 deletions src/Pipeline/BuildStage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace WeasyPrint\Pipeline;

interface BuildStage
{
public function __invoke(BuildTraveler $container): BuildTraveler;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use WeasyPrint\Objects\Output;
use WeasyPrint\Service;

class BuilderContainer
class BuildTraveler
{
private string $inputPath;
private string $outputPath;
Expand All @@ -17,8 +17,7 @@ class BuilderContainer

public function __construct(
public Service $service
) {
}
) {}

public function makeTemporaryFilename(): string|false
{
Expand Down
10 changes: 0 additions & 10 deletions src/Pipeline/BuilderPipelineStage.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/Pipeline/BuilderPipes/EnsureSourceIsSet.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Pipeline/BuilderPipes/Execute.php

This file was deleted.

19 changes: 0 additions & 19 deletions src/Pipeline/BuilderPipes/PersistTemporaryInput.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Pipeline/BuilderPipes/SetOutputPath.php

This file was deleted.

19 changes: 0 additions & 19 deletions src/Pipeline/BuilderPipes/UnlinkTemporaryInput.php

This file was deleted.

20 changes: 20 additions & 0 deletions src/Pipeline/Stages/EnsureSourceIsSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace WeasyPrint\Pipeline\Stages;

use WeasyPrint\Exceptions\SourceNotSetException;
use WeasyPrint\Pipeline\{BuildStage, BuildTraveler};

class EnsureSourceIsSet implements BuildStage
{
public function __invoke(BuildTraveler $container): BuildTraveler
{
if (!$container->service->sourceIsSet()) {
throw new SourceNotSetException();
}

return $container;
}
}
17 changes: 17 additions & 0 deletions src/Pipeline/Stages/Execute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace WeasyPrint\Pipeline\Stages;

use WeasyPrint\Pipeline\{BuildStage, BuildTraveler};

class Execute implements BuildStage
{
public function __invoke(BuildTraveler $container): BuildTraveler
{
$container->getCommand()->execute();

return $container;
}
}
19 changes: 19 additions & 0 deletions src/Pipeline/Stages/PersistTemporaryInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace WeasyPrint\Pipeline\Stages;

use WeasyPrint\Pipeline\{BuildStage, BuildTraveler};

class PersistTemporaryInput implements BuildStage
{
public function __invoke(BuildTraveler $container): BuildTraveler
{
$container->service
->getSource()
->persistTemporaryFile($container->getInputPath());

return $container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace WeasyPrint\Pipeline\BuilderPipes;
namespace WeasyPrint\Pipeline\Stages;

use WeasyPrint\Commands\BuildCommand;
use WeasyPrint\Pipeline\{BuilderContainer, BuilderPipelineStage};
use WeasyPrint\Pipeline\{BuildStage, BuildTraveler};

class PrepareBuildCommand implements BuilderPipelineStage
class PrepareBuildCommand implements BuildStage
{
public function __invoke(BuilderContainer $container): BuilderContainer
public function __invoke(BuildTraveler $container): BuildTraveler
{
$service = $container->service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace WeasyPrint\Pipeline\BuilderPipes;
namespace WeasyPrint\Pipeline\Stages;

use WeasyPrint\Exceptions\{MissingOutputFileException, OutputReadFailedException};
use WeasyPrint\Objects\Output;
use WeasyPrint\Pipeline\{BuilderContainer, BuilderPipelineStage};
use WeasyPrint\Pipeline\{BuildStage, BuildTraveler};

class PrepareOutput implements BuilderPipelineStage
class PrepareOutput implements BuildStage
{
public function __invoke(BuilderContainer $container): BuilderContainer
public function __invoke(BuildTraveler $container): BuildTraveler
{
if (!is_file($outputPath = $container->getOutputPath())) {
throw new MissingOutputFileException($outputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace WeasyPrint\Pipeline\BuilderPipes;
namespace WeasyPrint\Pipeline\Stages;

use WeasyPrint\Pipeline\{BuilderContainer, BuilderPipelineStage};
use WeasyPrint\Pipeline\{BuildStage, BuildTraveler};

class SetInputPath implements BuilderPipelineStage
class SetInputPath implements BuildStage
{
public function __invoke(BuilderContainer $container): BuilderContainer
public function __invoke(BuildTraveler $container): BuildTraveler
{
$container->setInputPath(
match (($source = $container->service->getSource())->isUrl()) {
Expand Down
Loading

0 comments on commit 441170c

Please sign in to comment.