You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
926 B
PHP
42 lines
926 B
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Contract\ServiceContract;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
|
use Hyperf\Validation\Request\FormRequest;
|
|
|
|
/**
|
|
* @property ServiceContract $service
|
|
* @property FormRequest $request
|
|
*/
|
|
abstract class BaseController
|
|
{
|
|
#[Inject]
|
|
protected ValidatorFactoryInterface $validator;
|
|
|
|
protected function getService(): ServiceContract
|
|
{
|
|
return $this->service;
|
|
}
|
|
|
|
protected function validated(array $rules): array
|
|
{
|
|
$request = $this->getRequest();
|
|
|
|
$validator = $this->validator->make(
|
|
$request->all(),
|
|
$rules,
|
|
$request->messages(),
|
|
$request->attributes()
|
|
);
|
|
$validator->validate();
|
|
return $validator->validated();
|
|
}
|
|
|
|
protected function getRequest(): FormRequest
|
|
{
|
|
return $this->request;
|
|
}
|
|
} |