protected function addAttachments($incomingMessage)
    {
        $attachment = $this->event->get('attachment');

        if ($attachment === self::ATTACHMENT_IMAGE) {
            $images = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Image($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Image::PATTERN);
            $incomingMessage->setImages($images);
        } elseif ($attachment === self::ATTACHMENT_AUDIO) {
            $audio = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Audio($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Audio::PATTERN);
            $incomingMessage->setAudio($audio);
        } elseif ($attachment === self::ATTACHMENT_VIDEO) {
            $videos = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Video($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Video::PATTERN);
            $incomingMessage->setVideos($videos);
        } elseif ($attachment === self::ATTACHMENT_FILE) {
            $files = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new File($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(File::PATTERN);
            $incomingMessage->setFiles($files);
        }

        return $incomingMessage;
    }
protected function addAttachments($incomingMessage)
    {
        $attachment = $this->event->get('attachment');

        if ($attachment === self::ATTACHMENT_IMAGE) {
            $images = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Image($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Image::PATTERN);
            $incomingMessage->setImages($images);
        } elseif ($attachment === self::ATTACHMENT_AUDIO) {
            $audio = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Audio($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Audio::PATTERN);
            $incomingMessage->setAudio($audio);
        } elseif ($attachment === self::ATTACHMENT_VIDEO) {
            $videos = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Video($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Video::PATTERN);
            $incomingMessage->setVideos($videos);
        } elseif ($attachment === self::ATTACHMENT_FILE) {
            $files = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new File($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(File::PATTERN);
            $incomingMessage->setFiles($files);
        }

        return $incomingMessage;
    }
protected function addAttachments ( $ incomingMessage ) { $ attachment = $ this -> event -> get ( 'attachment' ) ; if ( $ attachment === self :: ATTACHMENT_IMAGE ) { $ images = $ this -> files -> map ( function ( $ file ) { if ( $ file instanceof UploadedFile ) { $ path = $ file -> getRealPath ( ) ; } else { $ path = $ file [ 'tmp_name' ] ; } return new Image ( $ this -> getDataURI ( $ path ) ) ; } ) -> values ( ) -> toArray ( ) ; $ incomingMessage -> setText ( Image :: PATTERN ) ; $ incomingMessage -> setImages ( $ images ) ; } elseif ( $ attachment === self :: ATTACHMENT_AUDIO ) { $ audio = $ this -> files -> map ( function ( $ file ) { if ( $ file instanceof UploadedFile ) { $ path = $ file -> getRealPath ( ) ; } else { $ path = $ file [ 'tmp_name' ] ; } return new Audio ( $ this -> getDataURI ( $ path ) ) ; } ) -> values ( ) -> toArray ( ) ; $ incomingMessage -> setText ( Audio :: PATTERN ) ; $ incomingMessage -> setAudio ( $ audio ) ; } elseif ( $ attachment === self :: ATTACHMENT_VIDEO ) { $ videos = $ this -> files -> map ( function ( $ file ) { if ( $ file instanceof UploadedFile ) { $ path = $ file -> getRealPath ( ) ; } else { $ path = $ file [ 'tmp_name' ] ; } return new Video ( $ this -> getDataURI ( $ path ) ) ; } ) -> values ( ) -> toArray ( ) ; $ incomingMessage -> setText ( Video :: PATTERN ) ; $ incomingMessage -> setVideos ( $ videos ) ; } elseif ( $ attachment === self :: ATTACHMENT_FILE ) { $ files = $ this -> files -> map ( function ( $ file ) { if ( $ file instanceof UploadedFile ) { $ path = $ file -> getRealPath ( ) ; } else { $ path = $ file [ 'tmp_name' ] ; } return new File ( $ this -> getDataURI ( $ path ) ) ; } ) -> values ( ) -> toArray ( ) ; $ incomingMessage -> setText ( File :: PATTERN ) ; $ incomingMessage -> setFiles ( $ files ) ; } return $ incomingMessage ; }
Add potential attachments to the message object.

@param IncomingMessage $incomingMessage
@return IncomingMessage
Add potential attachments to the message object .