I am in the process of migrating an application from Symfony 2.8 to Symfony 3.4
The services are now private and therefore instead of making a direct call to the services from the container, we must use dependency injection as a workaround.
So this is the following script and i'd like to check the existence and after that call profiler service using dependency injection :
<?php
namespace DEL\Bundle\ApiBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Class EstimatePDFController
*
* @package DEL\Bundle\ApiBundle\Controller
*/
class EstimateController extends Controller
{
/**
*
* @param Request $request Request object.
*
* @return Response A Response instance
*/
public function sendAction(Request $request)
{
// disable debug env outputs
if ($this->container->has('profiler')) {
$this->container->get('profiler')->disable();
}
return new Response('OK');
}
}
As far as I know, this is not possible using autowiring. But the documentation provides an alternative:
profiler
to your controller as a propertysetProfiler(Profiler $profiler)
that sets the property$this->profiler
is null or not in yoursendAction
method