Skip to content

Commit

Permalink
Added possibillity to add more than one message to messagebag in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Nov 3, 2024
1 parent 3512fa0 commit 1ffdb58
Show file tree
Hide file tree
Showing 5 changed files with 681 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/ZugferdMailMessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,11 @@ public function addThrowable(Throwable $throwable, string $source, array $additi
*/
private function getMessageBagFilteredByType(string $messageType): array
{
return array_map(
function ($data) {
return $data["message"];
},
array_filter(
$this->messageContainer,
function ($data) use ($messageType) {
return $data['type'] == $messageType;
}
)
return array_filter(
$this->messageContainer,
function ($data) use ($messageType) {
return $data['type'] == $messageType;
}
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ZugferdMailReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private function validateDocument(ZugferdDocument $document, array $messageAddit
{
if ($this->config->getSymfonyValidationEnabled()) {
$validator = new ZugferdDocumentValidator($document);
$this->raiseRuntimeExceptionIf(count($validator->validateDocument()) != 0, "Validation against Symfony-Validation failed");
$this->raiseRuntimeExceptionIf($validator->validateDocument()->count() != 0, "Validation against Symfony-Validation failed");
$this->addSuccessMessageToMessageBag('The document was successfully validated against Symfony validator', $messageAdditionalData);
} else {
$this->addLogSecondaryMessageToMessageBag('The document was not validated against Symfony validator (Disabled)', $messageAdditionalData);
Expand Down
2 changes: 1 addition & 1 deletion src/concerns/ZugferdMailParsesPlaceholders.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function parsePlaceholdersByZugferdDocumentReader(ZugferdDocumentReade
* Parses a string ($subject) with values from an array ($keyValuePairs)
*
* @param array<string, mixed> $keyValuePairs
* @param string $subject
* @param string $subject
* @return string
*/
protected function parsePlaceholdersByArray(array $keyValuePairs, string $subject): string
Expand Down
285 changes: 285 additions & 0 deletions src/concerns/ZugferdMailSendsMessagesToMessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,291 @@ protected function addThrowableToMessageBag(Throwable $throwable, array $additio
return $this;
}

/**
* Helper function for adding messages to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param string $type
* @param string $message
* @param array $additionalData
* @return static
*/
protected function addMessageToMessageBagIf(bool $condition, string $type, string $message, array $additionalData = [])
{
return $condition === true ? $this->addMessageToMessageBag($type, $message, $additionalData) : $this;
}

/**
* Helper function for adding a log entry to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param string $message
* @param array $additionalData
* @return static
*/
protected function addLogMessageToMessageBagIf(bool $condition, string $message, array $additionalData = [])
{
return $condition === true ? $this->addLogMessageToMessageBag($message, $additionalData) : $this;
}

/**
* Helper function for adding a secondary log entry to message bag if $condition evaluates to true
*
* @param string $message
* @param array $additionalData
* @return static
*/
protected function addLogSecondaryMessageToMessageBagIf(bool $condition, string $message, array $additionalData = [])
{
return $condition === true ? $this->addLogSecondaryMessageToMessageBag($message, $additionalData) : $this;
}

/**
* Helper function for adding a warning entry to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param string $message
* @param array $additionalData
* @return static
*/
protected function addWarningMessageToMessageBagIf(bool $condition, string $message, array $additionalData = [])
{
return $condition === true ? $this->addWarningMessageToMessageBag($message, $additionalData) : $this;
}

/**
* Helper function for adding a error entry to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param string $message
* @param array $additionalData
* @return static
*/
protected function addErrorMessageToMessageBagIf(bool $condition, string $message, array $additionalData = [])
{
return $condition === true ? $this->addErrorMessageToMessageBag($message, $additionalData) : $this;
}

/**
* Helper function for adding a success entry to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param string $message
* @param array $additionalData
* @return static
*/
protected function addSuccessMessageToMessageBagIf(bool $condition, string $message, array $additionalData = [])
{
return $condition === true ? $this->addSuccessMessageToMessageBag($message, $additionalData) : $this;
}

/**
* Helper function for adding an throwable (Exception) to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param Throwable $throwable
* @param array $additionalData
* @return static
*/
protected function addThrowableToMessageBagIf(bool $condition, Throwable $throwable, array $additionalData = [])
{
return $condition === true ? $this->addThrowableToMessageBag($throwable, $additionalData) : $this;
}

/**
* Helper function for adding multiple messages to message bag
*
* @param string $type
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleMessagesToMessageBag(string $type, array $messages, array $additionalData = [])
{
array_walk(
$messages,
function ($message) use ($type, $additionalData) {
$this->addMessageToMessageBag($type, $message, $additionalData);
}
);

return $this;
}

/**
* Helper function for adding multiple log entries to message bag
*
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleLogMessagesToMessageBag(array $messages, array $additionalData = [])
{
array_walk(
$messages,
function ($message) use ($additionalData) {
$this->addLogMessageToMessageBag($message, $additionalData);
}
);

return $this;
}

/**
* Helper function for adding multiple secondary log entries to message bag
*
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleLogSecondaryMessagesToMessageBag(array $messages, array $additionalData = [])
{
array_walk(
$messages,
function ($message) use ($additionalData) {
$this->addLogSecondaryMessageToMessageBag($message, $additionalData);
}
);

return $this;
}

/**
* Helper function for adding multiple warning entries to message bag
*
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleWarningMessagesToMessageBag(array $messages, array $additionalData = [])
{
array_walk(
$messages,
function ($message) use ($additionalData) {
$this->addWarningMessageToMessageBag($message, $additionalData);
}
);

return $this;
}

/**
* Helper function for adding multiple error entries to message bag
*
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleErrorMessagesToMessageBag(array $messages, array $additionalData = [])
{
array_walk(
$messages,
function ($message) use ($additionalData) {
$this->addErrorMessageToMessageBag($message, $additionalData);
}
);

return $this;
}

/**
* Helper function for adding multiple success entries to message bag
*
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleSuccessMessagesToMessageBag(array $messages, array $additionalData = [])
{
array_walk(
$messages,
function ($message) use ($additionalData) {
$this->addSuccessMessageToMessageBag($message, $additionalData);
}
);

return $this;
}

/**
* Helper function for adding multiple messages to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param string $type
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleMessagesToMessageBagIf(bool $condition, string $type, array $messages, array $additionalData = [])
{
return $condition === true ? $this->addMultipleMessagesToMessageBag($type, $messages, $additionalData) : $this;
}

/**
* Helper function for adding multiple log entries to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleLogMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = [])
{
return $condition === true ? $this->addMultipleLogMessagesToMessageBag($messages, $additionalData) : $this;
}

/**
* Helper function for adding multiple secondary log entries to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleLogSecondaryMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = [])
{
return $condition === true ? $this->addMultipleLogSecondaryMessagesToMessageBag($messages, $additionalData) : $this;
}

/**
* Helper function for adding multiple warning entries to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleWarningMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = [])
{
return $condition === true ? $this->addMultipleWarningMessagesToMessageBag($messages, $additionalData) : $this;
}

/**
* Helper function for adding multiple error entries to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleErrorMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = [])
{
return $condition === true ? $this->addMultipleErrorMessagesToMessageBag($messages, $additionalData) : $this;
}

/**
* Helper function for adding multiple success entries to message bag if $condition evaluates to true
*
* @param boolean $condition
* @param array $messages
* @param array $additionalData
* @return static
*/
protected function addMultipleSuccessMessagesToMessageBagIf(bool $condition, array $messages, array $additionalData = [])
{
return $condition === true ? $this->addMultipleSuccessMessagesToMessageBag($messages, $additionalData) : $this;
}

/**
* Helper function for getting the source from a current classname
*
Expand Down
Loading

0 comments on commit 1ffdb58

Please sign in to comment.