33
33
use Symfony \Component \HttpFoundation \Response ;
34
34
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
35
35
use Symfony \Component \HttpKernel \Kernel as BaseKernel ;
36
- use Symfony \Component \Mercure \Hub ;
37
36
use Symfony \Component \Mercure \HubInterface ;
38
37
use Symfony \Component \Mercure \Update ;
39
38
use Symfony \Component \Routing \Loader \Configurator \RoutingConfigurator ;
@@ -117,8 +116,6 @@ protected function configureContainer(ContainerConfigurator $container): void
117
116
],
118
117
],
119
118
]);
120
-
121
- $ container ->services ()->alias (Hub::class, 'mercure.hub.default ' ); // FIXME: temporary fix for a bug in https://github.com/symfony/mercure-bundle/pull/42
122
119
}
123
120
124
121
protected function configureRoutes (RoutingConfigurator $ routes ): void
@@ -135,6 +132,7 @@ protected function configureRoutes(RoutingConfigurator $routes): void
135
132
$ routes ->add ('songs ' , '/songs ' )->controller ('kernel::songs ' );
136
133
$ routes ->add ('artists ' , '/artists ' )->controller ('kernel::artists ' );
137
134
$ routes ->add ('artist ' , '/artists/{id} ' )->controller ('kernel::artist ' );
135
+ $ routes ->add ('artist_from_song ' , '/artistFromSong ' )->controller ('kernel::artistFromSong ' );
138
136
}
139
137
140
138
public function getProjectDir (): string
@@ -265,4 +263,42 @@ public function artist(Request $request, EntityManagerInterface $doctrine, Envir
265
263
266
264
return new Response ($ twig ->render ('artist.html.twig ' , ['artist ' => $ artist ]));
267
265
}
266
+
267
+ public function artistFromSong (Request $ request , EntityManagerInterface $ doctrine , Environment $ twig ): Response
268
+ {
269
+ $ song = null ;
270
+ if ($ request ->isMethod ('POST ' )) {
271
+ // on first post, create the objects
272
+ // on second, update the artist
273
+ $ id = $ request ->get ('id ' );
274
+ if (!$ id ) {
275
+ $ artist = new Artist ();
276
+ $ artist ->name = 'testing artist ' ;
277
+
278
+ $ song = new Song ();
279
+ $ song ->artist = $ artist ;
280
+ $ song ->title = 'testing song title ' ;
281
+
282
+ $ doctrine ->persist ($ artist );
283
+ $ doctrine ->persist ($ song );
284
+ $ doctrine ->flush ();
285
+ } else {
286
+ $ song = $ doctrine ->find (Song::class, $ id );
287
+ if (!$ song ) {
288
+ throw new NotFoundHttpException ();
289
+ }
290
+ $ artist = $ song ->artist ;
291
+ if (!$ artist ) {
292
+ throw new NotFoundHttpException ();
293
+ }
294
+ $ artist ->name = $ artist ->name .' after change ' ;
295
+
296
+ $ doctrine ->flush ();
297
+ }
298
+ }
299
+
300
+ return new Response ($ twig ->render ('artist_from_song.html.twig ' , [
301
+ 'song ' => $ song ,
302
+ ]));
303
+ }
268
304
}
0 commit comments