Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
Support for namespace keyword in resolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Feb 22, 2014
1 parent c6a1826 commit 7b686c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/ClassName/ClassNameReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class ClassNameReference extends RelativePath implements
*/
const CLASS_NAME_PATTERN = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/';

/**
* The atom used to represent the current namespace.
*/
const NAMESPACE_ATOM = 'namespace';

/**
* Construct a new class name reference.
*
Expand Down
9 changes: 8 additions & 1 deletion src/Resolution/ClassNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Eloquent\Cosmos\Resolution;

use Eloquent\Cosmos\ClassName\ClassNameInterface;
use Eloquent\Cosmos\ClassName\ClassNameReference;
use Eloquent\Cosmos\ClassName\QualifiedClassNameInterface;
use Eloquent\Pathogen\AbsolutePathInterface;
use Eloquent\Pathogen\PathInterface;
Expand Down Expand Up @@ -101,7 +102,13 @@ public function resolveAgainstContext(
}

if ($firstAtom = $className->firstAtomShortName()) {
if ($parent = $context->classNameByShortName($firstAtom)) {
if (ClassNameReference::NAMESPACE_ATOM === $firstAtom->atomAt(0)) {
$parent = $context->primaryNamespace();
} else {
$parent = $context->classNameByShortName($firstAtom);
}

if ($parent) {
if (count($className->atoms()) < 2) {
return $parent;
}
Expand Down
5 changes: 5 additions & 0 deletions test/suite/Resolution/ClassNameResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public function testResolveAgainstContextDocumentationExamples()
)
);

$this->assertSame(
'\foo\Another',
$this->resolver->resolveAgainstContext($this->context, $this->classNameFactory->create('namespace\Another'))
->string()
);
$this->assertSame(
'\My\Full\Classname',
$this->resolver->resolveAgainstContext($this->context, $this->classNameFactory->create('Another'))->string()
Expand Down

0 comments on commit 7b686c8

Please sign in to comment.