UUEncodedPartHeaderContainer
extends PartHeaderContainer
in package
Header container representing the start line of a uu-encoded part.
The line may contain a unix file mode and a filename.
Tags
Table of Contents
- $filename : string|null
- $headerFactory : HeaderFactory
- $logger : LoggerInterface
- $mode : int|null
- $errors : array<string|int, mixed>
- $headerMap : array<string|int, mixed>
- $headerObjects : array<string|int, IHeader>
- $headers : array<string|int, array<string|int, string>>
- $nextIndex : int
- $validated : bool
- __construct() : mixed
- add() : static
- Adds the header to the collection.
- addError() : static
- Creates and adds an Error object to this ErrorBag.
- exists() : bool
- Returns true if the passed header exists in this collection.
- get() : IHeader|null
- Returns the IHeader object for the header with the given $name, or null if none exist.
- getAll() : array<string|int, IHeader>
- Returns all headers with the passed name.
- getAllErrors() : array<string|int, Error>
- Returns any errors on this object, and all IErrorBag children of this object at or above the passed PSR log level from Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
- getAs() : IHeader|null
- Returns the IHeader object for the header with the given $name, or null if none exist, using the passed $iHeaderClass to construct it.
- getErrorLoggingContextName() : string
- Returns the class name. Override to identify objects in logs.
- getErrors() : array<string|int, Error>
- Returns any local errors this object has at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
- getFilename() : string|null
- Returns the filename included in the uuencoded 'begin' line for this part.
- getHeaderObjects() : array<string|int, IHeader>
- Returns an array of IHeader objects representing all headers in this collection.
- getHeaders() : array<string|int, array<string|int, string>>
- Returns an array of headers in this collection. Each returned element in the array is an array with the first element set to the name, and the second its value:
- getIterator() : Traversable
- Returns an iterator to the headers in this collection. Each returned element is an array with its first element set to the header's name, and the second to its value:
- getUnixFileMode() : int|null
- Returns the file mode included in the uuencoded 'begin' line for this part.
- hasAnyErrors() : bool
- Returns true if there are errors on this object, or any IErrorBag child of this object at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). Note that this will stop after finding the first error and return, so may be slightly more performant if an error actually exists over calling getAllErrors if only interested in whether an error exists.
- hasErrors() : bool
- Returns true if this object has an error in its error bag at or above the passed $minPsrLevel (defaults to ERROR). If $validate is true, additional validation may be performed.
- remove() : bool
- Removes the header from the collection with the passed name. Defaults to removing the first instance of the header for a collection that contains more than one with the same passed name.
- removeAll() : bool
- Removes all headers that match the passed name.
- set() : static
- If a header exists with the passed name, and at the passed offset if more than one exists, its value is updated.
- setFilename() : static
- Sets the filename included in the uuencoded 'begin' line.
- setUnixFileMode() : static
- Sets the unix file mode for the uuencoded 'begin' line.
- getErrorBagChildren() : array<string|int, IErrorBag>
- Return any children ErrorBag objects.
- validate() : void
- Perform any extra validation and call 'addError'.
- getAllWithOriginalHeaderNameIfSet() : array<string|int, int>|null
- Returns an array of header indexes with names that more closely match the passed $name if available: for instance if there are two headers in an email, "Content-Type" and "ContentType", and the query is for a header with the name "Content-Type", only headers that match exactly "Content-Type" would be returned.
- getByIndex() : IHeader|null
- Returns the header in the headers array at the passed 0-based integer index or null if one doesn't exist.
- getByIndexAs() : IHeader|null
- Returns the header in the headers array at the passed 0-based integer index or null if one doesn't exist, using the passed $iHeaderClass to construct it.
Properties
$filename
protected
string|null
$filename
= null
the name of the file in the uuencoding 'header'.
$headerFactory
protected
HeaderFactory
$headerFactory
the HeaderFactory object used for created headers
$logger
protected
LoggerInterface
$logger
$mode
protected
int|null
$mode
= null
the unix file permission
$errors
private
array<string|int, mixed>
$errors
= []
array of Error objects belonging to this object.
$headerMap
private
array<string|int, mixed>
$headerMap
= []
Maps header names by their "normalized" (lower-cased, non-alphanumeric characters stripped) name to an array of indexes in the $headers array. For example: $headerMap['contenttype'] = [ 1, 4 ] would indicate that the headers in $headers[1] and $headers[4] are both headers with the name 'Content-Type' or 'contENTtype'.
$headerObjects
private
array<string|int, IHeader>
$headerObjects
= []
Each element is an IHeader representing the header at the same index in the $headers array. If an IHeader has not been constructed for the header at that index, the element would be set to null.
$headers
private
array<string|int, array<string|int, string>>
$headers
= []
Each element in the array is an array with its first element set to the header's name, and the second its value.
$nextIndex
private
int
$nextIndex
= 0
the next index to use for $headers and $headerObjects.
$validated
private
bool
$validated
= false
true once the object has been validated.
Methods
__construct()
public
__construct(LoggerInterface $logger) : mixed
Parameters
- $logger : LoggerInterface
Return values
mixed —add()
Adds the header to the collection.
public
add(string $name, string $value) : static
Parameters
- $name : string
- $value : string
Return values
static —addError()
Creates and adds an Error object to this ErrorBag.
public
addError(string $message, string $psrLogLevel[, Throwable|null $exception = null ]) : static
Parameters
- $message : string
- $psrLogLevel : string
- $exception : Throwable|null = null
Return values
static —exists()
Returns true if the passed header exists in this collection.
public
exists(string $name, int $offset) : bool
Parameters
- $name : string
- $offset : int
Return values
bool —get()
Returns the IHeader object for the header with the given $name, or null if none exist.
public
get(string $name, int $offset) : IHeader|null
An optional offset can be provided, which defaults to the first header in the collection when more than one header with the same name exists.
Note that mime headers aren't case sensitive.
Parameters
- $name : string
- $offset : int
Return values
IHeader|null —getAll()
Returns all headers with the passed name.
public
getAll(string $name) : array<string|int, IHeader>
Parameters
- $name : string
Return values
array<string|int, IHeader> —getAllErrors()
Returns any errors on this object, and all IErrorBag children of this object at or above the passed PSR log level from Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
public
getAllErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : array<string|int, Error>
Care should be taken using this if the intention is to only 'preview' a message without parsing it entirely, since this will cause the whole message to be parsed as it traverses children, and could be slow on messages with large attachments, etc...
If $validate is true, additional validation may be performed on children to check for errors.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
array<string|int, Error> —getAs()
Returns the IHeader object for the header with the given $name, or null if none exist, using the passed $iHeaderClass to construct it.
public
getAs(string $name, string $iHeaderClass, int $offset) : IHeader|null
An optional offset can be provided, which defaults to the first header in the collection when more than one header with the same name exists.
Note that mime headers aren't case sensitive.
Parameters
- $name : string
- $iHeaderClass : string
- $offset : int
Return values
IHeader|null —getErrorLoggingContextName()
Returns the class name. Override to identify objects in logs.
public
getErrorLoggingContextName() : string
Return values
string —getErrors()
Returns any local errors this object has at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
public
getErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : array<string|int, Error>
If $validate is true, additional validation may be performed on the object to check for errors.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
array<string|int, Error> —getFilename()
Returns the filename included in the uuencoded 'begin' line for this part.
public
getFilename() : string|null
Return values
string|null —getHeaderObjects()
Returns an array of IHeader objects representing all headers in this collection.
public
getHeaderObjects() : array<string|int, IHeader>
Return values
array<string|int, IHeader> —getHeaders()
Returns an array of headers in this collection. Each returned element in the array is an array with the first element set to the name, and the second its value:
public
getHeaders() : array<string|int, array<string|int, string>>
[ [ 'Header-Name', 'Header Value' ], [ 'Second-Header-Name', 'Second-Header-Value' ], // etc... ]
Return values
array<string|int, array<string|int, string>> —getIterator()
Returns an iterator to the headers in this collection. Each returned element is an array with its first element set to the header's name, and the second to its value:
public
getIterator() : Traversable
[ 'Header-Name', 'Header Value' ]
return Traversable<array
Return values
Traversable —getUnixFileMode()
Returns the file mode included in the uuencoded 'begin' line for this part.
public
getUnixFileMode() : int|null
Return values
int|null —hasAnyErrors()
Returns true if there are errors on this object, or any IErrorBag child of this object at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). Note that this will stop after finding the first error and return, so may be slightly more performant if an error actually exists over calling getAllErrors if only interested in whether an error exists.
public
hasAnyErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : bool
Care should be taken using this if the intention is to only 'preview' a message without parsing it entirely, since this will cause the whole message to be parsed as it traverses children, and could be slow on messages with large attachments, etc...
If $validate is true, additional validation may be performed to check for errors.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
bool —hasErrors()
Returns true if this object has an error in its error bag at or above the passed $minPsrLevel (defaults to ERROR). If $validate is true, additional validation may be performed.
public
hasErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : bool
The PSR levels are defined in Psr\Log\LogLevel.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
bool —remove()
Removes the header from the collection with the passed name. Defaults to removing the first instance of the header for a collection that contains more than one with the same passed name.
public
remove(string $name, int $offset) : bool
Parameters
- $name : string
- $offset : int
Return values
bool —true if a header was found and removed.
removeAll()
Removes all headers that match the passed name.
public
removeAll(string $name) : bool
Parameters
- $name : string
Return values
bool —true if one or more headers were removed.
set()
If a header exists with the passed name, and at the passed offset if more than one exists, its value is updated.
public
set(string $name, string $value, int $offset) : static
If a header with the passed name doesn't exist at the passed offset, it is created at the next available offset (offset is ignored when adding).
Parameters
- $name : string
- $value : string
- $offset : int
Return values
static —setFilename()
Sets the filename included in the uuencoded 'begin' line.
public
setFilename(string $filename) : static
Parameters
- $filename : string
Return values
static —setUnixFileMode()
Sets the unix file mode for the uuencoded 'begin' line.
public
setUnixFileMode(int $mode) : static
Parameters
- $mode : int
Return values
static —getErrorBagChildren()
Return any children ErrorBag objects.
protected
abstract getErrorBagChildren() : array<string|int, IErrorBag>
Return values
array<string|int, IErrorBag> —validate()
Perform any extra validation and call 'addError'.
protected
validate() : void
getErrors and getAllErrors call validate() if their $validate parameter is true. validate() is only called once on an object with getErrors getAllErrors.
Return values
void —getAllWithOriginalHeaderNameIfSet()
Returns an array of header indexes with names that more closely match the passed $name if available: for instance if there are two headers in an email, "Content-Type" and "ContentType", and the query is for a header with the name "Content-Type", only headers that match exactly "Content-Type" would be returned.
private
getAllWithOriginalHeaderNameIfSet(string $name) : array<string|int, int>|null
Parameters
- $name : string
Return values
array<string|int, int>|null —getByIndex()
Returns the header in the headers array at the passed 0-based integer index or null if one doesn't exist.
private
getByIndex(int $index) : IHeader|null
Parameters
- $index : int
Return values
IHeader|null —getByIndexAs()
Returns the header in the headers array at the passed 0-based integer index or null if one doesn't exist, using the passed $iHeaderClass to construct it.
private
getByIndexAs(int $index, string $iHeaderClass) : IHeader|null
Parameters
- $index : int
- $iHeaderClass : string