Skip to content

Commit

Permalink
Merge pull request #16633 from cakephp/issue-16419
Browse files Browse the repository at this point in the history
Ensure TableLocator returns the same instance when using a table's registry alias.
This improves behavior when entities have namespaced classnames as their registry value.
  • Loading branch information
markstory committed Jul 17, 2022
2 parents 24de81a + 17f6e0d commit 92bf43c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/ORM/Locator/TableLocator.php
Expand Up @@ -215,8 +215,6 @@ protected function createInstance(string $alias, array $options)
$options = ['alias' => $classAlias] + $options;
} elseif (!isset($options['alias'])) {
$options['className'] = $alias;
/** @psalm-suppress PossiblyFalseOperand */
$alias = substr($alias, strrpos($alias, '\\') + 1, -5);
}

if (isset($this->_config[$alias])) {
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/ORM/Locator/TableLocatorTest.php
Expand Up @@ -178,6 +178,10 @@ public function testGet(): void

$result = $this->_locator->get(ArticlesTable::class);
$this->assertSame('Articles', $result->getAlias());
$this->assertSame(ArticlesTable::class, $result->getRegistryAlias());

$result2 = $this->_locator->get($result->getRegistryAlias());
$this->assertSame($result, $result2);
}

/**
Expand Down

0 comments on commit 92bf43c

Please sign in to comment.