FuelPHP IDE補完用ファイルであるautocomplete.phpを生成するgenerate.phpが、キャメルケースに対応していないため、修正してみました。
素晴らしいスクリプトに感謝します。
http://d.hatena.ne.jp/Kenji_s/20120123/1327301678
FuelPHP IDE補完用ファイルであるautocomplete.phpを生成するgenerate.phpが、キャメルケースに対応していないため、修正してみました。
素晴らしいスクリプトに感謝します。
http://d.hatena.ne.jp/Kenji_s/20120123/1327301678
<?php | |
namespace Fuel\Tasks; | |
class Generate | |
{ | |
static $class_definition = ''; | |
public static function run() | |
{ | |
echo <<<EOL | |
Usage: | |
oil refine generate:autocomplete ... generate php file for IDE's auto completion | |
EOL; | |
} | |
public static function autocomplete() | |
{ | |
$classes = \File::read_dir(COREPATH . 'classes'); | |
static::generate_class_definition($classes); | |
static::$class_definition = '<?php' . "\n\n" . static::$class_definition; | |
$file = 'autocomplete.php'; | |
$ret = file_put_contents($file, static::$class_definition); | |
if ($ret === false) | |
{ | |
echo 'Can\'t write to ' . $file; | |
} | |
else | |
{ | |
echo $file . ' was created.'; | |
} | |
} | |
private static function generate_class_definition($classes, $str = '') | |
{ | |
foreach ($classes as $dir => $file) | |
{ | |
if (is_array($file)) | |
{ | |
static::generate_class_definition($file, $str . ucfirst(rtrim($dir, '/') . '_')); | |
} | |
else | |
{ | |
$class_name = static::get_real_class_name($str, $file); | |
static::$class_definition .= 'class ' . $class_name; | |
static::$class_definition .= ' extends Fuel\\Core\\' . $class_name; | |
static::$class_definition .= ' {}' . "\n"; | |
} | |
} | |
} | |
private static function get_real_class_name($path_as_snake, $file) | |
{ | |
$path = sprintf('%sclasses/%s%s', COREPATH, str_replace('_', '/', $path_as_snake), $file); | |
$content = file_get_contents($path); | |
preg_match('/(^abstract class|^class|^interface)\s(\w*)/m', $content, $matches); | |
if(count($matches) == 3){ | |
return $matches[2]; | |
} | |
else{ | |
die("Unexpected format was detected[$path]."); | |
} | |
} | |
} |