Completed
Pull Request — master (#927)
by
unknown
02:28
created

Registry.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\ORMException;
9
use Symfony\Bridge\Doctrine\ManagerRegistry;
10
use Symfony\Bridge\Doctrine\RegistryInterface;
11
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
12
use Symfony\Component\DependencyInjection\ContainerInterface;
13
14
/**
15
 * References all Doctrine connections and entity managers in a given Container.
16
 */
17
class Registry extends ManagerRegistry implements RegistryInterface
18
{
19
    /**
20
     * @param Connection[]             $connections
21
     * @param EntityManagerInterface[] $entityManagers
22
     * @param string                   $defaultConnection
23
     * @param string                   $defaultEntityManager
24
     */
25
    public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
26
    {
27
        $parentTraits = class_uses(parent::class);
28
        if (isset($parentTraits[ContainerAwareTrait::class])) {
29
            // this case should be removed when Symfony 3.4 becomes the lowest supported version
30
            // and then also, the constructor should type-hint Psr\Container\ContainerInterface
31
            $this->setContainer($container);
32
        } else {
33
            $this->container = $container;
34
        }
35
36
        parent::__construct('ORM', $connections, $entityManagers, $defaultConnection, $defaultEntityManager, 'Doctrine\ORM\Proxy\Proxy');
0 ignored issues
show
$connections is of type array<integer,object<Doctrine\DBAL\Connection>>, but the function expects a array<integer,string>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$entityManagers is of type array<integer,object<Doc...ntityManagerInterface>>, but the function expects a array<integer,string>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
37
    }
38
39
    /**
40
     * Gets the default entity manager name.
41
     *
42
     * @deprecated
43
     *
44
     * @return string The default entity manager name
45
     */
46
    public function getDefaultEntityManagerName()
47
    {
48
        @trigger_error('getDefaultEntityManagerName is deprecated since Symfony 2.1. Use getDefaultManagerName instead', E_USER_DEPRECATED);
49
50
        return $this->getDefaultManagerName();
51
    }
52
53
    /**
54
     * Gets a named entity manager.
55
     *
56
     * @deprecated
57
     *
58
     * @param string $name The entity manager name (null for the default one)
59
     *
60
     * @return EntityManager
61
     */
62
    public function getEntityManager($name = null)
63
    {
64
        @trigger_error('getEntityManager is deprecated since Symfony 2.1. Use getManager instead', E_USER_DEPRECATED);
65
66
        return $this->getManager($name);
67
    }
68
69
    /**
70
     * Gets an array of all registered entity managers
71
     *
72
     * @deprecated
73
     *
74
     * @return EntityManager[] an array of all EntityManager instances
75
     */
76
    public function getEntityManagers()
77
    {
78
        @trigger_error('getEntityManagers is deprecated since Symfony 2.1. Use getManagers instead', E_USER_DEPRECATED);
79
80
        return $this->getManagers();
81
    }
82
83
    /**
84
     * Resets a named entity manager.
85
     *
86
     * This method is useful when an entity manager has been closed
87
     * because of a rollbacked transaction AND when you think that
88
     * it makes sense to get a new one to replace the closed one.
89
     *
90
     * Be warned that you will get a brand new entity manager as
91
     * the existing one is not usable anymore. This means that any
92
     * other object with a dependency on this entity manager will
93
     * hold an obsolete reference. You can inject the registry instead
94
     * to avoid this problem.
95
     *
96
     * @deprecated
97
     *
98
     * @param string $name The entity manager name (null for the default one)
99
     */
100
    public function resetEntityManager($name = null)
101
    {
102
        @trigger_error('resetEntityManager is deprecated since Symfony 2.1. Use resetManager instead', E_USER_DEPRECATED);
103
104
        $this->resetManager($name);
105
    }
106
107
    /**
108
     * Resolves a registered namespace alias to the full namespace.
109
     *
110
     * This method looks for the alias in all registered entity managers.
111
     *
112
     * @deprecated
113
     *
114
     * @param string $alias The alias
115
     *
116
     * @return string The full namespace
117
     */
118
    public function getEntityNamespace($alias)
119
    {
120
        @trigger_error('getEntityNamespace is deprecated since Symfony 2.1. Use getAliasNamespace instead', E_USER_DEPRECATED);
121
122
        return $this->getAliasNamespace($alias);
123
    }
124
125
    /**
126
     * Resolves a registered namespace alias to the full namespace.
127
     *
128
     * This method looks for the alias in all registered entity managers.
129
     *
130
     * @see Configuration::getEntityNamespace
131
     *
132
     * @param string $alias The alias
133
     *
134
     * @return string The full namespace
135
     */
136
    public function getAliasNamespace($alias)
137
    {
138
        foreach (array_keys($this->getManagers()) as $name) {
139
            try {
140
                return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
141
            } catch (ORMException $e) {
142
            }
143
        }
144
145
        throw ORMException::unknownEntityNamespace($alias);
146
    }
147
148
    /**
149
     * Gets all connection names.
150
     *
151
     * @deprecated
152
     *
153
     * @return string[] An array of connection names
154
     */
155
    public function getEntityManagerNames()
156
    {
157
        @trigger_error('getEntityManagerNames is deprecated since Symfony 2.1. Use getManagerNames instead', E_USER_DEPRECATED);
158
159
        return $this->getManagerNames();
160
    }
161
162
    /**
163
     * Gets the entity manager associated with a given class.
164
     *
165
     * @deprecated
166
     *
167
     * @param string $class A Doctrine Entity class name
168
     *
169
     * @return EntityManager|null
170
     */
171
    public function getEntityManagerForClass($class)
172
    {
173
        @trigger_error('getEntityManagerForClass is deprecated since Symfony 2.1. Use getManagerForClass instead', E_USER_DEPRECATED);
174
175
        return $this->getManagerForClass($class);
176
    }
177
}
178