Skip to content

Instantly share code, notes, and snippets.

@uru-bns
Created February 13, 2014 12:18
Show Gist options
  • Save uru-bns/8974099 to your computer and use it in GitHub Desktop.
Save uru-bns/8974099 to your computer and use it in GitHub Desktop.

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].");
}
}
}
Copy link

ghost commented Feb 17, 2014

LGTM

@uru-bns
Copy link
Author

uru-bns commented Mar 18, 2014

(少なくとも)Configクラスが生成されないバグ発見。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment