efureev / response-actions
Single Action structure for HTTP-Response
Installs: 5 341
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1|^8.2
- ext-mbstring: *
Requires (Dev)
- phpstan/phpstan: ^1.10.14
- phpunit/phpunit: ^10.1.1
- squizlabs/php_codesniffer: ^3.7.2
- symfony/var-dumper: ^6.2
README
Action Message Response Structure
{ // Logic data block "data": [], // Action Message block (can be overwritten) "_responseAction": { // Request Execution Status. See: \App\Shared\UI\Response\ActionMessage\Types\StatusEnum::name() "status": "success", // list of actions \App\Shared\UI\Response\ActionMessage\Actions\Action "actions": [ { // ... some action's body } ] } }
Actions
- Message
- MessageError: Message with Code
- Command
- HttpCommand
- Download
- Event
- Redirect
Common Action's Props
{ // Action's Name "name": "message", // Action Order to perform. Default = 0 "order": 1, }
Action Message
{ // message to show to user "message": "It's done!", // Type of the message "type": "info", }
ResponseAction::successMessage('Operation has success!');
You can make multi-message with different type:
ResponseAction::errorMessage('Operation has failed!') ->addAction(Message::info('Try to restart page'));
Action MessageError
{ // message to show to user "message": "It's done!", // type: int|string "code": 321, "type": "error", }
Action Command
{ // done | failed "status": "failed", // type: string|null "description": "Reason..." }
Action Download
{ "url": "https://example.com/file.pdf", "name": "Readme.pdf", }
Action Event
{ "event": "uploadData", "params": [], }
Action Redirect
{ "url": "https://example.com", "target": "_blank", }
Private
You can use private props:
$responseAction = ResponseAction::successMessage('Operation has done!') ->addAction( Event::make('log', ['saved!', 'continue watching...']), Event::make('uploadModuleData')->private(), Event::make('uploadData')->private('menu'), Event::make('refreshUser')->private('authUser')->setOrder(1), Redirect::make('https://example.com')->setOrder(5), Download::make('https://example.com/file.pdf', 'Readme.pdf')->setOrder(2), );
ExtraData
You can use extra data:
$responseAction = ResponseAction::cmdDone() ->withExtra([]);