Symfony

Showcase: Migrating FranceTVSport.fr to Drupal 8 and Symfony 4

Submitted by Frederic Marand on

The opening talk as DrupalCamp Paris 2019 was a presentation given by Thomas Jolliet (FranceTV) and yours truly about how we rebuilt FranceTV Sport to a Symfony 4 / headless Drupal 8 combo.

The most salient points of the talk are probably the "defense in depth" mechanisms we built for scalability and fault tolerance, and the business results, like -85% full page load time, -65% speed index, or +50% iOS app traffic.

How to access the mount point without a slash in Silex mounted routes

Submitted by Frederic Marand on

The problem: routing /blogs, not just /blogs/ in Silex

Route mounting in the Silex PHP framework allows conveniently grouping controllers per feature in separate files, then using mounting them on some prefix path like $app->mount('/blogs'). This will prepend the prefix "/blogs" to the paths defined in the the feature controller, effectively delegating to it all the /blogs/* routes. However, as the Silex documentation claims:

When mounting a route collection under /blog, it is not possible to define a route for the /blog URL. The shortest possible URL is /blog/.

This means handling the route mount point has to be done by a route outside the mounted feature, which makes it slightly less clean, as you have to do something like:

<?php
$blog
= require_once __DIR__ . '/controllers-blog.php';
// This will handle /blogs/ and below, but not /blogs
$app->mount('/blogs', $blog);
// So we have to use a non-mounted route from a sub-request to avoid a redirect().
$app->get('/blogs', function () use($app) {
 
// forward to /blogs/
 
$subRequest = Request::create('/blogs/' , 'GET');
  return
$app->handle($subRequest , HttpKernelInterface::SUB_REQUEST);
}
?>

But is there really no workaround for this limitation ? Sure there is!