File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public function getType()
28
28
{
29
29
$ reflect = new \ReflectionClass ($ this );
30
30
$ className = $ reflect ->getShortName ();
31
- return Inflector::pluralize (Inflector:: camel2id ($ className) );
31
+ return Inflector::camel2id ($ className );
32
32
}
33
33
34
34
/**
Original file line number Diff line number Diff line change 14
14
use yii \web \Linkable ;
15
15
use yii \web \Request ;
16
16
use yii \web \Response ;
17
+ use yii \helpers \Inflector ;
17
18
18
19
class Serializer extends Component
19
20
{
@@ -48,7 +49,10 @@ class Serializer extends Component
48
49
* @var Response the response to be sent. If not set, the `response` application component will be used.
49
50
*/
50
51
public $ response ;
51
-
52
+ /**
53
+ * @var bool whether to automatically pluralize the `type` of resource.
54
+ */
55
+ public $ pluralize = true ;
52
56
53
57
/**
54
58
* @inheritdoc
@@ -113,7 +117,7 @@ protected function serializeModel(ResourceInterface $model)
113
117
114
118
if (!empty ($ relationship )) {
115
119
if (in_array ($ name , $ included )) {
116
- $ data ['relationships ' ][$ name ]['data ' ] = $ relationship ;
120
+ $ data ['relationships ' ][$ name ]['data ' ] = $ relationship ;
117
121
}
118
122
}
119
123
if ($ model instanceof LinksInterface) {
@@ -167,6 +171,9 @@ protected function serializeIdentifier(ResourceIdentifierInterface $identifier)
167
171
if ($ value === null || is_array ($ value ) || (is_object ($ value ) && !method_exists ($ value , '__toString ' ))) {
168
172
throw new InvalidValueException ("The value {$ key } of resource object " . get_class ($ identifier ) . ' MUST be a string. ' );
169
173
}
174
+ if ($ key === 'type ' && $ this ->pluralize ) {
175
+ $ value = Inflector::pluralize ($ value );
176
+ }
170
177
$ result [$ key ] = (string ) $ value ;
171
178
}
172
179
return $ result ;
You can’t perform that action at this time.
0 commit comments