1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VGirol\JsonApiFaker\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use VGirol\JsonApiFaker\Contract\RelationshipContract; |
7
|
|
|
use VGirol\JsonApiFaker\Exception\JsonApiFakerException; |
8
|
|
|
use VGirol\JsonApiFaker\Generator as BaseGenerator; |
9
|
|
|
use VGirol\JsonApiFaker\Laravel\Contract\GeneratorContract; |
10
|
|
|
use VGirol\JsonApiFaker\Laravel\Contract\ResourceIdentifierContract; |
11
|
|
|
use VGirol\JsonApiFaker\Laravel\Contract\ResourceObjectContract; |
12
|
|
|
use VGirol\JsonApiFaker\Laravel\Contract\RiCollectionContract; |
13
|
|
|
use VGirol\JsonApiFaker\Laravel\Contract\RoCollectionContract; |
14
|
|
|
use VGirol\JsonApiFaker\Laravel\Factory\RelationshipFactory; |
15
|
|
|
use VGirol\JsonApiFaker\Laravel\Factory\ResourceIdentifierFactory; |
16
|
|
|
use VGirol\JsonApiFaker\Laravel\Factory\ResourceObjectFactory; |
17
|
|
|
use VGirol\JsonApiFaker\Laravel\Factory\RiCollectionFactory; |
18
|
|
|
use VGirol\JsonApiFaker\Laravel\Factory\RoCollectionFactory; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This class extends the \VGirol\JsonApiFaker\Generator class. |
22
|
|
|
*/ |
23
|
|
|
class Generator extends BaseGenerator implements GeneratorContract |
24
|
|
|
{ |
25
|
60 |
|
public function __construct() |
26
|
|
|
{ |
27
|
60 |
|
parent::__construct(); |
28
|
|
|
|
29
|
60 |
|
$this->setFactory('ri-collection', RiCollectionFactory::class) |
30
|
60 |
|
->setFactory('ro-collection', RoCollectionFactory::class) |
31
|
60 |
|
->setFactory('relationship', RelationshipFactory::class) |
32
|
60 |
|
->setFactory('resource-identifier', ResourceIdentifierFactory::class) |
33
|
60 |
|
->setFactory('resource-object', ResourceObjectFactory::class); |
34
|
60 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create a resource identifier collection factory. |
38
|
|
|
* |
39
|
|
|
* @param Collection $collection |
40
|
|
|
* @param string|null $resourceType |
41
|
|
|
* |
42
|
|
|
* @return RiCollectionContract |
43
|
|
|
* @throws JsonApiFakerException |
44
|
|
|
*/ |
45
|
15 |
|
public function riCollection($collection, ?string $resourceType) |
46
|
|
|
{ |
47
|
15 |
|
return $this->create('ri-collection')->setCollection($collection, $resourceType); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create a resource object collection factory. |
52
|
|
|
* |
53
|
|
|
* @param Collection $collection |
54
|
|
|
* @param string|null $resourceType |
55
|
|
|
* |
56
|
|
|
* @return RoCollectionContract |
57
|
|
|
* @throws JsonApiFakerException |
58
|
|
|
*/ |
59
|
|
|
public function roCollection($collection, ?string $resourceType) |
60
|
|
|
{ |
61
|
|
|
return $this->create('ro-collection')->setCollection($collection, $resourceType); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return ResourceIdentifierContract |
66
|
|
|
* @throws JsonApiFakerException |
67
|
|
|
*/ |
68
|
21 |
|
public function resourceIdentifier(...$args) |
69
|
|
|
{ |
70
|
21 |
|
return parent::resourceIdentifier(...$args); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return ResourceObjectContract |
75
|
|
|
* @throws JsonApiFakerException |
76
|
|
|
*/ |
77
|
6 |
|
public function resourceObject(...$args) |
78
|
|
|
{ |
79
|
6 |
|
return parent::resourceObject(...$args); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return RelationshipContract |
84
|
|
|
* @throws JsonApiFakerException |
85
|
|
|
*/ |
86
|
15 |
|
public function relationship(...$args) |
87
|
|
|
{ |
88
|
15 |
|
return parent::relationship(...$args); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|