@@ -34,12 +34,17 @@ public function hasOne(string $itemClass, string $name = null): OneRelationInter
34
34
$ name = $ name ?: Util::stringSnake (debug_backtrace ()[1 ]['function ' ]);
35
35
36
36
if (!array_key_exists ($ name , $ this ->relations )) {
37
- $ this ->relations [$ name ] = new HasOneRelation ((new $ itemClass ())->getType ());
37
+ $ this ->relations [$ name ] = $ this -> newHasOne ((new $ itemClass ())->getType ());
38
38
}
39
39
40
40
return $ this ->relations [$ name ];
41
41
}
42
42
43
+ protected function newHasOne (string $ type ): OneRelationInterface
44
+ {
45
+ return new HasOneRelation ($ type );
46
+ }
47
+
43
48
/**
44
49
* Create a plural relation to another item.
45
50
*
@@ -53,12 +58,17 @@ public function hasMany(string $itemClass, string $name = null): ManyRelationInt
53
58
$ name = $ name ?: Util::stringSnake (debug_backtrace ()[1 ]['function ' ]);
54
59
55
60
if (!array_key_exists ($ name , $ this ->relations )) {
56
- $ this ->relations [$ name ] = new HasManyRelation ((new $ itemClass ())->getType ());
61
+ $ this ->relations [$ name ] = $ this -> newHasMany ((new $ itemClass ())->getType ());
57
62
}
58
63
59
64
return $ this ->relations [$ name ];
60
65
}
61
66
67
+ protected function newHasMany (string $ type ): ManyRelationInterface
68
+ {
69
+ return new HasManyRelation ($ type );
70
+ }
71
+
62
72
/**
63
73
* Create a singular relation.
64
74
*
@@ -71,12 +81,17 @@ public function morphTo(string $name = null): OneRelationInterface
71
81
$ name = $ name ?: Util::stringSnake (debug_backtrace ()[1 ]['function ' ]);
72
82
73
83
if (!array_key_exists ($ name , $ this ->relations )) {
74
- $ this ->relations [$ name ] = new MorphToRelation ();
84
+ $ this ->relations [$ name ] = $ this -> newMorphTo ();
75
85
}
76
86
77
87
return $ this ->relations [$ name ];
78
88
}
79
89
90
+ protected function newMorphTo (): OneRelationInterface
91
+ {
92
+ return new MorphToRelation ();
93
+ }
94
+
80
95
/**
81
96
* Create a plural relation.
82
97
*
@@ -89,12 +104,17 @@ public function morphToMany(string $name = null): ManyRelationInterface
89
104
$ name = $ name ?: Util::stringSnake (debug_backtrace ()[1 ]['function ' ]);
90
105
91
106
if (!array_key_exists ($ name , $ this ->relations )) {
92
- $ this ->relations [$ name ] = new MorphToManyRelation ();
107
+ $ this ->relations [$ name ] = $ this -> newMorphToMany ();
93
108
}
94
109
95
110
return $ this ->relations [$ name ];
96
111
}
97
112
113
+ protected function newMorphToMany (): ManyRelationInterface
114
+ {
115
+ return new MorphToManyRelation ();
116
+ }
117
+
98
118
/**
99
119
* @return \Swis\JsonApi\Client\Interfaces\OneRelationInterface[]|\Swis\JsonApi\Client\Interfaces\ManyRelationInterface[]
100
120
*/
0 commit comments