|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Knp\RadBundle\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
9
|
|
|
use Knp\RadBundle\DependencyInjection\Definition\DoctrineRepositoryFactory; |
|
10
|
|
|
use Knp\RadBundle\DependencyInjection\ServiceIdGenerator; |
|
11
|
|
|
use Knp\RadBundle\Finder\ClassFinder; |
|
12
|
|
|
|
|
13
|
|
|
class RegisterDoctrineRepositoriesPass implements CompilerPassInterface |
|
14
|
|
|
{ |
|
15
|
|
|
private $bundle; |
|
16
|
|
|
private $classFinder; |
|
17
|
|
|
private $definitionFactory; |
|
18
|
|
|
private $serviceIdGenerator; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(BundleInterface $bundle, ClassFinder $classFinder = null, DoctrineRepositoryFactory $definitionFactory = null, ServiceIdGenerator $serviceIdGenerator = null) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->bundle = $bundle; |
|
23
|
|
|
$this->classFinder = $classFinder ?: new ClassFinder; |
|
24
|
|
|
$this->definitionFactory = $definitionFactory ?: new DoctrineRepositoryFactory(); |
|
25
|
|
|
$this->serviceIdGenerator = $serviceIdGenerator ?: new ServiceIdGenerator(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function process(ContainerBuilder $container) |
|
32
|
|
|
{ |
|
33
|
|
|
if (!$container->getParameter('knp_rad.detect.entity')) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (false === $container->hasDefinition('doctrine')) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$directory = $this->bundle->getPath().'/Entity'; |
|
42
|
|
|
$namespace = $this->bundle->getNamespace().'\Entity'; |
|
43
|
|
|
|
|
44
|
|
|
$classes = $this->classFinder->findClassesMatching($directory, $namespace, '(?<!Repository)$'); |
|
45
|
|
|
foreach ($classes as $class) { |
|
46
|
|
|
if (!strpos($class, $this->bundle->getNamespace()) === 0) { |
|
47
|
|
|
continue; |
|
48
|
|
|
} |
|
49
|
|
|
$id = $this->serviceIdGenerator->generateForBundleClass($this->bundle, $class, 'repository'); |
|
|
|
|
|
|
50
|
|
|
if ($container->hasDefinition($id)) { |
|
51
|
|
|
continue; |
|
52
|
|
|
} |
|
53
|
|
|
$def = $this->definitionFactory->createDefinition($class); |
|
54
|
|
|
$container->setDefinition($id, $def); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: