я не умею читать код на Cа ты хоть пробовал?
Потому что я не вижу, чем в этом случае мне поможет фабрика, билдер и/или di.
возвращать не просто DOMElement, а любого его кастомного наследника по желанию пользователя библиотеки?это обычная реализация шаблона factory method/фабричный метод
TagFactory::createTag()
:class TagFactory
{
protected $tagClasses = [];
protected $document;
public function __construct(Document $document)
{
$this->document = $document;
}
public function setTagClass(string $tag, string $class): self
{
if (!is_subclass_of($class, TagInterface::class)) {
throw new InvalidArgumentException("Class $class not instance TagInterface");
}
$this->tagClasses[$tag] = $class;
return $this;
}
public function createTag(string $name, iterable $attributes = [], string $content = null): TagInterface
{
if (isset($this->tagClasses[$name])) {
$tag = new $this->tagClasses[$name]($this->document, $attributes);
} else {
$tag = new Tag($this->document, $name, $attributes);
}
if ($content !== null) {
$tag->setContent($content);
}
return $tag;
}
}
su ffmpeg ...