File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
src/Symfony/Component/Serializer/Normalizer Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Serializer \Normalizer ;
13
13
14
+ use Symfony \Component \Serializer \Exception \InvalidArgumentException ;
14
15
use Symfony \Contracts \Translation \TranslatableInterface ;
15
16
use Symfony \Contracts \Translation \TranslatorInterface ;
16
17
@@ -30,10 +31,14 @@ public function __construct(
30
31
}
31
32
32
33
/**
33
- * @param TranslatableInterface $object
34
+ * @throws InvalidArgumentException
34
35
*/
35
36
public function normalize (mixed $ object , string $ format = null , array $ context = []): string
36
37
{
38
+ if (!$ object instanceof TranslatableInterface) {
39
+ throw new InvalidArgumentException (sprintf ('The object must implement the "%s". ' , TranslatableInterface::class));
40
+ }
41
+
37
42
return $ object ->trans ($ this ->translator , $ context [self ::NORMALIZATION_LOCALE_KEY ] ?? $ this ->defaultContext [self ::NORMALIZATION_LOCALE_KEY ]);
38
43
}
39
44
You can’t perform that action at this time.
0 commit comments