Skip to content

Commit 549ce87

Browse files
author
Marco Bunge
committed
Fix typo
1 parent 3500100 commit 549ce87

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/AbstractMapper.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ abstract class AbstractMapper implements Mapper
3737
*/
3838
protected $primaryKey;
3939

40+
/**
41+
* @var string
42+
*/
43+
protected $autoIncrementKey;
44+
4045
/**
4146
* @var Column[]
4247
*/
@@ -47,11 +52,6 @@ abstract class AbstractMapper implements Mapper
4752
*/
4853
private $hydrator;
4954

50-
/**
51-
* @var string
52-
*/
53-
protected $lastInsertIdReference;
54-
5555
/**
5656
* @var IdentityMap
5757
*/
@@ -157,9 +157,9 @@ final public function getPrimaryKey()
157157
/**
158158
* @return string
159159
*/
160-
final public function getLastInsertIdReference()
160+
final public function getAutoIncrementKey()
161161
{
162-
return $this->lastInsertIdReference;
162+
return $this->autoIncrementKey;
163163
}
164164

165165
/**
@@ -240,9 +240,9 @@ public function isNew($dataOrEntity)
240240
public function find($primaryKey = [])
241241
{
242242
// load entity from cache
243-
if(isset($primaryKey[$this->getLastInsertIdReference()])){
244-
if($this->getIdentityMap()->hasId($primaryKey[$this->getLastInsertIdReference()])){
245-
return $this->getIdentityMap()->getObject($primaryKey[$this->getLastInsertIdReference()]);
243+
if(isset($primaryKey[$this->getAutoIncrementKey()])){
244+
if($this->getIdentityMap()->hasId($primaryKey[$this->getAutoIncrementKey()])){
245+
return $this->getIdentityMap()->getObject($primaryKey[$this->getAutoIncrementKey()]);
246246
}
247247
}
248248

@@ -298,9 +298,9 @@ public function select(callable $queryCallback, $fields = ['*'], $one = false)
298298
$entity = null;
299299
// fetch entity from identity map
300300
// keeping object id
301-
if(isset($record[$this->getLastInsertIdReference()])){
302-
if($identityMap->hasId($record[$this->getLastInsertIdReference()])){
303-
$entity = $identityMap->getObject($record[$this->getLastInsertIdReference()]);
301+
if(isset($record[$this->getAutoIncrementKey()])){
302+
if($identityMap->hasId($record[$this->getAutoIncrementKey()])){
303+
$entity = $identityMap->getObject($record[$this->getAutoIncrementKey()]);
304304
}
305305
}
306306

@@ -344,7 +344,7 @@ public function delete($entity)
344344

345345
$result = $query->execute();
346346

347-
$this->getIdentityMap()->remove($data[$this->getLastInsertIdReference()], $entity);
347+
$this->getIdentityMap()->remove($data[$this->getAutoIncrementKey()], $entity);
348348

349349
return $result;
350350
}
@@ -368,12 +368,12 @@ public function create($entity)
368368
$query->execute();
369369

370370
//inject auto increment key
371-
if (null !== $this->getLastInsertIdReference()) {
372-
$data[$this->getLastInsertIdReference()] = $this->connection->lastInsertId();
371+
if (null !== $this->getAutoIncrementKey()) {
372+
$data[$this->getAutoIncrementKey()] = $this->connection->lastInsertId();
373373
$entity = $this->map($data, $entity);
374374

375375
// add identity
376-
$this->getIdentityMap()->set($data[$this->getLastInsertIdReference()], $entity);
376+
$this->getIdentityMap()->set($data[$this->getAutoIncrementKey()], $entity);
377377
}
378378

379379
return $entity;
@@ -414,7 +414,7 @@ public function update($entity)
414414
$query->execute();
415415

416416
// update identity
417-
$this->getIdentityMap()->set($data[$this->getLastInsertIdReference()], $entity);
417+
$this->getIdentityMap()->set($data[$this->getAutoIncrementKey()], $entity);
418418

419419
// we don't need to update entity data
420420
return $entity;
@@ -530,8 +530,8 @@ private function doDefine()
530530
reset($primaryKey);
531531

532532
// sanitize and validate last insert id reference which is a subset of primary key
533-
if (0 < count($this->primaryKey) && null === $this->lastInsertIdReference) {
534-
$this->lastInsertIdReference = current($primaryKey);
533+
if (0 < count($this->primaryKey) && null === $this->autoIncrementKey) {
534+
$this->autoIncrementKey = current($primaryKey);
535535
}
536536

537537
//sanitize and validate columns

src/Mapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getColumns();
5454
/**
5555
* @return string
5656
*/
57-
public function getLastInsertIdReference();
57+
public function getAutoIncrementKey();
5858

5959
/**
6060
* @return Gateway

src/UnitOfWork.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public function update($object)
117117
$mapper = $this->connection->loadMapper($object);
118118
$data = $mapper->getHydrator()->extract($object);
119119

120-
if (isset($data[$mapper->getLastInsertIdReference()])) {
121-
$mapper->getIdentityMap()->set($data[$mapper->getLastInsertIdReference()], $object);
120+
if (isset($data[$mapper->getAutoIncrementKey()])) {
121+
$mapper->getIdentityMap()->set($data[$mapper->getAutoIncrementKey()], $object);
122122
}
123123

124124
$this->updatedObjects[spl_object_hash($object)] = $object;
@@ -161,8 +161,8 @@ public function delete($object)
161161
$mapper = $this->connection->loadMapper($object);
162162
$data = $mapper->getHydrator()->extract($object);
163163

164-
if (isset($data[$mapper->getLastInsertIdReference()])) {
165-
$mapper->getIdentityMap()->remove($data[$mapper->getLastInsertIdReference()], $object);
164+
if (isset($data[$mapper->getAutoIncrementKey()])) {
165+
$mapper->getIdentityMap()->remove($data[$mapper->getAutoIncrementKey()], $object);
166166
}
167167

168168
$this->deletedObjects[spl_object_hash($object)] = $object;

tests/IntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testMapperIntegration()
6060
$this->assertEquals('post', $mapper->getTableName());
6161
$this->assertArrayHasKey('id', $mapper->getColumns());
6262
$this->assertArrayHasKey('content', $mapper->getColumns());
63-
$this->assertEquals('id', $mapper->getLastInsertIdReference());
63+
$this->assertEquals('id', $mapper->getAutoIncrementKey());
6464

6565
$entity->setContent('cnt');
6666
$this->assertEquals(null, $entity->getId());

0 commit comments

Comments
 (0)