Skip to content

Commit f872a3a

Browse files
committed
ResultIterator: Optional namespace (defaults to Dao\..\ResultIterator)
1 parent 4b8fabc commit f872a3a

6 files changed

+18
-12
lines changed

src/Configuration.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,24 @@ class Configuration implements ConfigurationInterface
8989
public function __construct(
9090
string $beanNamespace,
9191
string $daoNamespace,
92-
string $resultIteratorNamespace,
9392
Connection $connection,
9493
NamingStrategyInterface $namingStrategy = null,
9594
Cache $cache = null,
9695
SchemaAnalyzer $schemaAnalyzer = null,
9796
LoggerInterface $logger = null,
9897
array $generatorListeners = [],
9998
AnnotationParser $annotationParser = null,
100-
array $codeGeneratorListeners = []
99+
array $codeGeneratorListeners = [],
100+
string $resultIteratorNamespace = null
101101
) {
102102
$this->beanNamespace = rtrim($beanNamespace, '\\');
103103
$this->daoNamespace = rtrim($daoNamespace, '\\');
104+
if ($resultIteratorNamespace === null) {
105+
$baseNamespace = explode('\\', $this->daoNamespace);
106+
array_pop($baseNamespace);
107+
$baseNamespace[] = 'ResultIterator';
108+
$resultIteratorNamespace = implode('\\', $baseNamespace);
109+
}
104110
$this->resultIteratorNamespace = rtrim($resultIteratorNamespace, '\\');
105111
$this->connection = $connection;
106112
if ($cache !== null) {

tests/Commands/AlteredConfigurationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testAlteredConfiguration(): void
2222
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
2323
$schemaAnalyzer = $this->getMockBuilder(SchemaAnalyzer::class)->disableOriginalConstructor()->getMock();
2424

25-
$configuration = new Configuration('FooBean', 'FooDao', 'FooResultIterator', $connection, $namingStrategy, $cache, $schemaAnalyzer, $logger, []);
25+
$configuration = new Configuration('FooBean', 'FooDao', $connection, $namingStrategy, $cache, $schemaAnalyzer, $logger, [], null, [], 'FooResultIterator');
2626

2727
$alteredConfiguration = new AlteredConfiguration($configuration);
2828

tests/Performance/ManyToOneBench.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected static function getCache(): ArrayCache
149149

150150
private static function createConfiguration(): ConfigurationInterface
151151
{
152-
$configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), null, self::getCache(), null, null, []);
152+
$configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), null, self::getCache(), null, null, []);
153153
$configuration->setPathFinder(new PathFinder(null, dirname(__DIR__, 5)));
154154
return $configuration;
155155
}

tests/TDBMAbstractServiceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function getCache(): ArrayCache
142142
protected function getConfiguration() : ConfigurationInterface
143143
{
144144
if ($this->configuration === null) {
145-
$this->configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), $this->getCache(), null, null, [$this->getDummyGeneratorListener()]);
145+
$this->configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), $this->getCache(), null, null, [$this->getDummyGeneratorListener()]);
146146
$this->configuration->setPathFinder(new PathFinder(null, dirname(__DIR__, 4)));
147147
}
148148
return $this->configuration;

tests/TDBMDaoGeneratorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testDaoGeneration(): void
142142

143143
public function testGenerationException(): void
144144
{
145-
$configuration = new Configuration('UnknownVendor\\Dao', 'UnknownVendor\\Bean', 'UnknownVendor\\ResultIterator', self::getConnection(), $this->getNamingStrategy());
145+
$configuration = new Configuration('UnknownVendor\\Dao', 'UnknownVendor\\Bean', self::getConnection(), $this->getNamingStrategy());
146146

147147
$schemaManager = $this->tdbmService->getConnection()->getSchemaManager();
148148
$schemaAnalyzer = new SchemaAnalyzer($schemaManager);
@@ -184,7 +184,7 @@ public function testGetBeanClassName(): void
184184
$this->assertEquals(UserBean::class, $this->tdbmService->getBeanClassName('users'));
185185

186186
// Let's create another TDBMService to test the cache.
187-
$configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), $this->getCache(), null, null, [$this->getDummyGeneratorListener()]);
187+
$configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), $this->getCache(), null, null, [$this->getDummyGeneratorListener()]);
188188
$configuration->setPathFinder(new PathFinder(null, dirname(__DIR__, 4)));
189189
$newTdbmService = new TDBMService($configuration);
190190
$this->assertEquals(UserBean::class, $newTdbmService->getBeanClassName('users'));

tests/TDBMServiceTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ public function testFindObjectsFromSqlHierarchyUp(): void
783783
public function testLogger(): void
784784
{
785785
$arrayLogger = new ArrayLogger();
786-
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), null, null, $arrayLogger));
786+
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), null, null, $arrayLogger));
787787

788788
$tdbmService->setLogLevel(LogLevel::DEBUG);
789789
$beans = $tdbmService->findObjects('contact', null, [], 'contact.id ASC', [], null, TDBMObject::class);
@@ -808,7 +808,7 @@ public function testFindObjectsFromSqlCountWithOneToManyLink(): void
808808

809809
public function testBuildFilterFromFilterBagIterator(): void
810810
{
811-
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
811+
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
812812

813813
[$sql, $parameters, $counter] = $tdbmService->buildFilterFromFilterBag(new \ArrayIterator(['id' => 1]), self::getConnection()->getDatabasePlatform());
814814
$this->assertRegExp('/\(.id. = :tdbmparam1\)/', $sql);
@@ -819,7 +819,7 @@ public function testFindObjectsMethodWithoutResultIteratorClass(): void
819819
{
820820
$this->expectException(TDBMInvalidArgumentException::class);
821821
$this->expectExceptionMessageRegExp('/^\$resultIteratorClass should be a `' . preg_quote(ResultIterator::class, '/') . '`. `(.*)` provided\.$/');
822-
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
822+
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
823823

824824
$tdbmService->findObjects('', null, [], null, [], null, null, self::class);
825825
}
@@ -828,7 +828,7 @@ public function testFindObjectsFromSqlMethodWithoutResultIteratorClass(): void
828828
{
829829
$this->expectException(TDBMInvalidArgumentException::class);
830830
$this->expectExceptionMessageRegExp('/^\$resultIteratorClass should be a `' . preg_quote(ResultIterator::class, '/') . '`. `(.*)` provided\.$/');
831-
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
831+
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
832832

833833
$tdbmService->findObjectsFromSql('', '', null, [], null, null, null, self::class);
834834
}
@@ -837,7 +837,7 @@ public function testFindObjectsFromRawSqlMethodWithoutResultIteratorClass(): voi
837837
{
838838
$this->expectException(TDBMInvalidArgumentException::class);
839839
$this->expectExceptionMessageRegExp('/^\$resultIteratorClass should be a `' . preg_quote(ResultIterator::class, '/') . '`. `(.*)` provided\.$/');
840-
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', 'TheCodingMachine\\TDBM\\Test\\ResultIterator', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
840+
$tdbmService = new TDBMService(new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), null, null, new NullLogger()));
841841

842842
$tdbmService->findObjectsFromRawSql('', '', [], null, null, null, self::class);
843843
}

0 commit comments

Comments
 (0)