|
|
@ -35,7 +35,7 @@ class AutoloadBuilder |
|
|
|
|
|
|
|
public function build() |
|
|
|
{ |
|
|
|
$this->openAutoload(); |
|
|
|
$array_string = "<?php\n// This file is autogenerated by \n// " . __FILE__ . " script.\nreturn array(\n"; |
|
|
|
// for dublicates check
|
|
|
|
$classes = array(); |
|
|
|
foreach ($this->dirs as $dir) { |
|
|
@ -65,47 +65,39 @@ class AutoloadBuilder |
|
|
|
if (array_key_exists($match[2], $classes)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
$string = "'{$match[2]}'=>'" . $relative_path . "',\n"; |
|
|
|
$this->write($string); |
|
|
|
$array_string .= "'{$match[2]}'=>'" . $relative_path . "',\n"; |
|
|
|
$classes[$match[2]] = $file->getRealPath(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$this->closeAutoload(); |
|
|
|
$array_string .= ');'; |
|
|
|
$this->writeAutoload($array_string); |
|
|
|
$this->isFileConsistent(); |
|
|
|
} |
|
|
|
|
|
|
|
protected function isExcluded($file) |
|
|
|
{ |
|
|
|
foreach ($this->exclude as $dir) { |
|
|
|
if (stripos($file, PATH . $dir) === 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function openAutoload() |
|
|
|
protected function writeAutoload($string) |
|
|
|
{ |
|
|
|
$this->write("<?php\n// This file is autogenerated by \n// " . __FILE__ . " script.\nreturn array(\n"); |
|
|
|
file_put_contents($this->autoload, $string); |
|
|
|
} |
|
|
|
|
|
|
|
protected function closeAutoload() |
|
|
|
protected function isFileConsistent() |
|
|
|
{ |
|
|
|
if ($this->write(');')) { |
|
|
|
fclose($this->handler); |
|
|
|
$autoload_array = include($this->autoload); |
|
|
|
if(!is_array($autoload_array)) { |
|
|
|
unlink($this->autoload); |
|
|
|
trigger_error("Error while generating autoload file.", E_USER_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected function write($string) |
|
|
|
protected function isExcluded($file) |
|
|
|
{ |
|
|
|
if (!$this->handler) { |
|
|
|
if (!$this->handler = fopen($this->autoload, 'w')) { |
|
|
|
trigger_error("{$this->autoload} is not writable", E_USER_ERROR); |
|
|
|
foreach ($this->exclude as $dir) { |
|
|
|
if (stripos($file, PATH . $dir) === 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return (bool) fwrite($this->handler, $string); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
protected function rightSubstr($string, $nchars) |
|
|
|