Bristol SU Support Package
src
Action
Contracts
Action.php
Go to the documentation of this file.
1
<?php
2
3
namespace
BristolSU\Support\Action\Contracts
;
4
5
use
BristolSU\Support\Action\ActionResponse
;
6
use
BristolSU\Support\Action\History\HasHistory
;
7
use
BristolSU\Support\Action\History\RecordsHistory
;
8
use
Exception
;
9
use
FormSchema\Schema\Form
;
10
use
Illuminate\Bus\Queueable
;
11
use
Illuminate\Contracts\Queue\ShouldQueue
;
12
use
Illuminate\Foundation\Bus\Dispatchable
;
13
17
abstract
class
Action
implements
ShouldQueue,
RecordsHistory
18
{
19
use
Dispatchable
,
Queueable
,
HasHistory
;
20
24
private
$data
;
25
29
private
$response
;
30
31
public
function
__construct
(array
$data
= [])
32
{
33
$this->data =
$data
;
34
}
35
43
abstract
public
static
function
options
(): Form;
44
45
public
function
handle
()
46
{
47
try
{
48
$this->response = app()->call([$this,
'run'
]);
49
}
catch
(
Exception
$e) {
50
$this->response =
ActionResponse::failure
(($e->getMessage() ===
''
?
'An error was thrown during processing'
: $e->getMessage()));
51
}
52
if
($this instanceof
RecordsHistory
) {
53
$this->
saveHistory
($this->
getResponse
());
54
}
55
}
56
62
public
function
getResponse
(): ?
ActionResponse
63
{
64
return
$this->response
;
65
}
66
74
public
function
option
(
string
$key, $default = null)
75
{
76
if
(array_key_exists($key, $this->data)) {
77
return
$this->data[$key];
78
}
79
return
$default;
80
}
81
87
public
function
getData
(): array
88
{
89
return
$this->data
;
90
}
91
97
abstract
public
function
run
():
ActionResponse
;
98
99
}
BristolSU\Support\Action\Contracts\Action\options
static options()
Dispatchable
BristolSU\Support\Action\Contracts\Action\option
option(string $key, $default=null)
Definition:
Action.php:74
ShouldQueue
BristolSU\Support\Action\ActionResponse\failure
static failure(string $message='')
Definition:
ActionResponse.php:77
BristolSU\Support\Action\History\RecordsHistory\saveHistory
saveHistory(ActionResponse $response)
BristolSU\Support\Action\Contracts\Action\$response
$response
Definition:
Action.php:29
Form
BristolSU\Support\Action\Contracts\Action\getResponse
getResponse()
Definition:
Action.php:62
BristolSU\Support\Action\Contracts\Action\getData
getData()
Definition:
Action.php:87
Queueable
ActionResponse
Dispatchable
HasHistory
BristolSU\Support\Action\Contracts\Action\__construct
__construct(array $data=[])
Definition:
Action.php:31
RecordsHistory
BristolSU\Support\Action\ActionResponse
Definition:
ActionResponse.php:5
HasHistory
BristolSU\Support\Action\Contracts\Action
Definition:
Action.php:17
BristolSU\Support\Action\Contracts\Action\handle
handle()
Definition:
Action.php:45
BristolSU\Support\Action\Contracts\Action\run
run()
BristolSU\Support\Action\Contracts
Definition:
Action.php:3
BristolSU\Support\Action\Contracts\Action\$data
$data
Definition:
Action.php:24
Queueable
BristolSU\Support\Action\History\RecordsHistory
Definition:
RecordsHistory.php:7
Exception
Generated by
1.8.13