Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mautic.corals.io/app/bundles/CoreBundle/Controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mautic.corals.io/app/bundles/CoreBundle/Controller/FormErrorMessagesTrait.php
<?php

namespace Mautic\CoreBundle\Controller;

use Symfony\Component\Form\FormInterface;

trait FormErrorMessagesTrait
{
    /**
     * @param array<mixed> $formErrors
     */
    public function getFormErrorMessage(array $formErrors): string
    {
        $msg = '';

        foreach ($formErrors as $key => $error) {
            if (!$error) {
                continue;
            }

            if ($msg) {
                $msg .= ', ';
            }

            if (is_string($key)) {
                $msg .= $key.': ';
            }

            if (is_array($error)) {
                $msg .= $this->getFormErrorMessage($error);
            } else {
                $msg .= $error;
            }
        }

        return $msg;
    }

    /**
     * @param FormInterface<mixed> $form
     *
     * @return array<array<string|null>>
     */
    public function getFormErrorMessages(FormInterface $form): array
    {
        $errors = [];

        foreach ($form->getErrors(true) as $error) {
            if (isset($errors[$error->getOrigin()->getName()])) {
                $errors[$error->getOrigin()->getName()] = [$error->getMessage()];
            } else {
                $errors[$error->getOrigin()->getName()][] = $error->getMessage();
            }
        }

        return $errors;
    }

    /**
     * @param FormInterface<mixed> $form
     *
     * @return array<string|null>
     */
    public function getFormErrorCodes(FormInterface $form): array
    {
        $codes = [];

        foreach ($form->getErrors(true) as $error) {
            $code         = $error->getCause()->getCode();
            $codes[$code] = $code;
        }

        return $codes;
    }

    /**
     * @param FormInterface<mixed> $form
     */
    public function getFormErrorForBuilder(FormInterface $form): ?string
    {
        if (!$form->isSubmitted() || $form->isValid()) {
            return null;
        }

        $validationErrors = $this->getFormErrorMessages($form);

        if (!$validationErrors) {
            return null;
        }

        $validationError = $this->getFormErrorMessage($validationErrors);

        return $this->translator->trans('mautic.core.form.builder.error', ['%error%' => $validationError]);
    }
}

Spamworldpro Mini