The MailMimeParser uses PHP-DI for dependency injection, allowing you to override or provide specialized classes (like encryption or signing plugins). You can configure this at two levels:
Instance Level
When creating a new instance via the constructor, you can provide a specific LoggerInterface or a PHP-DI configuration (array, string, or DefinitionSource). This configuration only affects that specific instance.
$parser = new MailMimeParser(
$myLogger, // LoggerInterface
$myDiConfig, // array|string|DefinitionSource
true // $useGlobalDefinitions (default: true)
);
Global Level
To affect all instances of MailMimeParser created in your application, use the static methods:
addGlobalPhpDiContainerDefinition(...): Adds a new definition to the global container.setGlobalPhpDiConfigurations(array $phpDiConfigs, bool $useDefaultDefinitionsFile = true): Replaces all global definitions with the provided ones.setGlobalLogger(LoggerInterface $logger): Sets a logger to be used by all instances.setFallbackCharset(string $charset): Sets the global fallback charset for text parts that do not declare one.
// Instance-specific configuration
$parser = new MailMimeParser($logger, $diConfig);
// Global configuration
MailMimeParser::addGlobalPhpDiContainerDefinition($diConfig);
MailMimeParser::setGlobalLogger($logger);