<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Web\Classes\Pdf\Convert;

class ConvertToPDFCompositor implements IConvertToPDF
{
  
  private $converters;

  
  public function __construct(IConvertToPDF ...$converters)
  {
    $this->converters = $converters;
  }

  public function isMimeTypeSupported(string $mimetype): bool
  {
    foreach ($this->converters as $converter) {
      if ($converter->isMimeTypeSupported($mimetype)) {
        return true;
      }
    }

    return false;
  }

  public function convert(string $contents, string $mimetype): ?string
  {
    foreach ($this->converters as $converter) {
      if ($this->isMimeTypeSupported($mimetype)) {
        $result = $converter->convert($contents, $mimetype);
        if (!is_null($result)) {
          return $result;
        }
      }
    }

    return null;
  }
}