Skip to content

Commit

Permalink
Move everything to a new Persistence subnamespace
Browse files Browse the repository at this point in the history
This has already been done on master, let us do it again, but with a BC
layer.
  • Loading branch information
greg0ire committed Dec 7, 2019
1 parent 43526ae commit a40e414
Show file tree
Hide file tree
Showing 82 changed files with 4,334 additions and 3,248 deletions.
3 changes: 2 additions & 1 deletion 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
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions 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);
}

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 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 object 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 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

0 comments on commit a40e414

Please sign in to comment.