use Symfony\Component\HttpFoundation\Response; $app = new Silex\Application(); $app->get('/', function () { return new Response('Hello World!'); }); $app->run();
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $app = new Silex\Application(); $app['my_service'] = function () { return new MyService(); }; $app->get('/hello/{name}', function (Request $request, $name) use ($app) { $my_service = $app['my_service']; $message = $my_service->getMessage($name); return new Response($message); }); $app->run();This example demonstrates how to use DependencyInjection in Silex to inject a custom service into a controller action. The controller action retrieves the service from the application container using the `$app['my_service']` key and uses it to generate a message based on the URL parameter `$name`. The Silex package library includes a variety of useful components and functionalities to help developers create web applications faster and easier. These include Routing, Configuration, Service Providers, Twig template engine integration and many more.