Skip to content

Commit fe4a437

Browse files
committed
model: renamed clearIdentityMpaAndCaches() to clear() (BC break!)
1 parent db32440 commit fe4a437

12 files changed

Lines changed: 27 additions & 51 deletions

src/Model/IModel.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
interface IModel
1616
{
17-
/** @const use as an argument when needed */
18-
const I_KNOW_WHAT_I_AM_DOING = 'i_know_what_i_am_doing';
19-
20-
2117
/**
2218
* Returns true if repository with name is attached to model.
2319
*/
@@ -81,16 +77,13 @@ public function persistAndFlush(IEntity $entity): IEntity;
8177

8278

8379
/**
84-
* USE ONLY IF YOU ARE SURE YOU KNOW WHAT ARE YOU DOING.
8580
* Clears repository identity map and other possible caches.
8681
* Make sure that all references to already used entites are released,
8782
* this makes possible to free the memory for garbage collector.
8883
* Orm will not allow you to work with these entities anymore.
89-
* @dangerous
90-
* @internal
91-
* @ignore
84+
* @return void
9285
*/
93-
public function clearIdentityMapAndCaches($areYouSure);
86+
public function clear();
9487

9588

9689
/**

src/Model/Model.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Nette\Object;
1212
use Nextras\Orm\Entity\IEntity;
1313
use Nextras\Orm\InvalidArgumentException;
14-
use Nextras\Orm\LogicException;
1514
use Nextras\Orm\Relationships\IRelationshipCollection;
1615
use Nextras\Orm\Repository\IRepository;
1716
use Nextras\Orm\Repository\PersistenceHelper;
@@ -167,14 +166,11 @@ public function persistAndFlush(IEntity $entity): IEntity
167166
}
168167

169168

170-
public function clearIdentityMapAndCaches($areYouSure)
169+
/** @inheritdoc */
170+
public function clear()
171171
{
172-
if ($areYouSure !== self::I_KNOW_WHAT_I_AM_DOING) {
173-
throw new LogicException('Use this method only if you are sure what are you doing.');
174-
}
175-
176172
foreach ($this->getLoadedRepositories() as $repository) {
177-
$repository->doClearIdentityMap($areYouSure);
173+
$repository->doClear();
178174
}
179175
}
180176

src/Repository/IRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function doFlush();
164164
* @internal
165165
* @ignore
166166
*/
167-
public function doClearIdentityMap($areYouSure);
167+
public function doClear();
168168

169169

170170
/**

src/Repository/Repository.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,8 @@ public function doFlush()
327327

328328

329329
/** @inheritdoc */
330-
public function doClearIdentityMap($areYouSure = null)
330+
public function doClear()
331331
{
332-
if ($areYouSure !== IModel::I_KNOW_WHAT_I_AM_DOING) {
333-
throw new LogicException('Do not call this method directly. Use IModel::clearIdentityMapAndCaches().');
334-
}
335-
336332
$this->identityMap->destroyAllEntities();
337333
$this->mapper->clearCache();
338334
}

tests/cases/acceptance/MemoryManagementTest.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace NextrasTests\Orm\Collection;
44

5-
use Mockery;
6-
use Nextras\Orm\Model\IModel;
75
use NextrasTests\Orm\Author;
86
use NextrasTests\Orm\TestCase;
97
use Tester\Assert;
108
use Tester\Environment;
119

10+
1211
$dic = require_once __DIR__ . '/../../bootstrap.php';
1312

1413

@@ -34,13 +33,13 @@ class MemoryManagementTest extends TestCase
3433
}
3534

3635
$this->persistEntity();
37-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
36+
$this->orm->clear();
3837

3938
$baseline = memory_get_usage(false);
4039

4140
for ($i = 0; $i < 200; ++$i) {
4241
$this->persistEntity();
43-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
42+
$this->orm->clear();
4443
gc_collect_cycles();
4544

4645
$ratio = memory_get_usage(false) / $baseline;

tests/cases/integration/Entity/entity.defaultValue.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace NextrasTests\Orm\Integration\Entity;
88

99
use DateTimeImmutable;
10-
use Nextras\Orm\Model\IModel;
1110
use NextrasTests\Orm\Author;
1211
use NextrasTests\Orm\TestCase;
1312
use Tester\Assert;
@@ -97,7 +96,7 @@ class EntityDefaultValueTest extends TestCase
9796
$id = $author->getPersistedId();
9897

9998

100-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
99+
$this->orm->clear();
101100

102101
$author = $this->orm->authors->getById($id);
103102
Assert::null($author->born);

tests/cases/integration/Mapper/storageReflection.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
namespace NextrasTests\Orm\Integration\Mapper;
99

10-
use Mockery;
11-
use Nextras\Orm\Model\IModel;
1210
use NextrasTests\Orm\Author;
1311
use NextrasTests\Orm\Book;
1412
use NextrasTests\Orm\DataTestCase;
1513
use NextrasTests\Orm\Publisher;
1614
use Tester\Assert;
1715

16+
1817
$dic = require_once __DIR__ . '/../../../bootstrap.php';
1918

2019

@@ -36,7 +35,7 @@ class StorageReflectionTest extends DataTestCase
3635

3736
$this->orm->books->persistAndFlush($bookA);
3837
$id = $bookA->getPersistedId();
39-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
38+
$this->orm->clear();
4039

4140
$bookB = $this->orm->books->getById($id);
4241
Assert::same('2015-09-09T10:10:10+02:00', $bookB->publishedAt->format('c'));

tests/cases/integration/Model/model.clearIdentityMapAndCaches().phpt renamed to tests/cases/integration/Model/model.clear().phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77

88
namespace NextrasTests\Orm\Integration\Model;
99

10-
use Mockery;
11-
use Nextras\Orm\Model\IModel;
1210
use NextrasTests\Orm\DataTestCase;
1311
use Tester\Assert;
1412

13+
1514
$dic = require_once __DIR__ . '/../../../bootstrap.php';
1615

1716

18-
class ModelClearIdentityMapAndCachesTest extends DataTestCase
17+
class ModelClearTest extends DataTestCase
1918
{
2019

2120
public function testBasics()
@@ -27,7 +26,7 @@ class ModelClearIdentityMapAndCachesTest extends DataTestCase
2726

2827
Assert::equal($book1, $book2);
2928

30-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
29+
$this->orm->clear();
3130

3231
$book3 = $this->orm->books->getById(1);
3332
Assert::notEqual($book1, $book3);
@@ -47,7 +46,7 @@ class ModelClearIdentityMapAndCachesTest extends DataTestCase
4746
$memory1 = memory_get_usage();
4847
4948
unset($books, $book);
50-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
49+
$this->orm->clear();
5150
5251
5352
$books = $this->orm->books->findAll();
@@ -62,5 +61,5 @@ class ModelClearIdentityMapAndCachesTest extends DataTestCase
6261
}
6362

6463

65-
$test = new ModelClearIdentityMapAndCachesTest($dic);
64+
$test = new ModelClearTest($dic);
6665
$test->run();

tests/cases/integration/Relationships/relationships.manyHasMany.collection.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace NextrasTests\Orm\Integration\Relationships;
99

10-
use Nextras\Orm\Model\IModel;
1110
use Nextras\Orm\Relationships\ManyHasMany;
1211
use NextrasTests\Orm\Book;
1312
use NextrasTests\Orm\DataTestCase;
@@ -31,7 +30,7 @@ class RelationshipsManyHasManyCollectionTest extends DataTestCase
3130
{
3231
parent::setUp();
3332

34-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
33+
$this->orm->clear();
3534
$this->book = $this->orm->books->getById(1);
3635
$this->tags = $this->book->tags;
3736
}

tests/cases/integration/Relationships/relationships.oneHasMany.collection.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace NextrasTests\Orm\Integration\Relationships;
99

10-
use Nextras\Orm\Model\IModel;
1110
use Nextras\Orm\Relationships\OneHasMany;
1211
use NextrasTests\Orm\Author;
1312
use NextrasTests\Orm\Book;
@@ -16,6 +15,7 @@ use NextrasTests\Orm\Helper;
1615
use NextrasTests\Orm\Publisher;
1716
use Tester\Assert;
1817

18+
1919
$dic = require_once __DIR__ . '/../../../bootstrap.php';
2020

2121

@@ -39,7 +39,7 @@ class RelationshipsOneHasManyCollectionTest extends DataTestCase
3939
{
4040
parent::setUp();
4141

42-
$this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING);
42+
$this->orm->clear();
4343
$this->publisher = $this->orm->publishers->getById(1);
4444
$this->authorA = $this->orm->authors->getById(1);
4545
$this->authorB = $this->orm->authors->getById(2);

0 commit comments

Comments
 (0)