Skip to content

Commit

Permalink
Merge pull request #504 from KnpLabs/v2-unstable-wkhtmltopdf-global-o…
Browse files Browse the repository at this point in the history
…ptions

V2 unstable wkhtmltopdf global options
  • Loading branch information
alexpozzi authored Oct 16, 2024
2 parents 9f7adcf + 92b64f1 commit ec52b62
Show file tree
Hide file tree
Showing 29 changed files with 405 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/CopiesOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

final class CopiesOption implements ExtraOption
{
/**
* @param positive-int $number
*/
public function __construct(private readonly int $number) {}

public function compile(): array
Expand Down
3 changes: 3 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/DpiOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

final class DpiOptions implements ExtraOption
{
/**
* @param positive-int $dpi
*/
public function __construct(private readonly int $dpi) {}

public function compile(): array
Expand Down
4 changes: 3 additions & 1 deletion src/Backend/WkHtmlToPdf/ExtraOption/GrayscaleOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class GrayscaleOption
use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class GrayscaleOption implements ExtraOption
{
public function __construct() {}

Expand Down
12 changes: 11 additions & 1 deletion src/Backend/WkHtmlToPdf/ExtraOption/ImageDpiOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class ImageDpiOption
use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class ImageDpiOption implements ExtraOption
{
/**
* @param positive-int $dpi
*/
public function __construct(public readonly int $dpi) {}

public function compile(): array
{
return ['--image-dpi', $this->dpi];
}
}
20 changes: 20 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/ImageQualityOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class ImageQualityOption implements ExtraOption
{
/**
* @param positive-int $quality
*/
public function __construct(public readonly int $quality) {}

public function compile(): array
{
return ['--image-quality', $this->quality];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/LowQualityOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class LowQualityOption implements ExtraOption
{
public function __construct() {}

public function compile(): array
{
return ['--lowquality'];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/MarginBottomOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class MarginBottomOption implements ExtraOption
{
public function __construct(public readonly string $margin) {}

public function compile(): array
{
return ['--margin-bottom', $this->margin];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/MarginLeftOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class MarginLeftOption implements ExtraOption
{
public function __construct(public readonly string $margin) {}

public function compile(): array
{
return ['--margin-left', $this->margin];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/MarginRightOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class MarginRightOption implements ExtraOption
{
public function __construct(public readonly string $margin) {}

public function compile(): array
{
return ['--margin-right', $this->margin];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/MarginTopOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class MarginTopOption implements ExtraOption
{
public function __construct(public readonly string $margin) {}

public function compile(): array
{
return ['--margin-top', $this->margin];
}
}
9 changes: 8 additions & 1 deletion src/Backend/WkHtmlToPdf/ExtraOption/NoCollateOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class NoCollateOption
use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class NoCollateOption implements ExtraOption
{
public function __construct() {}

public function compile(): array
{
return ['--no-collate'];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/NoPdfCompressionOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class NoPdfCompressionOption implements ExtraOption
{
public function __construct() {}

public function compile(): array
{
return ['--no-pdf-compression'];
}
}
10 changes: 0 additions & 10 deletions src/Backend/WkHtmlToPdf/ExtraOption/Orientation.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/Orientation/Value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption\Orientation;

enum Value: string
{
case PORTRAIT = 'Portrait';
case LANDSCAPE = 'Landscape';
}
28 changes: 28 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/OrientationOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
use KNPLabs\Snappy\Core\Backend\Options\PageOrientation;

final class OrientationOption implements ExtraOption
{
public function __construct(private readonly ExtraOption\Orientation\Value $orientation) {}

public static function fromPageOrientation(PageOrientation $pageOrientation): self
{
return new self(
match ($pageOrientation) {
PageOrientation::PORTRAIT => ExtraOption\Orientation\Value::PORTRAIT,
PageOrientation::LANDSCAPE => ExtraOption\Orientation\Value::LANDSCAPE,
}
);
}

public function compile(): array
{
return ['--orientation', $this->orientation->value];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/PageHeightOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class PageHeightOption implements ExtraOption
{
public function __construct(public readonly string $height) {}

public function compile(): array
{
return ['--page-height', $this->height];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/PageSizeOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class PageSizeOption implements ExtraOption
{
public function __construct(public readonly string $size) {}

public function compile(): array
{
return ['--page-size', $this->size];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/PageWidthOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class PageWidthOption implements ExtraOption
{
public function __construct(public readonly string $width) {}

public function compile(): array
{
return ['--page-width', $this->width];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/TitleOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class TitleOption implements ExtraOption
{
public function __construct(public readonly string $title) {}

public function compile(): array
{
return ['--title', $this->title];
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/ExtraOption/UseXserverOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;

final class UseXserverOption implements ExtraOption
{
public function __construct() {}

public function compile(): array
{
return ['--use-xserver'];
}
}
22 changes: 22 additions & 0 deletions src/Backend/WkHtmlToPdf/Options/GlobalOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\Options;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\OptionGroup;
use KNPLabs\Snappy\Backend\WkHtmlToPdf\Options\GlobalOptions\CollateOption;
use KNPLabs\Snappy\Backend\WkHtmlToPdf\Options\GlobalOptions\CookieJarOption;
use KNPLabs\Snappy\Backend\WkHtmlToPdf\Options\GlobalOptions\NoCollateOption;
use KNPLabs\Snappy\Core\Backend\Options\PageOrientation;

final class GlobalOptions extends OptionGroup
{
public function __construct(
public readonly ?CollateOption $collate,
public readonly ?NoCollateOption $noCollate,
public readonly ?CookieJarOption $cookieJar,
public readonly ?PageOrientation $pageOrientation,
) {
}
}
17 changes: 17 additions & 0 deletions src/Backend/WkHtmlToPdf/Options/GlobalOptions/CollateOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\Options\GlobalOptions;

use KNPLabs\Snappy\Backend\WkHtmlToPdf\Option;

final class CollateOption implements Option
{
public function __construct() {}

public function compile(): array
{
return ['--collate'];
}
}
15 changes: 15 additions & 0 deletions src/Backend/WkHtmlToPdf/Options/GlobalOptions/CookieJarOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\Options\GlobalOptions;

final class CookieJarOption
{
public function __construct(public readonly string $path) {}

public function compile(): array
{
return ['--no-collate'];
}
}
Loading

0 comments on commit ec52b62

Please sign in to comment.