Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5054 in develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Oct 20, 2013
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/ClassFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function accept()
}
$class = (null === $namespace) ? $content : $namespace . '\\' . $content;
$file->addClass($class);
if ($namespace) {
$file->addNamespace($namespace);
}
$namespace = null;
break;
}
Expand Down
34 changes: 32 additions & 2 deletions src/PhpClassFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class PhpClassFile extends SplFileInfo
/**
* @var array
*/
protected $classes;
protected $classes = array();

/**
* @var array
*/
protected $namespaces = array();

/**
* Get classes
Expand All @@ -31,15 +36,40 @@ public function getClasses()
return $this->classes;
}

/**
* Get namespaces
*
* @return array
*/
public function getNamespaces()
{
return $this->namespaces;
}

/**
* Add class
*
* @param string $class
* @return PhpClassFile
* @return self
*/
public function addClass($class)
{
$this->classes[] = $class;
return $this;
}

/**
* Add namespace
*
* @param string $namespace
* @return self
*/
public function addNamespace($namespace)
{
if (in_array($namespace, $this->namespaces)) {
return $this;
}
$this->namespaces[] = $namespace;
return $this;
}
}
9 changes: 9 additions & 0 deletions test/ClassFileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public function testIterationShouldInjectNamespaceInFoundItems()
$this->assertTrue($found);
}

public function testIterationShouldInjectNamespacesInFileInfo()
{
$locator = new ClassFileLocator(__DIR__);
foreach ($locator as $file) {
$namespaces = $file->getNamespaces();
$this->assertTrue(count($namespaces) > 0);
}
}

public function testIterationShouldInjectClassInFoundItems()
{
$locator = new ClassFileLocator(__DIR__);
Expand Down

0 comments on commit 73d3d1c

Please sign in to comment.