public function filterMessages(array $messages, array $supportedMessages, $canCreateNewMessages = false)
    {
        // Adding the keys `value` and `extension` to the messages, only if it is missing.
        $addValueToArray = function (array &$a) {
            foreach ($a as $k => $v) {
                if (false === isset($v['value'])) {
                    $a[$k]['value'] = '';
                }
                if (false === isset($v['extension'])) {
                    $a[$k]['extension'] = '';
                }
            }

            return $a;
        };

        $messagesArray = [];
        foreach ($messages as $key => $message) {
            if ($message instanceof FormzMessage) {
                $message = $message->toArray();
            }

            $messagesArray[$key] = $message;
        }

        $addValueToArray($messagesArray);
        $addValueToArray($supportedMessages);

        $messagesResult = $supportedMessages;

        ArrayUtility::mergeRecursiveWithOverrule(
            $messagesResult,
            $messagesArray,
            (bool)$canCreateNewMessages
        );

        return $messagesResult;
    }
public function filterMessages(array $messages, array $supportedMessages, $canCreateNewMessages = false)
    {
        // Adding the keys `value` and `extension` to the messages, only if it is missing.
        $addValueToArray = function (array &$a) {
            foreach ($a as $k => $v) {
                if (false === isset($v['value'])) {
                    $a[$k]['value'] = '';
                }
                if (false === isset($v['extension'])) {
                    $a[$k]['extension'] = '';
                }
            }

            return $a;
        };

        $messagesArray = [];
        foreach ($messages as $key => $message) {
            if ($message instanceof FormzMessage) {
                $message = $message->toArray();
            }

            $messagesArray[$key] = $message;
        }

        $addValueToArray($messagesArray);
        $addValueToArray($supportedMessages);

        $messagesResult = $supportedMessages;

        ArrayUtility::mergeRecursiveWithOverrule(
            $messagesResult,
            $messagesArray,
            (bool)$canCreateNewMessages
        );

        return $messagesResult;
    }
public function filterMessages ( array $ messages , array $ supportedMessages , $ canCreateNewMessages = false ) { // Adding the keys `value` and `extension` to the messages, only if it is missing. $ addValueToArray = function ( array & $ a ) { foreach ( $ a as $ k => $ v ) { if ( false === isset ( $ v [ 'value' ] ) ) { $ a [ $ k ] [ 'value' ] = '' ; } if ( false === isset ( $ v [ 'extension' ] ) ) { $ a [ $ k ] [ 'extension' ] = '' ; } } return $ a ; } ; $ messagesArray = [ ] ; foreach ( $ messages as $ key => $ message ) { if ( $ message instanceof FormzMessage ) { $ message = $ message -> toArray ( ) ; } $ messagesArray [ $ key ] = $ message ; } $ addValueToArray ( $ messagesArray ) ; $ addValueToArray ( $ supportedMessages ) ; $ messagesResult = $ supportedMessages ; ArrayUtility :: mergeRecursiveWithOverrule ( $ messagesResult , $ messagesArray , ( bool ) $ canCreateNewMessages ) ; return $ messagesResult ; }
Will return an array by considering the supported messages, and filling
the supported ones with the given values.

@param FormzMessage[] $messages
@param array          $supportedMessages
@param bool           $canCreateNewMessages
@return array
Will return an array by considering the supported messages and filling the supported ones with the given values .