Completed
Push — master ( 99354c...eb08eb )
by
unknown
11s
created

Registry.php (1 issue)

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 Symfony\Component\DependencyInjection\ContainerAwareTrait;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Bridge\Doctrine\RegistryInterface;
8
use Symfony\Bridge\Doctrine\ManagerRegistry;
9
use Doctrine\ORM\ORMException;
10
use Doctrine\ORM\EntityManager;
11
12
/**
13
 * References all Doctrine connections and entity managers in a given Container.
14
 *
15
 * @author Fabien Potencier <[email protected]>
16
 */
17
class Registry extends ManagerRegistry implements RegistryInterface
18
{
19
    /**
20
     * Construct.
21
     *
22
     * @param ContainerInterface $container
23
     * @param array              $connections
24
     * @param array              $entityManagers
25
     * @param string             $defaultConnection
26
     * @param string             $defaultEntityManager
27
     */
28
    public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
29
    {
30
        $parentTraits = class_uses(parent::class);
31
        if (isset($parentTraits[ContainerAwareTrait::class])) {
32
            // this case should be removed when Symfony 3.4 becomes the lowest supported version
33
            // and then also, the constructor should type-hint Psr\Container\ContainerInterface
34
            $this->setContainer($container);
35
        } else {
36
            $this->container = $container;
37
        }
38
39
        parent::__construct('ORM', $connections, $entityManagers, $defaultConnection, $defaultEntityManager, 'Doctrine\ORM\Proxy\Proxy');
40
    }
41
42
    /**
43
     * Gets the default entity manager name.
44
     *
45
     * @return string The default entity manager name
46
     *
47
     * @deprecated
48
     */
49
    public function getDefaultEntityManagerName()
50
    {
51
        @trigger_error('getDefaultEntityManagerName is deprecated since Symfony 2.1. Use getDefaultManagerName instead', E_USER_DEPRECATED);
52
53
        return $this->getDefaultManagerName();
54
    }
55
56
    /**
57
     * Gets a named entity manager.
58
     *
59
     * @param string $name The entity manager name (null for the default one)
60
     *
61
     * @return EntityManager
62
     *
63
     * @deprecated
64
     */
65
    public function getEntityManager($name = null)
66
    {
67
        @trigger_error('getEntityManager is deprecated since Symfony 2.1. Use getManager instead', E_USER_DEPRECATED);
68
69
        return $this->getManager($name);
70
    }
71
72
    /**
73
     * Gets an array of all registered entity managers
74
     *
75
     * @return EntityManager[] an array of all EntityManager instances
76
     *
77
     * @deprecated
78
     */
79
    public function getEntityManagers()
80
    {
81
        @trigger_error('getEntityManagers is deprecated since Symfony 2.1. Use getManagers instead', E_USER_DEPRECATED);
82
83
        return $this->getManagers();
84
    }
85
86
    /**
87
     * Resets a named entity manager.
88
     *
89
     * This method is useful when an entity manager has been closed
90
     * because of a rollbacked transaction AND when you think that
91
     * it makes sense to get a new one to replace the closed one.
92
     *
93
     * Be warned that you will get a brand new entity manager as
94
     * the existing one is not usable anymore. This means that any
95
     * other object with a dependency on this entity manager will
96
     * hold an obsolete reference. You can inject the registry instead
97
     * to avoid this problem.
98
     *
99
     * @param string $name The entity manager name (null for the default one)
100
     *
101
     * @return EntityManager
0 ignored issues
show
Should the return type not be EntityManager|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
102
     *
103
     * @deprecated
104
     */
105
    public function resetEntityManager($name = null)
106
    {
107
        @trigger_error('resetEntityManager is deprecated since Symfony 2.1. Use resetManager instead', E_USER_DEPRECATED);
108
109
        $this->resetManager($name);
110
    }
111
112
    /**
113
     * Resolves a registered namespace alias to the full namespace.
114
     *
115
     * This method looks for the alias in all registered entity managers.
116
     *
117
     * @param string $alias The alias
118
     *
119
     * @return string The full namespace
120
     *
121
     * @deprecated
122
     */
123
    public function getEntityNamespace($alias)
124
    {
125
        @trigger_error('getEntityNamespace is deprecated since Symfony 2.1. Use getAliasNamespace instead', E_USER_DEPRECATED);
126
127
        return $this->getAliasNamespace($alias);
128
    }
129
130
    /**
131
     * Resolves a registered namespace alias to the full namespace.
132
     *
133
     * This method looks for the alias in all registered entity managers.
134
     *
135
     * @param string $alias The alias
136
     *
137
     * @return string The full namespace
138
     *
139
     * @see Configuration::getEntityNamespace
140
     */
141
    public function getAliasNamespace($alias)
142
    {
143
        foreach (array_keys($this->getManagers()) as $name) {
144
            try {
145
                return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
146
            } catch (ORMException $e) {
147
            }
148
        }
149
150
        throw ORMException::unknownEntityNamespace($alias);
151
    }
152
153
    /**
154
     * Gets all connection names.
155
     *
156
     * @return array An array of connection names
157
     *
158
     * @deprecated
159
     */
160
    public function getEntityManagerNames()
161
    {
162
        @trigger_error('getEntityManagerNames is deprecated since Symfony 2.1. Use getManagerNames instead', E_USER_DEPRECATED);
163
164
        return $this->getManagerNames();
165
    }
166
167
    /**
168
     * Gets the entity manager associated with a given class.
169
     *
170
     * @param string $class A Doctrine Entity class name
171
     *
172
     * @return EntityManager|null
173
     *
174
     * @deprecated
175
     */
176
    public function getEntityManagerForClass($class)
177
    {
178
        @trigger_error('getEntityManagerForClass is deprecated since Symfony 2.1. Use getManagerForClass instead', E_USER_DEPRECATED);
179
180
        return $this->getManagerForClass($class);
181
    }
182
}
183