Browse Source

More complex regular expression for AutoloadBuilder

master
Anton Terekhov 12 years ago
parent
commit
255c3a837a
  1. 14
      util/AutoloadBuilder.php

14
util/AutoloadBuilder.php

@ -22,7 +22,7 @@ class AutoloadBuilder
protected $handler;
protected $regex = '/(class|interface) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/';
protected $regex = '/\n(abstract |final )?(class|interface) ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/';
public function __construct($autoload, $dirs = array(), $exclude = array())
{
@ -34,7 +34,7 @@ class AutoloadBuilder
public function build()
{
$array_string = "<?php\n// This file is autogenerated by \n// " . __FILE__ . " script.\nreturn array(\n";
// for dublicates check
// for duplicates check
$classes = array();
foreach ($this->dirs as $dir) {
$iterator = new RecursiveIteratorIterator(
@ -43,7 +43,9 @@ class AutoloadBuilder
);
foreach ($iterator as $file) {
/**
* @var SplFileInfo $file
*/
if ($this->isExcluded($file->getRealPath())) {
continue;
}
@ -60,11 +62,11 @@ class AutoloadBuilder
if (preg_match_all($this->regex, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
if (array_key_exists($match[2], $classes)) {
if (array_key_exists($match[3], $classes)) {
continue;
}
$array_string .= "'{$match[2]}'=>'" . $relative_path . "',\n";
$classes[$match[2]] = $file->getRealPath();
$array_string .= "'{$match[3]}'=>'" . $relative_path . "',\n";
$classes[$match[3]] = $file->getRealPath();
}
}
}

Loading…
Cancel
Save