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

Commit

Permalink
Merge pull request #5054
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Oct 20, 2013
2 parents 496d4c8 + 4984111 commit 05053fa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
15 changes: 12 additions & 3 deletions bin/pluginmap_generator.php
Expand Up @@ -122,11 +122,20 @@
// Iterate over each element in the path, and create a map of pluginname => classname
$map = new \stdClass;
foreach ($l as $file) {
$namespaces = $file->getNamespaces();
$namespace = empty($file->namespace) ? '' : $file->namespace . '\\';
$plugin = strtolower($file->classname);
$class = $namespace . $file->classname;

$map->{$plugin} = $class;
foreach ($file->getClasses() as $classname) {
$plugin = $classname;
foreach ($namespaces as $namespace) {
$namespace .= '\\';
if (0 === strpos($plugin, $namespace)) {
$plugin = str_replace($namespace, '', $plugin);
}
}
$plugin = strtolower($plugin);
$map->{$plugin} = $classname;
}
}

if ($appending) {
Expand Down
3 changes: 3 additions & 0 deletions library/Zend/File/ClassFileLocator.php
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 library/Zend/File/PhpClassFile.php
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 tests/ZendTest/File/ClassFileLocatorTest.php
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 05053fa

Please sign in to comment.