2021-03-23 21:58:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PDF;
|
|
|
|
|
|
|
|
use Cocur\Slugify\Slugify;
|
|
|
|
|
|
|
|
class Metadata
|
|
|
|
{
|
|
|
|
public ?string $abbreviation = null;
|
|
|
|
public ?string $author = null;
|
|
|
|
public ?string $creationdate = null;
|
|
|
|
public ?string $creator = null;
|
|
|
|
public ?string $encrypted = null;
|
|
|
|
public ?string $form = null;
|
|
|
|
public ?string $javascript = null;
|
|
|
|
public ?string $keywords = null;
|
|
|
|
public ?string $linearized = null;
|
|
|
|
public ?string $moddate = null;
|
|
|
|
public ?string $optimized = null;
|
|
|
|
public ?string $page_rot = null;
|
|
|
|
public ?string $page_size = null;
|
|
|
|
public ?string $pages = null;
|
|
|
|
public ?string $pdf_subtype = null;
|
|
|
|
public ?string $pdf_version = null;
|
|
|
|
public ?string $producer = null;
|
|
|
|
public ?string $standard = null;
|
|
|
|
public ?string $subject = null;
|
|
|
|
public ?string $subtitle = null;
|
|
|
|
public ?string $suspects = null;
|
|
|
|
public ?string $tagged = null;
|
|
|
|
public ?string $title = null;
|
|
|
|
public ?string $userproperties = null;
|
|
|
|
|
2021-04-08 15:36:57 +02:00
|
|
|
private function __construct(array $array)
|
2021-03-23 21:58:40 +01:00
|
|
|
{
|
|
|
|
$slugify = new Slugify(['separator' => '_']);
|
2021-04-08 15:36:57 +02:00
|
|
|
$notEmpty = static fn(string $v) => trim($v) !== '';
|
2021-03-23 21:58:40 +01:00
|
|
|
|
2021-04-08 15:36:57 +02:00
|
|
|
$array = array_filter($array, $notEmpty);
|
2021-03-23 21:58:40 +01:00
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
$key = $slugify->slugify($key);
|
|
|
|
if (property_exists(__CLASS__, $key)) {
|
|
|
|
$this->{$key} = trim($value);
|
|
|
|
}
|
|
|
|
}
|
2021-04-08 15:36:57 +02:00
|
|
|
}
|
2021-03-23 21:58:40 +01:00
|
|
|
|
2021-04-08 15:36:57 +02:00
|
|
|
public static function fill(array $data): Metadata
|
|
|
|
{
|
|
|
|
return new self($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function empty(): Metadata
|
|
|
|
{
|
|
|
|
return new self([]);
|
2021-03-23 21:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return get_object_vars($this);
|
|
|
|
}
|
|
|
|
}
|