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

Commit

Permalink
Merge branch 'hotfix/file-locator-refactor' of https://github.com/Mak…
Browse files Browse the repository at this point in the history
…s3w/zf2 into hotfix/zf2-296
  • Loading branch information
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions src/ClassFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ public function __construct($dirOrIterator = '.')
}

$dirOrIterator = new RecursiveDirectoryIterator($dirOrIterator, RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
}
if (!$dirOrIterator instanceof DirectoryIterator) {
} elseif (!$dirOrIterator instanceof DirectoryIterator) {
throw new Exception\InvalidArgumentException('Expected a DirectoryIterator');
}

if ($dirOrIterator instanceof RecursiveIterator) {
$iterator = new RecursiveIteratorIterator($dirOrIterator);
} else {
$iterator = $dirOrIterator;
$dirOrIterator = new RecursiveIteratorIterator($dirOrIterator);
}

parent::__construct($iterator);
parent::__construct($dirOrIterator);
}

/**
Expand Down Expand Up @@ -95,9 +92,8 @@ public function accept()
$contents = file_get_contents($file->getRealPath());
$tokens = token_get_all($contents);
$count = count($tokens);
$i = 0;
$t_trait = defined('T_TRAIT') ? T_TRAIT : -1; // For preserve PHP 5.3 compatibility
while ($i < $count) {
for ($i = 0; $i < $count; $i++) {
$token = $tokens[$i];

if (!is_array($token)) {
Expand All @@ -106,22 +102,15 @@ public function accept()
continue;
}

list($id, $content, $line) = $token;

switch ($id) {
switch ($token[0]) {
case T_NAMESPACE:
// Namespace found; grab it for later
$namespace = '';
$done = false;
do {
++$i;
if (!array_key_exists($i, $tokens)) {
break;
}
for ($i++; $i < $count; $i++) {
$token = $tokens[$i];
if (is_string($token)) {
if (';' === $token) {
$done = true;
break;
}
continue;
}
Expand All @@ -132,7 +121,7 @@ public function accept()
$namespace .= $content;
break;
}
} while (!$done && $i < $count);
}

// Set the namespace of this file in the object
$file->namespace = $namespace;
Expand All @@ -143,32 +132,23 @@ public function accept()
// Abstract class, class, interface or trait found

// Get the classname
$class = '';
do {
++$i;
for ($i++; $i < $count; $i++) {
$token = $tokens[$i];
if (is_string($token)) {
continue;
}
list($type, $content, $line) = $token;
switch ($type) {
case T_STRING:
$class = $content;
break;
if (T_STRING == $type) {
// If a classname was found, set it in the object, and
// return boolean true (found)
$file->classname = $content;
return true;
}
} while (empty($class) && $i < $count);

// If a classname was found, set it in the object, and
// return boolean true (found)
if (!empty($class)) {
$file->classname = $class;
return true;
}
break;
default:
break;
}
++$i;
}

// No class-type tokens found; return false
Expand Down

0 comments on commit c660c64

Please sign in to comment.