SonataPageBundle: Unable update deprecated RequestFactory::createFromGlobals('host_with_path'); in index.php

https://docs.sonata-project.org/projects/SonataPageBundle/en/3.x/reference/multisite/ contains example index.php. createFromGlobals method is deprecated and SonataPagePathRuntime::createFromGlobals(). https://docs.sonata-project.org/projects/SonataPageBundle/en/5.x/reference/multisite/ contains instructions for Host and Path Strategy configuration, but there is not new index.php. I tried Sonata\PageBundle\Runtime\SonataPagePathRuntime::createFromGlobals() but I got Attempted to call an undefined method named “createFromGlobals” of class “Sonata\PageBundle\Runtime\SonataPagePathRuntime”. I tried another option: Sonata\PageBundle\Request\SiteRequest::createFromGlobals() but got another error: An exception has been thrown during the rendering of a template (“You must configure runtime on your composer.json in order to use “Host path” strategy, take a look on page bundle multiside doc.”). on line {{ render(controller('App\\Controller\\NotificationController::detail')) }} in twig template.

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 1
  • Comments: 16 (11 by maintainers)

Most upvoted comments

I was only temporary error. After updating snapshot it works. But it should be in documentation.

<?php

use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return static function (): Kernel {
    if ($_SERVER['APP_DEBUG']) {
        umask(0000);

        Debug::enable();
    }
    if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
        Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
    }

    if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
        Request::setTrustedHosts([$trustedHosts]);
    }
    return new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
};

I don’t get it. Updating snapshot is not related to the runtime, it’s a regular process of page if you change something with the paths. Of course if you go from one type to another it should be a part of your migration to update snapshots not related to this specific file. @eerison ?

Well it is a comment from @mesiarm, I guess there is some miss understanding here.

it wasn’t provided an issue with steps to reproduce. and yeah snapshot isn’t related with runtime, I suspect it was just some cache that should be clean up.

and why I am saying it isn’t related with sonata? because his old and current solution just uses symfony’s code, nothing from sonata.

the steps provided to reproduce are not reproducible for others, because you and @haivala migrated to symfony runtime and none of you faced this issue.

if it contains issue: it MUST have clear steps what need to do, otherwise it won’t be fixed!

You must install symfony/runtime and makes changes to your index.php according to it: https://symfony.com/doc/current/components/runtime.html after that the page runtime has to be defined in your composer.json.