@@ -706,6 +706,17 @@ private function getWriteAccessInfo($class, $property, $value)
706
706
$ access [self ::ACCESS_HAS_PROPERTY ] = $ reflClass ->hasProperty ($ property );
707
707
$ camelized = $ this ->camelize ($ property );
708
708
$ singulars = (array ) Inflector::singularize ($ camelized );
709
+ $ plural = empty (array_intersect ([$ camelized ], $ singulars ));
710
+
711
+ if ($ plural && \is_array ($ value ) || $ value instanceof \Traversable) {
712
+ $ methods = $ this ->findAdderAndRemover ($ reflClass , $ singulars );
713
+
714
+ if (null !== $ methods ) {
715
+ $ access [self ::ACCESS_TYPE ] = self ::ACCESS_TYPE_ADDER_AND_REMOVER ;
716
+ $ access [self ::ACCESS_ADDER ] = $ methods [0 ];
717
+ $ access [self ::ACCESS_REMOVER ] = $ methods [1 ];
718
+ }
719
+ }
709
720
710
721
if (!isset ($ access [self ::ACCESS_TYPE ])) {
711
722
$ setter = 'set ' .$ camelized ;
@@ -728,22 +739,16 @@ private function getWriteAccessInfo($class, $property, $value)
728
739
$ access [self ::ACCESS_TYPE ] = self ::ACCESS_TYPE_MAGIC ;
729
740
$ access [self ::ACCESS_NAME ] = $ setter ;
730
741
} elseif (null !== $ methods = $ this ->findAdderAndRemover ($ reflClass , $ singulars )) {
731
- if (\is_array ($ value ) || $ value instanceof \Traversable) {
732
- $ access [self ::ACCESS_TYPE ] = self ::ACCESS_TYPE_ADDER_AND_REMOVER ;
733
- $ access [self ::ACCESS_ADDER ] = $ methods [0 ];
734
- $ access [self ::ACCESS_REMOVER ] = $ methods [1 ];
735
- } else {
736
- $ access [self ::ACCESS_TYPE ] = self ::ACCESS_TYPE_NOT_FOUND ;
737
- $ access [self ::ACCESS_NAME ] = sprintf (
738
- 'The property "%s" in class "%s" can be defined with the methods "%s()" but ' .
739
- 'the new value must be an array or an instance of \Traversable, ' .
740
- '"%s" given. ' ,
741
- $ property ,
742
- $ reflClass ->name ,
743
- implode ('()", " ' , $ methods ),
744
- \is_object ($ value ) ? \get_class ($ value ) : \gettype ($ value )
745
- );
746
- }
742
+ $ access [self ::ACCESS_TYPE ] = self ::ACCESS_TYPE_NOT_FOUND ;
743
+ $ access [self ::ACCESS_NAME ] = sprintf (
744
+ 'The property "%s" in class "%s" can be defined with the methods "%s()" but ' .
745
+ 'the new value must be an array or an instance of \Traversable, ' .
746
+ '"%s" given. ' ,
747
+ $ property ,
748
+ $ reflClass ->name ,
749
+ implode ('()", " ' , $ methods ),
750
+ \is_object ($ value ) ? \get_class ($ value ) : \gettype ($ value )
751
+ );
747
752
} else {
748
753
$ access [self ::ACCESS_TYPE ] = self ::ACCESS_TYPE_NOT_FOUND ;
749
754
$ access [self ::ACCESS_NAME ] = sprintf (
0 commit comments