Глобальный сервис в Symfony 4

 

namespace App\Events;

use App\Kernel;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class StaticServiceRequestListener
{
	
	private $container;
	
	public function __construct( ContainerInterface $container )
	{
		$this->container = $container;
	}
	
	public function onKernelRequest(GetResponseEvent $event){
		if( !Kernel::$staticServices){
			Kernel::$staticServices = $this->container;
		}
	}
}

config/services.yml

services:
    # ...
    App\Events\StaticServiceRequestListener:
        tags:
            - { name: kernel.event_listener, event: kernel.request }
namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
	
	/**
	 * @var ContainerInterface
	 */
    public static $staticServices;

   /** ..// */
    public static function service(string $id){
    	return static::$staticServices->get($id);
    }
}

 

Решение мелких проблем в Symfony блог ч1
Советую почитать