|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Mikemirten\Bundle\JsonApiBundle\Response; |
|
5
|
|
|
|
|
6
|
|
|
use Mikemirten\Bundle\JsonApiBundle\Response\Behaviour\HttpAttributesAwareInterface; |
|
7
|
|
|
use Mikemirten\Bundle\JsonApiBundle\Response\Behaviour\HttpAttributesContainer; |
|
8
|
|
|
use Mikemirten\Bundle\JsonApiBundle\Response\Behaviour\IncludedObjectsAwareInterface; |
|
9
|
|
|
use Mikemirten\Bundle\JsonApiBundle\Response\Behaviour\IncludedObjectsContainer; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Abstract Json API view supposed to get handled and converted into a response |
|
13
|
|
|
* |
|
14
|
|
|
* @package Mikemirten\Bundle\JsonApiBundle\Response |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AbstractJsonApiView implements HttpAttributesAwareInterface, IncludedObjectsAwareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
use HttpAttributesContainer; |
|
19
|
|
|
use IncludedObjectsContainer; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Callback to call after a resource-object has created. |
|
23
|
|
|
* |
|
24
|
|
|
* @var callable |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $resourceCallback; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Callback to call after a document has created. |
|
30
|
|
|
* |
|
31
|
|
|
* @var callable |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $documentCallback; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Set a callback to call after a resource-object has created. |
|
37
|
|
|
* |
|
38
|
|
|
* @param callable $callback |
|
39
|
|
|
*/ |
|
40
|
|
|
public function setResourceCallback(callable $callback) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->resourceCallback = $callback; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Has a callback to call after a resource-object has created ? |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
|
|
public function hasResourceCallback(): bool |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->resourceCallback !== null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get a callback to call after a resource-object has created. |
|
57
|
|
|
* |
|
58
|
|
|
* @return callable |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getResourceCallback(): callable |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->resourceCallback; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Set acallback to call after a document has created |
|
67
|
|
|
* |
|
68
|
|
|
* @param callable $callback |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setDocumentCallback(callable $callback) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->documentCallback = $callback; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Has a callback to call after a document has created |
|
77
|
|
|
* |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
|
|
public function hasDocumentCallback(): bool |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->documentCallback !== null; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get a callback to call after a document has created |
|
87
|
|
|
* |
|
88
|
|
|
* @return callable |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getDocumentCallback(): callable |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->documentCallback; |
|
93
|
|
|
} |
|
94
|
|
|
} |