Skip to content
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

orm 3.x #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ and the possiblity to install only the needed vendors make the difference to the

## Suggested

* [doctrine/dbal][20]: ^3.9.3
* [doctrine/dbal][20]: ^4.2.1
* [doctrine/mongodb-odm][21]: ^2.9.0
* [doctrine/orm][22]: ^2.20
* [doctrine/orm][22]: ^3.3
* [mongodb/mongodb][23]: ^1.20

## Installation

Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-laminas-config-doctrine][1].

```sh
composer require chubbyphp/chubbyphp-laminas-config-doctrine "^2.3"
composer require chubbyphp/chubbyphp-laminas-config-doctrine "^3.0"
```

## Usage
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": "^8.2",
"chubbyphp/chubbyphp-laminas-config-factory": "^1.3",
"doctrine/common": "^3.4.5",
"doctrine/event-manager": "^1.2|^2.0.1",
"doctrine/event-manager": "^2.0.1",
"psr/container": "^1.1.2|^2.0.2",
"symfony/cache": "^5.4.46|^6.4.14|^7.2",
"symfony/console": "^5.4.46|^6.4.14|^7.2"
Expand All @@ -34,9 +34,9 @@
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-laminas-config": "^1.4",
"chubbyphp/chubbyphp-mock": "^1.8",
"doctrine/dbal": "^3.9.3",
"doctrine/dbal": "^4.2.1",
"doctrine/mongodb-odm": "^2.9.0",
"doctrine/orm": "^2.20",
"doctrine/orm": "^3.3",
"infection/infection": "^0.29.8",
"mongodb/mongodb": "^1.20",
"php-coveralls/php-coveralls": "^2.7",
Expand All @@ -46,9 +46,9 @@
"ramsey/uuid": "^4.7.6"
},
"conflict": {
"doctrine/dbal": "<3.9.3 || >=4.0",
"doctrine/dbal": "<4.2.1 || >=5.0",
"doctrine/mongodb-odm": "<2.9.0 || >=3.0",
"doctrine/orm": "<2.20 || >=3.0",
"doctrine/orm": "<3.3 || >=4.0",
"mongodb/mongodb": "<1.20|| >=2.0"
},
"autoload": {
Expand All @@ -70,7 +70,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "3.0-dev"
}
},
"scripts": {
Expand Down
8 changes: 1 addition & 7 deletions src/ServiceFactory/DBAL/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\DBAL;

use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\Common\EventManagerFactory;
use Chubbyphp\Laminas\Config\Factory\AbstractFactory;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
Expand All @@ -19,13 +17,9 @@ public function __invoke(ContainerInterface $container): Connection
/** @var Configuration $configuration */
$configuration = $this->resolveDependency($container, Configuration::class, ConfigurationFactory::class);

/** @var EventManager $eventManager */
$eventManager = $this->resolveDependency($container, EventManager::class, EventManagerFactory::class);

return DriverManager::getConnection(
$this->resolveConfig($container->get('config')['doctrine']['dbal']['connection'] ?? []),
$configuration,
$eventManager
$configuration
);
}
}

This file was deleted.

26 changes: 3 additions & 23 deletions src/ServiceFactory/ORM/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,24 @@ public function __invoke(ContainerInterface $container): Configuration
{
$config = $this->resolveConfig($container->get('config')['doctrine']['orm']['configuration'] ?? []);

/** @var array<string, mixed> $namedQueries */
$namedQueries = $this->resolveValue($container, $config['namedQueries'] ?? []);

/** @var array<string, mixed> $namedNativeQueries */
$namedNativeQueries = $this->resolveValue($container, $config['namedNativeQueries'] ?? []);

/** @var array<string, mixed> $filters */
$filters = $this->resolveValue($container, $config['filters'] ?? []);

unset($config['namedQueries'], $config['namedNativeQueries'], $config['filters']);
unset($config['filters']);

$configuration = new Configuration();

$this->callAdders($configuration, $namedQueries, $namedNativeQueries, $filters);
$this->callAdders($configuration, $filters);
$this->callSetters($container, $configuration, $config);

return $configuration;
}

/**
* @param array<string, mixed> $namedQueries
* @param array<string, mixed> $namedNativeQueries
* @param array<string, mixed> $filters
*/
private function callAdders(Configuration $configuration, array $namedQueries, array $namedNativeQueries, array $filters): void
private function callAdders(Configuration $configuration, array $filters): void
{
foreach ($namedQueries as $namedQuery) {
$configuration->addNamedQuery($namedQuery['name'], $namedQuery['dql']);
}

foreach ($namedNativeQueries as $namedNativeQuery) {
$configuration->addNamedNativeQuery(
$namedNativeQuery['name'],
$namedNativeQuery['sql'],
$namedNativeQuery['rsm']
);
}

foreach ($filters as $filter) {
$configuration->addFilter($filter['name'], $filter['className']);
}
Expand Down
7 changes: 6 additions & 1 deletion src/ServiceFactory/ORM/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\ORM;

use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\Common\EventManagerFactory;
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\DBAL\ConnectionFactory;
use Chubbyphp\Laminas\Config\Factory\AbstractFactory;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
Expand All @@ -21,6 +23,9 @@ public function __invoke(ContainerInterface $container): EntityManager
/** @var Configuration $configuration */
$configuration = $this->resolveDependency($container, Configuration::class, ConfigurationFactory::class);

return EntityManager::create($connection, $configuration);
/** @var EventManager $eventManager */
$eventManager = $this->resolveDependency($container, EventManager::class, EventManagerFactory::class);

return new EntityManager($connection, $configuration, $eventManager);
}
}

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions tests/Integration/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ public function test(): void

$container = $factory(new Config($config));

/** @var EntityManagerInterface $entityManager */
$entityManager = $container->get(EntityManagerInterface::class);

/** @var ConnectionProvider $connectionProvider */
$connectionProvider = $container->get(ConnectionProvider::class);

Expand All @@ -102,6 +99,8 @@ public function test(): void
$sample = new Sample();
$sample->setName('name');

$entityManager = $entityManagerProvider->getDefaultManager();

$entityManager->persist($sample);
$entityManager->flush();

Expand Down
2 changes: 0 additions & 2 deletions tests/Resources/Mapping/Orm/SampleMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ final class SampleMapping implements ClassMapMappingInterface
*/
public function configureMapping(ClassMetadata $metadata): void
{
$metadata->setPrimaryTable(['name' => 'sample']);

$builder = new ClassMetadataBuilder($metadata);
$builder->setTable('sample');
$builder->createField('id', 'guid')->makePrimaryKey()->build();
Expand Down
11 changes: 0 additions & 11 deletions tests/Unit/ServiceFactory/DBAL/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\DBAL\ConnectionFactory;
use Chubbyphp\Mock\Call;
use Chubbyphp\Mock\MockByCallsTrait;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\SchemaManagerFactory;
Expand Down Expand Up @@ -35,15 +34,10 @@ public function testInvoke(): void
Call::create('getSchemaManagerFactory')->with()->willReturn($schemaManagerFactory),
]);

/** @var EventManager $eventManager */
$eventManager = $this->getMockByCalls(EventManager::class);

/** @var ContainerInterface $container */
$container = $this->getMockByCalls(ContainerInterface::class, [
Call::create('has')->with(Configuration::class)->willReturn(true),
Call::create('get')->with(Configuration::class)->willReturn($configuration),
Call::create('has')->with(EventManager::class)->willReturn(true),
Call::create('get')->with(EventManager::class)->willReturn($eventManager),
Call::create('get')->with('config')->willReturn([
'doctrine' => [
'dbal' => [
Expand Down Expand Up @@ -74,15 +68,10 @@ public function testCallStatic(): void
Call::create('getSchemaManagerFactory')->with()->willReturn($schemaManagerFactory),
]);

/** @var EventManager $eventManager */
$eventManager = $this->getMockByCalls(EventManager::class);

/** @var ContainerInterface $container */
$container = $this->getMockByCalls(ContainerInterface::class, [
Call::create('has')->with(Configuration::class.'default')->willReturn(true),
Call::create('get')->with(Configuration::class.'default')->willReturn($configuration),
Call::create('has')->with(EventManager::class.'default')->willReturn(true),
Call::create('get')->with(EventManager::class.'default')->willReturn($eventManager),
Call::create('get')->with('config')->willReturn([
'doctrine' => [
'dbal' => [
Expand Down

This file was deleted.

Loading