Skip to content

Commit

Permalink
* Updated logic in order to delegate validation to lower methods (set…
Browse files Browse the repository at this point in the history
… explode() limit to 2).

* Added test.
  • Loading branch information
phansys committed Feb 1, 2015
1 parent f6f0ae5 commit 7c229d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 1 addition & 4 deletions lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php
Expand Up @@ -190,10 +190,7 @@ public function getManagerForClass($class)
{
// Check for namespace alias
if (strpos($class, ':') !== false) {
if (2 < count($classNameAlias = explode(':', $class))) {
throw new \InvalidArgumentException(sprintf('Invalid classname "%s".', $class));
}
list($namespaceAlias, $simpleClassName) = $classNameAlias;
list($namespaceAlias, $simpleClassName) = explode(':', $class, 2);
$class = $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
}

Expand Down
Expand Up @@ -192,10 +192,7 @@ public function getMetadataFor($className)

// Check for namespace alias
if (strpos($className, ':') !== false) {
if (2 < count($classNameAlias = explode(':', $className))) {
throw new \InvalidArgumentException(sprintf('Invalid classname "%s".', $className));
}
list($namespaceAlias, $simpleClassName) = $classNameAlias;
list($namespaceAlias, $simpleClassName) = explode(':', $className, 2);

$realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
} else {
Expand Down Expand Up @@ -398,10 +395,7 @@ public function isTransient($class)

// Check for namespace alias
if (strpos($class, ':') !== false) {
if (2 < count($classNameAlias = explode(':', $class))) {
throw new \InvalidArgumentException(sprintf('Invalid classname "%s".', $class));
}
list($namespaceAlias, $simpleClassName) = $classNameAlias;
list($namespaceAlias, $simpleClassName) = explode(':', $class, 2);
$class = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
}

Expand Down
Expand Up @@ -84,6 +84,19 @@ public function testGetAliasedMetadata()
$this->assertTrue($this->cmf->hasMetadataFor('prefix:ChildEntity'));
}

/**
* @group DCOM-270
*/
public function testGetInvalidAliasedMetadata()
{
$this->setExpectedException(
'Doctrine\Common\Persistence\Mapping\MappingException',
'Class \'Doctrine\Tests\Common\Persistence\Mapping\ChildEntity:Foo\' does not exist'
);

$this->cmf->getMetadataFor('prefix:ChildEntity:Foo');
}

public function testWillFallbackOnNotLoadedMetadata()
{
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
Expand Down

0 comments on commit 7c229d0

Please sign in to comment.