Skip to content

Commit

Permalink
Merge branch '2.12.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.12.x:
  Modernize strpos() calls (doctrine#9480)
  Fix types on persisters (doctrine#9466)
  Rename DoctrineSetup to ORMSetup (doctrine#9481)
  Remove useless catches
  • Loading branch information
derrabus committed Feb 7, 2022
2 parents e6f07fa + 978f687 commit 607911f
Show file tree
Hide file tree
Showing 60 changed files with 343 additions and 426 deletions.
6 changes: 3 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ the entity manager.

## Deprecate `Doctrine\ORM\Configuration::newDefaultAnnotationDriver`

This functionality has been moved to the new `DoctrineSetup` class. Call
`Doctrine\ORM\Tools\DoctrineSetup::createDefaultAnnotationDriver()` to create
This functionality has been moved to the new `ORMSetup` class. Call
`Doctrine\ORM\ORMSetup::createDefaultAnnotationDriver()` to create
a new annotation driver.

## Deprecate `Doctrine\ORM\Tools\Setup`

In our effort to migrate from Doctrine Cache to PSR-6, the `Setup` class which
accepted a Doctrine Cache instance in each method has been deprecated.

The replacement is `Doctrine\ORM\Tools\DoctrineSetup` which accepts a PSR-6
The replacement is `Doctrine\ORM\ORMSetup` which accepts a PSR-6
cache instead.

## Deprecate `Doctrine\ORM\Cache\MultiGetRegion`
Expand Down
8 changes: 4 additions & 4 deletions docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps of configuration.
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\DoctrineSetup;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
Expand All @@ -28,7 +28,7 @@ steps of configuration.
$config = new Configuration;
$config->setMetadataCache($metadataCache);
$driverImpl = DoctrineSetup::createDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$driverImpl = ORMSetup::createDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCache($queryCache);
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
Expand Down Expand Up @@ -128,9 +128,9 @@ the ``Doctrine\ORM\Configuration``:
.. code-block:: php
<?php
use Doctrine\ORM\Tools\DoctrineSetup;
use Doctrine\ORM\ORMSetup;
$driverImpl = DoctrineSetup::createDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$driverImpl = ORMSetup::createDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
The path information to the entities is required for the annotation
Expand Down
8 changes: 4 additions & 4 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ access point to ORM functionality provided by Doctrine.
// bootstrap.php
require_once "vendor/autoload.php";
use Doctrine\ORM\Tools\DoctrineSetup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
$paths = array("/path/to/entity-files");
$isDevMode = false;
Expand All @@ -55,7 +55,7 @@ access point to ORM functionality provided by Doctrine.
'dbname' => 'foo',
);
$config = DoctrineSetup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$config = ORMSetup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
Or if you prefer XML:
Expand All @@ -64,7 +64,7 @@ Or if you prefer XML:
<?php
$paths = array("/path/to/xml-mappings");
$config = DoctrineSetup::createXMLMetadataConfiguration($paths, $isDevMode);
$config = ORMSetup::createXMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
Inside the ``DoctrineSetup`` methods several assumptions are made:
Expand All @@ -76,7 +76,7 @@ Inside the ``DoctrineSetup`` methods several assumptions are made:

.. note::

In order to have ``DoctrineSetup`` configure the cache automatically, the library ``symfony/cache``
In order to have ``ORMSetup`` configure the cache automatically, the library ``symfony/cache``
has to be installed as a dependency.

If you want to configure Doctrine in more detail, take a look at the :doc:`Advanced Configuration <reference/advanced-configuration>` section.
Expand Down
8 changes: 4 additions & 4 deletions docs/en/tutorials/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ step:
<?php
// bootstrap.php
use Doctrine\ORM\Tools\DoctrineSetup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
require_once "vendor/autoload.php";
Expand All @@ -142,9 +142,9 @@ step:
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = DoctrineSetup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader);
$config = ORMSetup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader);
// or if you prefer XML
// $config = DoctrineSetup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
// $config = ORMSetup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
// database configuration parameters
$conn = array(
Expand All @@ -163,7 +163,7 @@ The ``require_once`` statement sets up the class autoloading for Doctrine and
its dependencies using Composer's autoloader.

The second block consists of the instantiation of the ORM
``Configuration`` object using the ``DoctrineSetup`` helper. It assumes a bunch
``Configuration`` object using the ``ORMSetup`` helper. It assumes a bunch
of defaults that you don't have to bother about for now. You can
read up on the configuration details in the
:doc:`reference chapter on configuration <../reference/configuration>`.
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Cache/Persister/CachedPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ interface CachedPersister
{
/**
* Perform whatever processing is encapsulated here after completion of the transaction.
*
* @return void
*/
public function afterTransactionComplete();

/**
* Perform whatever processing is encapsulated here after completion of the rolled-back.
*
* @return void
*/
public function afterTransactionRolledBack();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getTargetEntityMetadata()
}

/**
* @return object[]|null
* {@inheritdoc}
*/
public function loadCollectionCache(PersistentCollection $collection, CollectionCacheKey $key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function getTargetEntityMetadata();
/**
* Loads a collection from cache
*
* @return PersistentCollection|null
* @return mixed[]|null
*/
public function loadCollectionCache(PersistentCollection $collection, CollectionCacheKey $key);

/**
* Stores a collection into cache
*
* @param array|mixed[]|Collection $elements
* @param mixed[]|Collection $elements
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
class ReadWriteCachedCollectionPersister extends AbstractCollectionPersister
{
/**
* @param CollectionPersister $persister The collection persister that will be cached.
* @param ConcurrentRegion $region The collection region.
* @param EntityManagerInterface $em The entity manager.
* @param mixed[] $association The association mapping.
* @param mixed[] $association The association mapping.
*/
public function __construct(CollectionPersister $persister, ConcurrentRegion $region, EntityManagerInterface $em, array $association)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ private function storeJoinedAssociations($entity): void
* @param string $query
* @param string[]|Criteria $criteria
* @param string[] $orderBy
* @param int $limit
* @param int $offset
* @param int|null $limit
* @param int|null $offset
*
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
*/
class ReadWriteCachedEntityPersister extends AbstractEntityPersister
{
/**
* @param EntityPersister $persister The entity persister to cache.
* @param ConcurrentRegion $region The entity cache region.
* @param EntityManagerInterface $em The entity manager.
* @param ClassMetadata $class The entity metadata.
*/
public function __construct(EntityPersister $persister, ConcurrentRegion $region, EntityManagerInterface $em, ClassMetadata $class)
{
parent::__construct($persister, $region, $em, $class);
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function array_slice;
use function lcfirst;
use function sprintf;
use function strpos;
use function str_starts_with;
use function substr;

/**
Expand Down Expand Up @@ -178,15 +178,15 @@ public function count(array $criteria = [])
*/
public function __call($method, $arguments)
{
if (strpos($method, 'findBy') === 0) {
if (str_starts_with($method, 'findBy')) {
return $this->resolveMagicCall('findBy', substr($method, 6), $arguments);
}

if (strpos($method, 'findOneBy') === 0) {
if (str_starts_with($method, 'findOneBy')) {
return $this->resolveMagicCall('findOneBy', substr($method, 9), $arguments);
}

if (strpos($method, 'countBy') === 0) {
if (str_starts_with($method, 'countBy')) {
return $this->resolveMagicCall('count', substr($method, 7), $arguments);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
use function explode;
use function in_array;
use function is_subclass_of;
use function str_contains;
use function strlen;
use function strpos;
use function strtolower;
use function substr;

Expand Down Expand Up @@ -329,7 +329,7 @@ private function addDefaultDiscriminatorMap(ClassMetadata $class): void
*/
private function getShortName(string $className): string
{
if (strpos($className, '\\') === false) {
if (! str_contains($className, '\\')) {
return strtolower($className);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
use function ltrim;
use function method_exists;
use function spl_object_id;
use function str_contains;
use function str_replace;
use function strpos;
use function strtolower;
use function trait_exists;
use function trim;
Expand Down Expand Up @@ -2521,7 +2521,7 @@ public function setPrimaryTable(array $table)
{
if (isset($table['name'])) {
// Split schema and table name from a table name like "myschema.mytable"
if (strpos($table['name'], '.') !== false) {
if (str_contains($table['name'], '.')) {
[$this->table['schema'], $table['name']] = explode('.', $table['name'], 2);
}

Expand Down Expand Up @@ -2669,7 +2669,7 @@ public function addSqlResultSetMapping(array $resultMapping)

if (! isset($field['column'])) {
$fieldName = $field['name'];
if (strpos($fieldName, '.')) {
if (str_contains($fieldName, '.')) {
[, $fieldName] = explode('.', $fieldName);
}

Expand Down Expand Up @@ -3417,7 +3417,7 @@ public function fullyQualifiedClassName($className)
return $className;
}

if (strpos($className, '\\') === false && $this->namespace) {
if (! str_contains($className, '\\') && $this->namespace) {
return $this->namespace . '\\' . $className;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\ORM\Mapping;

use function strpos;
use function str_contains;
use function strrpos;
use function strtolower;
use function substr;
Expand All @@ -21,7 +21,7 @@ class DefaultNamingStrategy implements NamingStrategy
*/
public function classToTableName($className)
{
if (strpos($className, '\\') !== false) {
if (str_contains($className, '\\')) {
return substr($className, strrpos($className, '\\') + 1);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\Deprecations\Deprecation;

use function preg_replace;
use function strpos;
use function str_contains;
use function strrpos;
use function strtolower;
use function strtoupper;
Expand Down Expand Up @@ -79,7 +79,7 @@ public function setCase($case)
*/
public function classToTableName($className)
{
if (strpos($className, '\\') !== false) {
if (str_contains($className, '\\')) {
$className = substr($className, strrpos($className, '\\') + 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

declare(strict_types=1);

namespace Doctrine\ORM\Tools;
namespace Doctrine\ORM;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
Expand All @@ -26,7 +25,7 @@
use function sprintf;
use function sys_get_temp_dir;

final class DoctrineSetup
final class ORMSetup
{
/**
* Creates a configuration with an annotation metadata driver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function count(PersistentCollection $collection);
/**
* Slices elements.
*
* @param int $offset
* @param int $length
* @param int $offset
* @param int|null $length
*
* @return mixed[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ protected function getInsertRowSQL(PersistentCollection $collection)
*
* Internal note: Order of the parameters must be the same as the order of the columns in getInsertRowSql.
*
* @param mixed $element
* @param object $element
*
* @return mixed[]
* @psalm-return list<mixed>
Expand Down
Loading

0 comments on commit 607911f

Please sign in to comment.