Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Namespace move BC compatibility layer #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "lib/Doctrine/Common"
"Doctrine\\Common\\": "lib/Doctrine/Common",
"Doctrine\\Persistence\\": "lib/Doctrine/Persistence"
}
},
"autoload-dev": {
Expand Down
37 changes: 24 additions & 13 deletions 37 lib/Doctrine/Common/NotifyPropertyChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

namespace Doctrine\Common;

/**
* Interface for classes that notify event listeners of changes to their managed properties.
*
* This interface is implemented by objects that manually want to notify their object manager or
* other listeners when properties change, instead of relying on the object manager to compute
* property changes itself when changes are to be persisted.
*/
interface NotifyPropertyChanged
{
use const E_USER_DEPRECATED;
use function class_alias;
use function interface_exists;
use function sprintf;
use function trigger_error;

if (! interface_exists(\Doctrine\Persistence\NotifyPropertyChanged::class, false)) {
@trigger_error(sprintf(
'The %s\NotifyPropertyChanged class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0.'
. ' Use \Doctrine\Persistence\NotifyPropertyChanged instead.',
__NAMESPACE__
), E_USER_DEPRECATED);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you ok with this or do you think line 20 should be enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the DebugClassLoader already triggers a deprecation based on the @deprecated annotation we should skip this to avoid duplicate deprecation messages. Otherwise, I definitely want to keep these in.

// cc @nicolas-grekas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That practice on Symfony is to still add all possible runtime deprecations, because using the DebugClassLoader is optional, especially when using packages standalone.

Copy link
Member

@alcaeus alcaeus Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That clears it up. Thanks Nicolas!

@greg0ire I would suggest we add this deprecation message to all deprecated classes/interfaces.


class_alias(
\Doctrine\Persistence\NotifyPropertyChanged::class,
__NAMESPACE__ . '\NotifyPropertyChanged'
);

if (false) {
/**
* Adds a listener that wants to be notified about property changes.
*
* @return void
* @deprecated 1.3 Use Doctrine\Persistence\NotifyPropertyChanged
*/
public function addPropertyChangedListener(PropertyChangedListener $listener);
interface NotifyPropertyChanged extends \Doctrine\Persistence\NotifyPropertyChanged
{
}
}
253 changes: 19 additions & 234 deletions 253 lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,245 +2,30 @@

namespace Doctrine\Common\Persistence;

use InvalidArgumentException;
use ReflectionClass;
use function explode;
use const E_USER_DEPRECATED;
use function class_alias;
use function class_exists;
use function sprintf;
use function strpos;

/**
* Abstract implementation of the ManagerRegistry contract.
*/
abstract class AbstractManagerRegistry implements ManagerRegistry
{
/** @var string */
private $name;

/** @var string[] */
private $connections;

/** @var string[] */
private $managers;

/** @var string */
private $defaultConnection;

/** @var string */
private $defaultManager;

/** @var string */
private $proxyInterfaceName;

/**
* @param string $name
* @param string[] $connections
* @param string[] $managers
* @param string $defaultConnection
* @param string $defaultManager
* @param string $proxyInterfaceName
*/
public function __construct($name, array $connections, array $managers, $defaultConnection, $defaultManager, $proxyInterfaceName)
{
$this->name = $name;
$this->connections = $connections;
$this->managers = $managers;
$this->defaultConnection = $defaultConnection;
$this->defaultManager = $defaultManager;
$this->proxyInterfaceName = $proxyInterfaceName;
}

/**
* Fetches/creates the given services.
*
* A service in this context is connection or a manager instance.
*
* @param string $name The name of the service.
*
* @return ObjectManager The instance of the given service.
*/
abstract protected function getService($name);

/**
* Resets the given services.
*
* A service in this context is connection or a manager instance.
*
* @param string $name The name of the service.
*
* @return void
*/
abstract protected function resetService($name);

/**
* Gets the name of the registry.
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* {@inheritdoc}
*/
public function getConnection($name = null)
{
if ($name === null) {
$name = $this->defaultConnection;
}

if (! isset($this->connections[$name])) {
throw new InvalidArgumentException(sprintf('Doctrine %s Connection named "%s" does not exist.', $this->name, $name));
}

return $this->getService($this->connections[$name]);
}

/**
* {@inheritdoc}
*/
public function getConnectionNames()
{
return $this->connections;
}

/**
* {@inheritdoc}
*/
public function getConnections()
{
$connections = [];
foreach ($this->connections as $name => $id) {
$connections[$name] = $this->getService($id);
}

return $connections;
}

/**
* {@inheritdoc}
*/
public function getDefaultConnectionName()
{
return $this->defaultConnection;
}

/**
* {@inheritdoc}
*/
public function getDefaultManagerName()
{
return $this->defaultManager;
}

/**
* {@inheritdoc}
*
* @throws InvalidArgumentException
*/
public function getManager($name = null)
{
if ($name === null) {
$name = $this->defaultManager;
}

if (! isset($this->managers[$name])) {
throw new InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->name, $name));
}

return $this->getService($this->managers[$name]);
}

/**
* {@inheritdoc}
*/
public function getManagerForClass($class)
{
// Check for namespace alias
if (strpos($class, ':') !== false) {
[$namespaceAlias, $simpleClassName] = explode(':', $class, 2);
$class = $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
}

$proxyClass = new ReflectionClass($class);

if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
$parentClass = $proxyClass->getParentClass();

if (! $parentClass) {
return null;
}

$class = $parentClass->getName();
}

foreach ($this->managers as $id) {
$manager = $this->getService($id);

if (! $manager->getMetadataFactory()->isTransient($class)) {
return $manager;
}
}
}

/**
* {@inheritdoc}
*/
public function getManagerNames()
{
return $this->managers;
}

/**
* {@inheritdoc}
*/
public function getManagers()
{
$dms = [];
foreach ($this->managers as $name => $id) {
$dms[$name] = $this->getService($id);
}

return $dms;
}
use function trigger_error;

if (! class_exists(\Doctrine\Persistence\AbstractManagerRegistry::class, false)) {
@trigger_error(sprintf(
'The %s\AbstractManagerRegistry class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0.'
. ' Use \Doctrine\Persistence\AbstractManagerRegistry instead.',
__NAMESPACE__
), E_USER_DEPRECATED);
}

/**
* {@inheritdoc}
*/
public function getRepository($persistentObjectName, $persistentManagerName = null)
{
return $this
->selectManager($persistentObjectName, $persistentManagerName)
->getRepository($persistentObjectName);
}
class_alias(
\Doctrine\Persistence\AbstractManagerRegistry::class,
__NAMESPACE__ . '\AbstractManagerRegistry'
);

if (false) {
/**
* {@inheritdoc}
* @deprecated 1.3 Use Doctrine\Persistence\AbstractManagerRegistry
*/
public function resetManager($name = null)
abstract class AbstractManagerRegistry extends \Doctrine\Persistence\AbstractManagerRegistry
{
if ($name === null) {
$name = $this->defaultManager;
}

if (! isset($this->managers[$name])) {
throw new InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->name, $name));
}

// force the creation of a new document manager
// if the current one is closed
$this->resetService($this->managers[$name]);

return $this->getManager($name);
}

private function selectManager(string $persistentObjectName, ?string $persistentManagerName = null) : ObjectManager
{
if ($persistentManagerName !== null) {
return $this->getManager($persistentManagerName);
}

return $this->getManagerForClass($persistentObjectName) ?? $this->getManager();
}
}
50 changes: 21 additions & 29 deletions 50 lib/Doctrine/Common/Persistence/ConnectionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,30 @@

namespace Doctrine\Common\Persistence;

/**
* Contract covering connection for a Doctrine persistence layer ManagerRegistry class to implement.
*/
interface ConnectionRegistry
{
/**
* Gets the default connection name.
*
* @return string The default connection name.
*/
public function getDefaultConnectionName();
use const E_USER_DEPRECATED;
use function class_alias;
use function interface_exists;
use function sprintf;
use function trigger_error;

/**
* Gets the named connection.
*
* @param string $name The connection name (null for the default one).
*
* @return object
*/
public function getConnection($name = null);
if (! interface_exists(\Doctrine\Persistence\ConnectionRegistry::class, false)) {
@trigger_error(sprintf(
'The %s\ConnectionRegistry class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0.'
. ' Use \Doctrine\Persistence\ConnectionRegistry instead.',
__NAMESPACE__
), E_USER_DEPRECATED);
}

/**
* Gets an array of all registered connections.
*
* @return object[] An array of Connection instances.
*/
public function getConnections();
class_alias(
\Doctrine\Persistence\ConnectionRegistry::class,
__NAMESPACE__ . '\ConnectionRegistry'
);

if (false) {
/**
* Gets all connection names.
*
* @return string[] An array of connection names.
* @deprecated 1.3 Use Doctrine\Persistence\ConnectionRegistry
*/
public function getConnectionNames();
interface ConnectionRegistry extends \Doctrine\Persistence\ConnectionRegistry
{
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.