Parses a MIME message into an {@see IMessage} object.
The class sets up the dependency injection container (using PHP-DI) with the ability to override and/or provide specialized classes. To override you can:
- Provide an array|string|DefinitionSource to the constructor to affect classes used on a single instance of MailMimeParser
- Call MailMimeParser::addGlobalContainerDefinition with an array|string|DefinitionSource to to override it globally on all instances of MailMimeParser
- Call MailMimeParser::getGlobalContainer(), and use set() to override individual definitions globally.
You may also provide a LoggerInterface on the constructor for a single instance, or override it globally by calling setGlobalLogger. This is the same as setting up Psr\Log\LoggerInterface with your logger class in a Php-Di configuration in one of the above methods.
To invoke the parser, call parse
on a MailMimeParser object.
$parser = new MailMimeParser();
// the resource is attached due to the second parameter being true and will
// be closed when the returned IMessage is destroyed
$message = $parser->parse(fopen('path/to/file.txt'), true);
// use $message here
- author Zaahid Bateson
Constants |
public ZBateson
|
Methods |
public __construct(?Psr\Log\LoggerInterface $logger = NULL, DI\Definition\Source\DefinitionSource|array|string|?null $phpDiContainerConfig = NULL, bool $useGlobalDefinitions = true) Provide custom php-di configuration to customize dependency injection, or provide a custom logger for the instance only. Note: this only affects instances created through this instance of the MailMimeParser, or the container itself. Calling 'new MimePart()' directly for instance, would use the global service locator to setup any dependencies MimePart needs. This applies to a provided $logger too -- it would only affect instances of objects created through the provided MailMimeParser. Passing false to $useGlobalDefinitions will cause MMP to not use any global definitions. The default definitions file MailMimeParser::DEFAULT_DEFINITIONS_FILE will still be added though.
|
public static addGlobalPhpDiContainerDefinition(DI\Definition\Source\DefinitionSource|array|string $phpDiConfig) : void |
public static getGlobalContainer() : DI\Container Returns the global php-di container instance. |
public parse(?mixed $resource, bool $attached) : ZBateson Parses the passed stream handle or string into an {@see IMessage} object and returns it. If the passed $resource is a resource handle or StreamInterface, the resource must remain open while the returned IMessage object exists. Pass true as the second argument to have the resource attached to the IMessage and closed for you when it's destroyed, or pass false to manually close it if it should remain open after the IMessage object is destroyed.
|
public static resetGlobalPhpDiContainerDefinitions() : void |
public static setGlobalLogger(Psr\Log\LoggerInterface $logger) : void Registers the provided logger globally. |
public static setGlobalPhpDiConfigurations(array $phpDiConfigs, bool $useDefaultDefinitionsFile = true) : void Sets global configuration for php-di. Overrides all previously set definitions. You can optionally not use the default MMP definitions file by passing 'false' to the $useDefaultDefinitionsFile argument.
|
Properties |
protected DI\Container $container
|
protected ZBateson
|
Constants |
private ZBateson
|
Properties |
private static ?DI\Container $globalContainer = NULL
|
private static array $globalDefinitions = ['/homepages/18/d179646520/htdocs/PHPFUIWebsite/ZBateson/MailMimeParser/di_config.php']
|
Methods |
private static getGlobalContainerBuilder() : DI\ContainerBuilder Returns the default ContainerBuilder with default loaded definitions. |
Properties |
private static ?DI\Container $globalContainer = NULL
|
private static array $globalDefinitions = ['/homepages/18/d179646520/htdocs/PHPFUIWebsite/ZBateson/MailMimeParser/di_config.php']
|
Methods |
public static addGlobalPhpDiContainerDefinition(DI\Definition\Source\DefinitionSource|array|string $phpDiConfig) : void |
public static getGlobalContainer() : DI\Container Returns the global php-di container instance. |
private static getGlobalContainerBuilder() : DI\ContainerBuilder Returns the default ContainerBuilder with default loaded definitions. |
public static resetGlobalPhpDiContainerDefinitions() : void |
public static setGlobalLogger(Psr\Log\LoggerInterface $logger) : void Registers the provided logger globally. |
public static setGlobalPhpDiConfigurations(array $phpDiConfigs, bool $useDefaultDefinitionsFile = true) : void Sets global configuration for php-di. Overrides all previously set definitions. You can optionally not use the default MMP definitions file by passing 'false' to the $useDefaultDefinitionsFile argument.
|