hyperf-view/builder/FormRequest.php

62 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
/**
* MineAdmin is committed to providing solutions for quickly building web applications
* Please view the LICENSE file that was distributed with this source code,
* For the full copyright and license information.
* Thank you very much for using MineAdmin.
*
* @Author X.Mo<root@imoi.cn>
* @Link https://gitee.com/xmo/MineAdmin
*/
namespace Builder;
use Hyperf\Validation\Request\FormRequest as rForm;
class FormRequest extends rForm
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* 公共规则
* @return array
*/
public function commonRules(): array
{
return [];
}
/**
* Get the validation rules that apply to the request.
* @return array
*/
public function rules(): array
{
$operation = $this->getOperation();
$method = $operation . 'Rules';
$rules = ( $operation && method_exists($this, $method) ) ? $this->$method() : [];
return array_merge($rules, $this->commonRules());
}
/**
* @return string|null
*/
protected function getOperation(): ?string
{
$path = explode('/', $this->path());
do {
$operation = array_pop($path);
} while (is_numeric($operation));
return $operation;
}
}