Completed
Pull Request — master (#873)
by Marco
09:46
created

Registry.php (11 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
     * Construct.
21
     *
22
     * @param Connection[]             $connections
23
     * @param EntityManagerInterface[] $entityManagers
24
     * @param string                   $defaultConnection
25
     * @param string                   $defaultEntityManager
26
     */
27
    public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
28
    {
29
        $parentTraits = class_uses(parent::class);
30
        if (isset($parentTraits[ContainerAwareTrait::class])) {
31
            // this case should be removed when Symfony 3.4 becomes the lowest supported version
32
            // and then also, the constructor should type-hint Psr\Container\ContainerInterface
33
            $this->setContainer($container);
34
        } else {
35
            $this->container = $container;
36
        }
37
38
        parent::__construct('ORM', $connections, $entityManagers, $defaultConnection, $defaultEntityManager, 'Doctrine\ORM\Proxy\Proxy');
39
    }
40
41
    /**
42
     * Gets the default entity manager name.
43
     *
44
     * @deprecated
45
     *
46
     * @return string The default entity manager name
47
     */
48
    public function getDefaultEntityManagerName()
49
    {
50
        @trigger_error('getDefaultEntityManagerName is deprecated since Symfony 2.1. Use getDefaultManagerName instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
51
52
        return $this->getDefaultManagerName();
53
    }
54
55
    /**
56
     * Gets a named entity manager.
57
     *
58
     * @deprecated
59
     *
60
     * @param string $name The entity manager name (null for the default one)
0 ignored issues
show
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
61
     *
62
     * @return EntityManager
63
     */
64
    public function getEntityManager($name = null)
65
    {
66
        @trigger_error('getEntityManager is deprecated since Symfony 2.1. Use getManager instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
67
68
        return $this->getManager($name);
69
    }
70
71
    /**
72
     * Gets an array of all registered entity managers
73
     *
74
     * @deprecated
75
     *
76
     * @return EntityManager[] an array of all EntityManager instances
77
     */
78
    public function getEntityManagers()
79
    {
80
        @trigger_error('getEntityManagers is deprecated since Symfony 2.1. Use getManagers instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
81
82
        return $this->getManagers();
83
    }
84
85
    /**
86
     * Resets a named entity manager.
87
     *
88
     * This method is useful when an entity manager has been closed
89
     * because of a rollbacked transaction AND when you think that
90
     * it makes sense to get a new one to replace the closed one.
91
     *
92
     * Be warned that you will get a brand new entity manager as
93
     * the existing one is not usable anymore. This means that any
94
     * other object with a dependency on this entity manager will
95
     * hold an obsolete reference. You can inject the registry instead
96
     * to avoid this problem.
97
     *
98
     * @deprecated
99
     *
100
     * @param string $name The entity manager name (null for the default one)
0 ignored issues
show
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
101
     */
102
    public function resetEntityManager($name = null)
103
    {
104
        @trigger_error('resetEntityManager is deprecated since Symfony 2.1. Use resetManager instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
105
106
        $this->resetManager($name);
107
    }
108
109
    /**
110
     * Resolves a registered namespace alias to the full namespace.
111
     *
112
     * This method looks for the alias in all registered entity managers.
113
     *
114
     * @deprecated
115
     *
116
     * @param string $alias The alias
117
     *
118
     * @return string The full namespace
119
     */
120
    public function getEntityNamespace($alias)
121
    {
122
        @trigger_error('getEntityNamespace is deprecated since Symfony 2.1. Use getAliasNamespace instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
123
124
        return $this->getAliasNamespace($alias);
125
    }
126
127
    /**
128
     * Resolves a registered namespace alias to the full namespace.
129
     *
130
     * This method looks for the alias in all registered entity managers.
131
     *
132
     * @see Configuration::getEntityNamespace
133
     *
134
     * @param string $alias The alias
135
     *
136
     * @return string The full namespace
137
     */
138
    public function getAliasNamespace($alias)
139
    {
140
        foreach (array_keys($this->getManagers()) as $name) {
141
            try {
142
                return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
143
            } catch (ORMException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
The class Doctrine\ORM\ORMException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
144
            }
145
        }
146
147
        throw ORMException::unknownEntityNamespace($alias);
148
    }
149
150
    /**
151
     * Gets all connection names.
152
     *
153
     * @deprecated
154
     *
155
     * @return string[] An array of connection names
156
     */
157
    public function getEntityManagerNames()
158
    {
159
        @trigger_error('getEntityManagerNames is deprecated since Symfony 2.1. Use getManagerNames instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
160
161
        return $this->getManagerNames();
162
    }
163
164
    /**
165
     * Gets the entity manager associated with a given class.
166
     *
167
     * @deprecated
168
     *
169
     * @param string $class A Doctrine Entity class name
170
     *
171
     * @return EntityManager|null
172
     */
173
    public function getEntityManagerForClass($class)
174
    {
175
        @trigger_error('getEntityManagerForClass is deprecated since Symfony 2.1. Use getManagerForClass instead', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
176
177
        return $this->getManagerForClass($class);
178
    }
179
}
180