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

Commit

Permalink
[zendframework/zendframework#5054] make pluginmap generator work again
Browse files Browse the repository at this point in the history
- Fixed some assumptions that changed along the way with regards to what
  the PhpClassFile class composes and returns. Added the ability to
  aggregate namespaces as well as classes in PhpClassFile, and a getter
  for the namespaces, in order to make the pluginmap_generator work.
- Modified the pluginmap_generator to use the new methods.
  • Loading branch information
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 @@ -83,6 +83,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 e4120f9

Please sign in to comment.