@@ -51,31 +51,27 @@ trait ControllerTrait
51
51
*/
52
52
protected function getRouter (): RouterInterface
53
53
{
54
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , RouterInterface::class));
55
54
}
56
55
57
56
/**
58
57
* @required
59
58
*/
60
59
protected function getRequestStack (): RequestStack
61
60
{
62
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , RequestStack::class));
63
61
}
64
62
65
63
/**
66
64
* @required
67
65
*/
68
66
protected function getHttpKernel (): HttpKernelInterface
69
67
{
70
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , HttpKernelInterface::class));
71
68
}
72
69
73
70
/**
74
71
* @required
75
72
*/
76
73
protected function getSerializer (): SerializerInterface
77
74
{
78
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , SerializerInterface::class));
79
75
}
80
76
81
77
/**
@@ -86,55 +82,48 @@ protected function getSerializer(): SerializerInterface
86
82
*/
87
83
protected function getSession (): Session
88
84
{
89
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , Session::class));
90
85
}
91
86
92
87
/**
93
88
* @required
94
89
*/
95
90
protected function getAuthorizationChecker (): AuthorizationCheckerInterface
96
91
{
97
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , AuthorizationCheckerInterface::class));
98
92
}
99
93
100
94
/**
101
95
* @required
102
96
*/
103
97
protected function getTwig (): \Twig_Environment
104
98
{
105
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , \Twig_Environment::class));
106
99
}
107
100
108
101
/**
109
102
* @required
110
103
*/
111
104
protected function getDoctrine (): ManagerRegistry
112
105
{
113
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , ManagerRegistry::class));
114
106
}
115
107
116
108
/**
117
109
* @required
118
110
*/
119
111
protected function getFormFactory (): FormFactoryInterface
120
112
{
121
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , FormFactoryInterface::class));
122
113
}
123
114
124
115
/**
125
116
* @required
126
117
*/
127
118
protected function getTokenStorage (): TokenStorageInterface
128
119
{
129
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , TokenStorageInterface::class));
130
120
}
131
121
132
122
/**
133
123
* @required
134
124
*/
135
125
protected function getCsrfTokenManager (): CsrfTokenManagerInterface
136
126
{
137
- throw new \LogicException (sprintf ('An instance of "%s" must be provided. ' , CsrfTokenManagerInterface::class));
138
127
}
139
128
140
129
/**
@@ -200,26 +189,22 @@ protected function redirectToRoute(string $route, array $parameters = array(), i
200
189
}
201
190
202
191
/**
203
- * Returns a JsonResponse that uses the serializer component if enabled, or json_encode .
192
+ * Returns a JsonResponse that uses the serializer component.
204
193
*
205
194
* @param mixed $data The response data
206
195
* @param int $status The status code to use for the Response
207
196
* @param array $headers Array of extra headers to add
208
- * @param array $context Context to pass to serializer when using serializer component
197
+ * @param array $context Context to pass to serializer
209
198
*
210
199
* @return JsonResponse
211
200
*/
212
201
protected function json ($ data , int $ status = 200 , array $ headers = array (), array $ context = array ()): JsonResponse
213
202
{
214
- try {
215
- $ json = $ this ->getSerializer ()->serialize ($ data , 'json ' , array_merge (array (
216
- 'json_encode_options ' => JsonResponse::DEFAULT_ENCODING_OPTIONS ,
217
- ), $ context ));
218
-
219
- return new JsonResponse ($ json , $ status , $ headers , true );
220
- } catch (\LogicException $ e ) {
221
- return new JsonResponse ($ data , $ status , $ headers );
222
- }
203
+ $ json = $ this ->getSerializer ()->serialize ($ data , 'json ' , array_merge (array (
204
+ 'json_encode_options ' => JsonResponse::DEFAULT_ENCODING_OPTIONS ,
205
+ ), $ context ));
206
+
207
+ return new JsonResponse ($ json , $ status , $ headers , true );
223
208
}
224
209
225
210
/**
0 commit comments