Skip to content

Commit 901535c

Browse files
committed
Deprecate the get() and has() shortcuts of AbstractController
1 parent 8c54c21 commit 901535c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

best_practices.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ Use Dependency Injection to Get Services
244244

245245
If you extend the base ``AbstractController``, you can only access to the most
246246
common services (e.g ``twig``, ``router``, ``doctrine``, etc.), directly from the
247-
container via ``$this->container->get()`` or ``$this->get()``.
247+
container via ``$this->container->get()``.
248248
Instead, you must use dependency injection to fetch services by
249249
:ref:`type-hinting action method arguments <controller-accessing-services>` or
250250
constructor arguments.

forms.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,15 @@ method::
857857

858858
use App\Form\TaskType;
859859
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
860+
use Symfony\Component\Form\FormFactoryInterface;
860861
// ...
861862

862863
class TaskController extends AbstractController
863864
{
864-
public function new(): Response
865+
public function new(FormFactoryInterface $formFactory): Response
865866
{
866867
$task = ...;
867-
$form = $this->get('form.factory')->createNamed('my_name', TaskType::class, $task);
868+
$form = $formFactory->createNamed('my_name', TaskType::class, $task);
868869

869870
// ...
870871
}

0 commit comments

Comments
 (0)