Add replacers to the validator that strip back out the prefix

@param  string                          $prefix
@param  Illuminate\Validation\Validator $validator
@return void
505237
protected function removePrefixFromMessages($prefix, $validator)
    {
        // Get all the rules in a single flat array
        $rules = array_flatten($validator->getRules());

        // Get just the rules, not rule modifiers
        $rules = array_map(function($rule) {
            preg_match('#^([^:]+)#', $rule, $matches);
            return $matches[1];
        }, $rules);

        // Callback that removes isntances of the prefix from a message. Laravel
        // will have already replaced underscores with spaces, so we need to
        // reverse that.
        $prefix = str_replace('_', ' ', $prefix);
        $replacer = function ($message) use ($prefix) {
            return str_replace($prefix, '', $message);
        };

        // Create an array of identical replacer functions
        $replacers = array_fill(0, count($rules), $replacer);

        // Add the replacers to the validtor
        $validator->addReplacers(array_combine($rules, $replacers));
    }
1149898
protected function failedValidation(Validator $validator)
    {
        if ($this->isApiRequest()) {
            throw new ValidationException($validator, $this->getErrorCodes());
        }

        parent::failedValidation($validator);
    }
342657
public function withValidator($validator): void
    {
        $credentials = $this->only('email', 'expiration', 'token');
        $passwordResetBroker = app('auth.password')->broker($this->route('passwordResetBroker'));

        $validator->after(function ($validator) use ($passwordResetBroker, $credentials) {
            if (! ($user = $passwordResetBroker->getUser($credentials))) {
                $validator->errors()->add('email', trans('cortex/auth::'.PasswordResetBrokerContract::INVALID_USER));
            }

            if ($user && ! $passwordResetBroker->validateToken($user, $credentials)) {
                $validator->errors()->add('email', trans('cortex/auth::'.PasswordResetBrokerContract::INVALID_TOKEN));
            }

            if (! $passwordResetBroker->validateTimestamp($credentials['expiration'])) {
                $validator->errors()->add('email', trans('cortex/auth::'.PasswordResetBrokerContract::EXPIRED_TOKEN));
            }
        });
    }
731088
public static function populateValidator(Validator $validator)
	{
		if (static::$provider === null)
		{
			static::setProvider(new FromArray(true, 'validation'));
		}

		return static::$provider->populateValidator($validator);
	}
27584
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('uid', 'create');

        $validator
            ->requirePresence('username', 'create')
            ->notEmpty('username');

        $validator
            ->requirePresence('password', 'create')
            ->notEmpty('password');

        $validator
            ->requirePresence('role', 'create')
            ->notEmpty('role')
            ->add('role', 'inList', [
                'rule' => ['inList', ['admin', 'author']],
                'message' => 'Please enter a valid role'
            ]);

        $validator
            ->boolean('verified')
            ->requirePresence('verified', 'create')
            ->notEmpty('verified');

        $validator
            ->email('email')
            ->requirePresence('email', 'create')
            ->notEmpty('email');

        return $validator;
    }
596813
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('address', 'create')
			->notEmpty('address')
			->add('address', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);

		$validator
			->allowEmpty('formatted_address');

		$validator
			->allowEmpty('country');

		$validator
			->decimal('lat')
			->allowEmpty('lat');

		$validator
			->decimal('lng')
			->allowEmpty('lng');

		$validator
			->allowEmpty('data');

		return $validator;
	}
63540
protected function callValidator($validator)
    {
        if (is_callable($validator)) {
            try {
                call_user_func_array($validator, array($this->value));
            } catch (\Exception $ex) {
                $this->error = $ex->getMessage();
                return false;
            }
        }
    }
739770
protected function removeValidator(Validator $validator) : Component
    {
        $hash = spl_object_hash($validator);
        unset($this->validators[$hash]);

        return $this;
    }
641350
public function extend($validator)
	{
		$validator = is_array($validator) ? $validator : [$validator];

		$this->validators = array_merge($this->validators, $validator);

		return $this;
	}
490209
public function validationDefault(Validator $validator)
    {
        return $validator
            ->add('theme', 'validTheme', [
                'rule' => function ($value, $context) {
                    $exists = plugin()
                        ->filter(function ($plugin) use ($value) {
                            return $plugin->isTheme && $plugin->name === $value;
                        })
                        ->first();

                    return !empty($exists);
                },
                'message' => __d('block', 'Invalid theme for region.'),
            ]);
    }
1291870
private static function checkValidator($validator)
    {
        if (!array_key_exists($validator, self::$validators)) {
            return self::checkClass($validator);
        }
        return self::$validators[$validator];
    }
1043625
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->add('email', 'valid', ['rule' => 'email'])
            ->requirePresence('email', 'create')
            ->notEmpty('email');

        $validator
            ->requirePresence('password', 'create')
            ->notEmpty('password');

        return $validator;
    }
847970
final protected function runExtendedScenario(Validator $validator): void
    {
        if (\is_null($method = $this->validationScenarios['extend'])) {
            return;
        }

        $this->{$method}($validator);
    }
1120694
protected function extendCreate(ValidatorResolver $validator)
    {
        $name = Keyword::make($validator->getData()['name']);

        $validator->after(function (ValidatorResolver $v) use ($name) {
            if ($this->isRoleNameAlreadyUsed($name)) {
                $v->errors()->add('name', trans('orchestra/control::response.roles.reserved-word'));
            }
        });
    }
237497
public function withValidator($validator)
    {
        if ($validator->passes()) {
            $validator->after(function ($validator) {

                try {
                    // get validated data
                    $data = $this->validated();

                    // 1 Copy theme
                    if (empty($data['original_theme'])) {
                        $theme = string_slug($data['APP_NAME']);
                        $dest = app()->resourcePath('themes' . DS . $theme);
                        if (is_dir($dest)) {
                            throw new InstallerFailed(str_replace(':theme', $theme, __('msg.theme_exists')));
                        }
                        $files = new \RecursiveIteratorIterator(
                            new \RecursiveDirectoryIterator(
                                app()->resourcePath('themes' . DS . $data['APP_THEME']),
                                \RecursiveDirectoryIterator::SKIP_DOTS
                            ),
                            \RecursiveIteratorIterator::SELF_FIRST
                        );
                        foreach ($files as $file) {
                            $pathname = $dest . DS . $files->getSubPathName();
                            $file->isDir() ? mkdir($pathname, 0755, true) : copy($file, $pathname);
                        }
                    }

                    // 2 Creat symlink to uploads dir
                    clearstatcache(true, $uploads_path = app()->basePath('uploads'));
                    if (! file_exists($uploads_path)) {
                        symlink(
                            app()->basePath('storage' . DS . 'app' . DS . 'uploads'),
                            $uploads_path
                        );
                    }

                    // 3 Manipulation of the database
                    \DB::beginTransaction();

                    // 3.1 Seed DB
                    $exitCode = \Artisan::call('db:seed', ['--force' => true]);
                    $outputSeed = \Artisan::output();
                    session()->flash('flash_output_seed', $outputSeed);

                    // 3.2 Creat user
                    \DB::table('users')->insert([
                        'name' => $data['name'],
                        'email' => $data['email'],
                        'password' => bcrypt($data['password']),
                        'role' => 'owner',
                        'last_ip' => request()->ip(),
                        'created_at' => date('Y-m-d H:i:s'),
                    ]);

                    // 3.3 Seed test content DB
                    if (! empty($data['test_seed'])) {
                        $exitCode = \Artisan::call('db:seed', ['--force' => true, '--class' => 'TestContentSeeder']);
                        $outputTestSeed = \Artisan::output();
                        session()->flash('flash_output_test_seed', $outputTestSeed);
                    }

                    // 4 Save config files

                    // Finaly set to `.env` variables
                    $this->merge([
                        // Set to new copied theme
                        'APP_THEME' => $theme ?? $data['APP_THEME'],
                        // Set to BBCMS is install complete
                        'APP_SET' => 'true',
                        'APP_DEBUG' => 'false',
                        // Mail settings
                        'MAIL_FROM_NAME' => $data['name'],
                        'MAIL_FROM_ADDRESS' => $data['email'],
                    ]);

                    \DB::commit();
                }
                catch (\InstallerFailed $e) {
                    \DB::rollback();
                    $validator->errors()->add('common', $e->getMessage());
                }

            });
        }

        return $validator;
    }
228936
protected function AddValidator($name, Validator $validator, $errorPrefix = '')
    {
        $field = $this->GetElement($name);
        if (!$errorPrefix)
        {
            $errorPrefix = $this->ErrorPrefix($name);
        }
        $validator->SetErrorLabelPrefix($errorPrefix);
        $field->AddValidator($validator);
    }
708693
public function attachValidators(Validator $validator)
    {
        /** @var ClassMetadata $fileMetadata */
        $fileMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\FileDescriptor');
        /** @var ClassMetadata $constantMetadata */
        $constantMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\ConstantDescriptor');
        /** @var ClassMetadata $functionMetadata */
        $functionMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\FunctionDescriptor');
        /** @var ClassMetadata $classMetadata */
        $classMetadata     = $validator->getMetadataFor('phpDocumentor\Descriptor\ClassDescriptor');
        /** @var ClassMetadata $interfaceMetadata */
        $interfaceMetadata = $validator->getMetadataFor('phpDocumentor\Descriptor\InterfaceDescriptor');
        /** @var ClassMetadata $traitMetadata */
        $traitMetadata     = $validator->getMetadataFor('phpDocumentor\Descriptor\TraitDescriptor');
        /** @var ClassMetadata $propertyMetadata */
        $propertyMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\PropertyDescriptor');
        /** @var ClassMetadata $methodMetadata */
        $methodMetadata    = $validator->getMetadataFor('phpDocumentor\Descriptor\MethodDescriptor');

        $fileMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50000')));
        $classMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50005')));
        $propertyMetadata->addConstraint(new phpDocAssert\Property\HasSummary());
        $methodMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50008')));
        $interfaceMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50009')));
        $traitMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50010')));
        $functionMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50011')));

        $functionMetadata->addConstraint(new phpDocAssert\Functions\IsReturnTypeNotAnIdeDefault());
        $methodMetadata->addConstraint(new phpDocAssert\Functions\IsReturnTypeNotAnIdeDefault());

        $functionMetadata->addConstraint(new phpDocAssert\Functions\IsParamTypeNotAnIdeDefault());
        $methodMetadata->addConstraint(new phpDocAssert\Functions\IsParamTypeNotAnIdeDefault());
        $functionMetadata->addConstraint(new phpDocAssert\Functions\AreAllArgumentsValid());
        $methodMetadata->addConstraint(new phpDocAssert\Functions\AreAllArgumentsValid());

        $classMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
        $interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
        $traitMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
        $fileMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());

        $classMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());
        $interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());
        $traitMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());
        $fileMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());

        $classMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());
        $interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());
        $traitMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());
        $fileMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());

        return $validator;
    }