public static function extendEngineResolver(
        ContainerInterface $container,
        ?EngineResolver $engines = null
    ): ?EngineResolver {
        if ($engines !== null) {
            // @var EngineResolver $engines
            $engines->register('twig', static function () use ($container) {
                return $container->get(TwigEngine::class);
            });
        }

        return $engines;
    }