Skip to content

Commit 64cb562

Browse files
committed
Deprecate inject dependency container into registry. Avoid warnings in Symfony 4+
1 parent e09530d commit 64cb562

2 files changed

Lines changed: 5 additions & 28 deletions

File tree

src/Vivait/StringGeneratorBundle/EventListener/GeneratorListener.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class GeneratorListener
2828
*/
2929
private $registry;
3030

31-
/**
32-
* @var ContainerInterface
33-
*/
34-
private $container;
35-
3631
/**
3732
* Registry has been made nullable as injecting it causes circular references. Instead, the container is injected
3833
* via a setter, and the registry is fetched from there instead.
@@ -46,14 +41,6 @@ public function __construct(Reader $reader, Registry $registry = null)
4641
$this->registry = $registry;
4742
}
4843

49-
/**
50-
* @param ContainerInterface $container
51-
*/
52-
public function setContainer(ContainerInterface $container)
53-
{
54-
$this->container = $container;
55-
}
56-
5744
/**
5845
* @param LifecycleEventArgs $args
5946
*/
@@ -92,7 +79,7 @@ public function prePersist(LifecycleEventArgs $args)
9279
private function generateString($property, GeneratorAnnotation $annotation, $entity)
9380
{
9481
/** @var GeneratorInterface|ConfigurableGeneratorInterface $generator */
95-
$generator = $this->getRegistry()->get($annotation->generator);
82+
$generator = $this->registry->get($annotation->generator);
9683

9784
$generator->setLength($annotation->length);
9885

@@ -168,15 +155,4 @@ private function isMethod($class, $callback)
168155
{
169156
return method_exists($class, $callback) && is_callable([$class, $callback]);
170157
}
171-
172-
/**
173-
* @return Registry
174-
*/
175-
private function getRegistry()
176-
{
177-
if($this->registry){
178-
return $this->registry;
179-
}
180-
return $this->container->get('vivait_generator.registry');
181-
}
182158
}

src/Vivait/StringGeneratorBundle/Resources/config/services.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ services:
22
vivait_generator.generator.listener:
33
class: Vivait\StringGeneratorBundle\EventListener\GeneratorListener
44
public: false
5-
arguments: ["@annotation_reader"]
6-
calls:
7-
- [setContainer, ["@service_container"]]
5+
arguments:
6+
- "@annotation_reader"
7+
- "@vivait_generator.registry"
8+
89
tags:
910
- { name: doctrine.event_listener, event: prePersist }
1011

0 commit comments

Comments
 (0)