22
33namespace Tetranz \Select2EntityBundle \Service ;
44
5+ use Doctrine \Common \Persistence \ManagerRegistry ;
56use Doctrine \ORM \EntityRepository ;
6- use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
7- use Symfony \Component \DependencyInjection \ContainerAwareTrait ;
8- use Symfony \Component \DependencyInjection \ContainerInterface ;
7+ use Symfony \Component \Form \FormFactoryInterface ;
98use Symfony \Component \Form \FormTypeInterface ;
109use Symfony \Component \HttpFoundation \Request ;
1110use Symfony \Component \PropertyAccess \PropertyAccess ;
1211
13- class AutocompleteService implements ContainerAwareInterface
12+ class AutocompleteService
1413{
15- use ContainerAwareTrait;
14+ /**
15+ * @var FormFactoryInterface
16+ */
17+ private $ formFactory ;
1618
19+ /**
20+ * @var ManagerRegistry
21+ */
22+ private $ doctrine ;
1723
18- public function __construct (ContainerInterface $ container )
24+ /**
25+ * @param FormFactoryInterface $formFactory
26+ * @param ManagerRegistry $doctrine
27+ */
28+ public function __construct (FormFactoryInterface $ formFactory , ManagerRegistry $ doctrine )
1929 {
20- $ this ->setContainer ($ container );
21- }
30+ $ this ->formFactory = $ formFactory ;
31+ $ this ->doctrine = $ doctrine ;
32+ }
2233
2334 /**
2435 * @param Request $request
@@ -28,11 +39,11 @@ public function __construct(ContainerInterface $container)
2839 */
2940 public function getAutocompleteResults (Request $ request , $ type )
3041 {
31- $ form = $ this ->container -> get ( ' form.factory ' ) ->create ($ type );
42+ $ form = $ this ->formFactory ->create ($ type );
3243 $ fieldOptions = $ form ->get ($ request ->get ('field_name ' ))->getConfig ()->getOptions ();
3344
3445 /** @var EntityRepository $repo */
35- $ repo = $ this ->container -> get ( ' doctrine ' ) ->getRepository ($ fieldOptions ['class ' ]);
46+ $ repo = $ this ->doctrine ->getRepository ($ fieldOptions ['class ' ]);
3647
3748 $ term = $ request ->get ('q ' );
3849
@@ -54,7 +65,6 @@ public function getAutocompleteResults(Request $request, $type)
5465 ->setFirstResult ($ offset )
5566 ;
5667
57-
5868 if (array_key_exists ('callback ' , $ fieldOptions )) {
5969 $ cb = $ fieldOptions ['callback ' ];
6070
@@ -75,4 +85,4 @@ public function getAutocompleteResults(Request $request, $type)
7585
7686 return $ result ;
7787 }
78- }
88+ }
0 commit comments