1. Go to this page and download the library: Download rice/basic library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rice / basic example snippets
namespace App\Assembler;
use App\DTO\TestDTO;
use Illuminate\Http\Request;
class TestAssembler implements BaseAssembler
{
public function toDTO(Request $request)
{
return (new TestDTO())
->setName($request->name)
->setPassword($request->password);
}
}
class ReturnCodeEnum extends BaseEnum
implements ClientErrorCode, SystemErrorCode, ServiceErrorCode
{
/**
* @default OK
*/
public const OK = '00000';
}
namespace Rice\Basic\Components\Exception;
use Rice\Basic\Components\Enum\BaseEnum;
use Rice\Basic\Components\Enum\HttpStatusCodeEnum;
use Rice\Basic\Components\Enum\InvalidRequestEnum;
class InvalidRequestException extends BaseException
{
public static function httpStatusCode(): int
{
return HttpStatusCodeEnum::INVALID_REQUEST;
}
public static function enumClass(): string
{
return InvalidRequestEnum::class;
}
/**
* @throws InvalidRequestException
*/
public static function default(): void
{
throw new self(InvalidRequestEnum::DEFAULT);
}
/**
* 如果这里是控制器的话,我们只要维护好 `phpstorm` 自带注释,那在做注解自动获取异常返回时
* 我们就能为 openApi 生成一个异常返回
*
* @throws InvalidRequestException
*/
public static function InvalidParam(): void
{
throw new self(BaseEnum::INVALID_PARAM);
}
}
$cat->speak;
$cat->getSpeak();
$cat->setSpeak($val);
class Cat
{
use AutoFillProperties;
/**
* @var string
*/
public $eyes;
/**
* @var Eat
*/
public $eat;
/**
* @var Speak
*/
public $speak;
/**
* @var string[]
*/
public $hair;
}
class Cat
{
use AutoFillProperties;
#[Doc(var: 'Eye[]', text: '眼睛')]
public $eyes;
#[Doc(var: 'Eat')]
public $eat;
#[Doc(var: 'Speak')]
public $speak;
#[Doc(var: 'string[]')]
public $hair;
}
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Rice\Basic\Support\Traits\Accessor;
use Rice\Basic\Support\Traits\AutoFillProperties;
class BaseRequest extends FormRequest
{
use AutoFillProperties, Accessor;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
namespace App\Http\Controllers;
use App\Logic\TestLogic;
use Illuminate\Http\Request;
use App\Assembler\TestAssembler;
use App\Http\Requests\TestRequest;
use Illuminate\Support\Facades\Response;
class TestController extends BaseController
{
public function test(Request $request): \Illuminate\Http\JsonResponse
{
$testRequest = new TestRequest($request->all());
$testRequest->check();
$testLogic = (new TestLogic());
$dto = TestAssembler::toDTO($request);
$resp = $testLogic->doSomethink($dto);
return Response::json($resp);
}
}
abstract class LaravelClient extends GuzzleClient
{
public static function build()
{
return new static(LaravelLog::build());
}
}
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Rice\Basic\Support\Traits\Scene;
class SceneRequest extends FormRequest
{
use Scene;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'state' => '
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.