63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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;
 | 
						|
 | 
						|
    private function __construct(array $array)
 | 
						|
    {
 | 
						|
        $slugify = new Slugify(['separator' => '_']);
 | 
						|
        $notEmpty = static fn(string $v) => trim($v) !== '';
 | 
						|
 | 
						|
        $array = array_filter($array, $notEmpty);
 | 
						|
        foreach ($array as $key => $value) {
 | 
						|
            $key = $slugify->slugify($key);
 | 
						|
            if (property_exists(__CLASS__, $key)) {
 | 
						|
                $this->{$key} = trim($value);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public static function fill(array $data): Metadata
 | 
						|
    {
 | 
						|
        return new self($data);
 | 
						|
    }
 | 
						|
 | 
						|
    public static function empty(): Metadata
 | 
						|
    {
 | 
						|
        return new self([]);
 | 
						|
    }
 | 
						|
 | 
						|
    public function toArray(): array
 | 
						|
    {
 | 
						|
        return get_object_vars($this);
 | 
						|
    }
 | 
						|
}
 |