<?php
namespace Fuel\Tasks;
/**
*
* Code Completion Code Generator
*
*/
class Ccc
{
private static $without_dirs;
private static $generated_code = array();
private static $dup_class = array();
public static function run()
{
// keep without-genereted directory names
if (\Cli::option('without', false) or \Cli::option('WITHOUT', false))
{
self::$without_dirs = explode('+', \Cli::option('without'));
}
else
{
self::$without_dirs = false;
}
// other command line handling to generate
if (\Cli::option('all', false) or \Cli::option('ALL', false))
{
$dir = \File::read_dir(COREPATH, 0, 'php');
self::generate_redefine($dir, '', COREPATH);
$dir = \File::read_dir(APPPATH, 0, 'php');
self::generate_redefine($dir, '', APPPATH);
$dir = \File::read_dir(PKGPATH, 0, 'php');
self::generate_redefine($dir, '', PKGPATH);
}
else
{
if (\Cli::option('core', false) or \Cli::option('CORE', false))
{
$dir = \File::read_dir(COREPATH, 0, 'php');
self::generate_redefine($dir, '', COREPATH);
}
elseif (\Cli::option('app', false) or \Cli::option('APP', false))
{
$dir = \File::read_dir(APPPATH, 0, 'php');
self::generate_redefine($dir, '', APPPATH);
}
elseif (\Cli::option('packages', false) or \Cli::option('PACKAGES', false))
{
$dir = \File::read_dir(PKGPATH, 0, 'php');
self::generate_redefine($dir, '', PKGPATH);
}
else
{
echo PHP_EOL.'usage: [php] oil [-all] [-core] [-app] [-packages] [-without=directory_name[+directory_name]...] [-help]'.PHP_EOL;
echo 'Code Completion Code Generator for FuelPHP'.PHP_EOL.PHP_EOL;
echo 'php at head of commnad line needed if you use oil in cmd.exe on windows normaly.'.PHP_EOL;
echo '-all : Generate from app, core and packages directory.'.PHP_EOL;
echo '-app : Generate from app directory.'.PHP_EOL;
echo '-core : Generate from core directory.'.PHP_EOL;
echo '-help : Display this help and exit.'.PHP_EOL;
echo '-packages : Generate from core packages.'.PHP_EOL;
echo '-without : + seperated directory name where no generated code.'.PHP_EOL.PHP_EOL;
echo 'This task output result into standard output.'.PHP_EOL;
echo 'So after you checked output code, redirect to your output PHP file. Do like :'.PHP_EOL;
echo 'php oil r ccc -all -without=tasks+migrations+vendor+tests+oil+orm+parser > CodeCompetionCode.php'.PHP_EOL;
echo 'And put the file on anywhere your source code folder.'.PHP_EOL.PHP_EOL;
echo 'Caution:'.PHP_EOL;
echo 'This generated code work on no namespace used on your code in IDE editor.'.PHP_EOL;
echo 'Because this just redefine every short class name as general(top) level of namespace.'.PHP_EOL;
echo 'So never work at a code like a task and/or a package, that used namespace.(Or your code used namespace. ;) )'.PHP_EOL;
echo 'If you want to work code completion on code used namespace, it is the better way switch comment off for the namespace statement during you edit it.';
exit(0);
}
}
ksort(self::$generated_code);
ksort(self::$dup_class);
echo '<?php'.PHP_EOL;
if (!empty(self::$dup_class))
{
echo '// Duplicated classes from here'.PHP_EOL;
echo implode("\n", self::$dup_class);
echo PHP_EOL.'// Duplicated classes to here'.PHP_EOL;
}
echo implode("\n", self::$generated_code);
}
private static function generate_redefine($ary, $path, $base)
{
foreach ($ary as $key => $val)
{
if (is_array($val))
{
if ((self::$without_dirs and !in_array(trim($key, '/\\'), self::$without_dirs)) or !self::$without_dirs)
{
self::generate_redefine($val, $path.$key, $base);
}
}
else
{
// read php code
try
{
$buff = explode("\n", \File::read($base.$path.$val, true));
}
catch (\Fuel\Core\InvalidPathException $e)
{
die('Failed to read file : '.$path.$val);
}
$namespace = '';
foreach ($buff as $i)
{
// get namespace
if (preg_match('/^[ \\t]*namespace[ \\t]+(.+?)[ \\t]*;/', $i, $matched) === 1)
{
$namespace = $matched[1];
}
// get abstract class
elseif ($namespace != '' and preg_match('/^[ \\t]*abstract[ \\t]+class[ \\t]+(\\w+)/', $i, $matched) === 1)
{
self::reg_classname($matched[1],
"abstract class\t".$matched[1].' extends '.$namespace.'\\'.$matched[1].'{};');
}
// get interface
elseif ($namespace != '' and preg_match('/^[ \\t]*interface[ \\t]+(\\w+)/', $i, $matched) === 1)
{
self::reg_classname($matched[1],
"interface\t\t".$matched[1].' extends '.$namespace.'\\'.$matched[1].'{};');
}
// get class
elseif ($namespace != '' and preg_match('/^[ \\t]*class[ \\t]+(\\w+)/', $i, $matched))
{
self::reg_classname($matched[1],
"class\t\t\t".$matched[1].' extends '.$namespace.'\\'.$matched[1].'{};');
}
}
}
}
}
private static function reg_classname($key, $str)
{
if (key_exists($key, self::$generated_code))
{
self::$dup_class[$key] = $str;
}
else
{
self::$generated_code[$key] = $str;
}
}
}
<?php class Agent extends Fuel\Core\Agent{}; class Arr extends Fuel\Core\Arr{}; class Asset extends Fuel\Core\Asset{}; class AttachmentNotFoundException extends Email\AttachmentNotFoundException{}; class Auth extends Auth\Auth{}; class AuthException extends Auth\AuthException{}; abstract class Auth_Acl_Driver extends Auth\Auth_Acl_Driver{}; class Auth_Acl_SimpleAcl extends Auth\Auth_Acl_SimpleAcl{}; abstract class Auth_Driver extends Auth\Auth_Driver{}; abstract class Auth_Group_Driver extends Auth\Auth_Group_Driver{}; class Auth_Group_SimpleGroup extends Auth\Auth_Group_SimpleGroup{}; abstract class Auth_Login_Driver extends Auth\Auth_Login_Driver{}; class Auth_Login_SimpleAuth extends Auth\Auth_Login_SimpleAuth{}; class Autoloader extends Fuel\Core\Autoloader{}; class Cache extends Fuel\Core\Cache{}; class CacheExpiredException extends Fuel\Core\CacheExpiredException{}; class CacheNotFoundException extends Fuel\Core\CacheNotFoundException{}; interface Cache_Handler_Driver extends Fuel\Core\Cache_Handler_Driver{}; class Cache_Handler_Json extends Fuel\Core\Cache_Handler_Json{}; class Cache_Handler_Serialized extends Fuel\Core\Cache_Handler_Serialized{}; class Cache_Handler_String extends Fuel\Core\Cache_Handler_String{}; class Cache_Storage_Apc extends Fuel\Core\Cache_Storage_Apc{}; abstract class Cache_Storage_Driver extends Fuel\Core\Cache_Storage_Driver{}; class Cache_Storage_File extends Fuel\Core\Cache_Storage_File{}; class Cache_Storage_Memcached extends Fuel\Core\Cache_Storage_Memcached{}; class Cache_Storage_Redis extends Fuel\Core\Cache_Storage_Redis{}; class Cli extends Fuel\Core\Cli{}; class Config extends Fuel\Core\Config{}; class ConfigException extends Fuel\Core\ConfigException{}; abstract class Config_File extends Fuel\Core\Config_File{}; class Config_Ini extends Fuel\Core\Config_Ini{}; interface Config_Interface extends Fuel\Core\Config_Interface{}; class Config_Json extends Fuel\Core\Config_Json{}; class Config_Php extends Fuel\Core\Config_Php{}; class Config_Yml extends Fuel\Core\Config_Yml{}; abstract class Controller extends Fuel\Core\Controller{}; abstract class Controller_Rest extends Fuel\Core\Controller_Rest{}; abstract class Controller_Template extends Fuel\Core\Controller_Template{}; class Cookie extends Fuel\Core\Cookie{}; class Crypt extends Fuel\Core\Crypt{}; class DB extends Fuel\Core\DB{}; class DBUtil extends Fuel\Core\DBUtil{}; abstract class Database_Connection extends Fuel\Core\Database_Connection{}; class Database_Exception extends Fuel\Core\Database_Exception{}; class Database_Expression extends Fuel\Core\Database_Expression{}; class Database_MySQL_Connection extends Fuel\Core\Database_MySQL_Connection{}; class Database_MySQL_Result extends Fuel\Core\Database_MySQL_Result{}; class Database_MySQLi_Connection extends Fuel\Core\Database_MySQLi_Connection{}; class Database_MySQLi_Result extends Fuel\Core\Database_MySQLi_Result{}; class Database_PDO_Connection extends Fuel\Core\Database_PDO_Connection{}; class Database_Query extends Fuel\Core\Database_Query{}; abstract class Database_Query_Builder extends Fuel\Core\Database_Query_Builder{}; class Database_Query_Builder_Delete extends Fuel\Core\Database_Query_Builder_Delete{}; class Database_Query_Builder_Insert extends Fuel\Core\Database_Query_Builder_Insert{}; class Database_Query_Builder_Join extends Fuel\Core\Database_Query_Builder_Join{}; class Database_Query_Builder_Select extends Fuel\Core\Database_Query_Builder_Select{}; class Database_Query_Builder_Update extends Fuel\Core\Database_Query_Builder_Update{}; abstract class Database_Query_Builder_Where extends Fuel\Core\Database_Query_Builder_Where{}; abstract class Database_Result extends Fuel\Core\Database_Result{}; class Database_Result_Cached extends Fuel\Core\Database_Result_Cached{}; class Database_Transaction extends Fuel\Core\Database_Transaction{}; class Date extends Fuel\Core\Date{}; class Debug extends Fuel\Core\Debug{}; class Email extends Email\Email{}; class EmailSendingFailedException extends Email\EmailSendingFailedException{}; class EmailValidationFailedException extends Email\EmailValidationFailedException{}; abstract class Email_Driver extends Email\Email_Driver{}; class Email_Driver_Mail extends Email\Email_Driver_Mail{}; class Email_Driver_Sendmail extends Email\Email_Driver_Sendmail{}; class Email_Driver_Smtp extends Email\Email_Driver_Smtp{}; class Error extends Fuel\Core\Error{}; class Event extends Fuel\Core\Event{}; class Fieldset extends Fuel\Core\Fieldset{}; class Fieldset_Field extends Fuel\Core\Fieldset_Field{}; class File extends Fuel\Core\File{}; class FileAccessException extends Fuel\Core\FileAccessException{}; class File_Area extends Fuel\Core\File_Area{}; class File_Handler_Directory extends Fuel\Core\File_Handler_Directory{}; class File_Handler_File extends Fuel\Core\File_Handler_File{}; class Finder extends Fuel\Core\Finder{}; class Form extends Fuel\Core\Form{}; class Format extends Fuel\Core\Format{}; class Ftp extends Fuel\Core\Ftp{}; class FtpConnectionException extends Fuel\Core\FtpConnectionException{}; class FtpFileAccessException extends Fuel\Core\FtpFileAccessException{}; class Fuel extends Fuel\Core\Fuel{}; class FuelException extends Fuel\Core\FuelException{}; class Fuel_Exception extends Fuel\Core\Fuel_Exception{}; class Html extends Fuel\Core\Html{}; abstract class HttpException extends Fuel\Core\HttpException{}; class HttpNotFoundException extends Fuel\Core\HttpNotFoundException{}; class HttpServerErrorException extends Fuel\Core\HttpServerErrorException{}; class Image extends Fuel\Core\Image{}; abstract class Image_Driver extends Fuel\Core\Image_Driver{}; class Image_Gd extends Fuel\Core\Image_Gd{}; class Image_Imagemagick extends Fuel\Core\Image_Imagemagick{}; class Image_Imagick extends Fuel\Core\Image_Imagick{}; class Inflector extends Fuel\Core\Inflector{}; class Input extends Fuel\Core\Input{}; class InvalidAttachmentsException extends Email\InvalidAttachmentsException{}; class InvalidEmailStringEncoding extends Email\InvalidEmailStringEncoding{}; class InvalidPathException extends Fuel\Core\InvalidPathException{}; class Lang extends Fuel\Core\Lang{}; class Log extends Fuel\Core\Log{}; class Markdown extends Fuel\Core\Markdown{}; class Migrate extends Fuel\Core\Migrate{}; class Model extends Fuel\Core\Model{}; class Model_Crud extends Fuel\Core\Model_Crud{}; class Mongo_Db extends Fuel\Core\Mongo_Db{}; class Mongo_DbException extends Fuel\Core\Mongo_DbException{}; class Num extends Fuel\Core\Num{}; class OutsideAreaException extends Fuel\Core\OutsideAreaException{}; class Package extends Fuel\Core\Package{}; class PackageNotFoundException extends Fuel\Core\PackageNotFoundException{}; class Pagination extends Fuel\Core\Pagination{}; class Profiler extends Fuel\Core\Profiler{}; class Redis extends Fuel\Core\Redis{}; class RedisException extends Fuel\Core\RedisException{}; class Request extends Fuel\Core\Request{}; class Request404Exception extends Fuel\Core\Request404Exception{}; class RequestException extends Fuel\Core\RequestException{}; class Request_Curl extends Fuel\Core\Request_Curl{}; abstract class Request_Driver extends Fuel\Core\Request_Driver{}; class Request_Soap extends Fuel\Core\Request_Soap{}; class Response extends Fuel\Core\Response{}; class Route extends Fuel\Core\Route{}; class Router extends Fuel\Core\Router{}; class Security extends Fuel\Core\Security{}; class SendmailConnectionException extends Email\SendmailConnectionException{}; class SendmailFailedException extends Email\SendmailFailedException{}; class Session extends Fuel\Core\Session{}; class Session_Cookie extends Fuel\Core\Session_Cookie{}; class Session_Db extends Fuel\Core\Session_Db{}; abstract class Session_Driver extends Fuel\Core\Session_Driver{}; class Session_Exception extends Fuel\Core\Session_Exception{}; class Session_File extends Fuel\Core\Session_File{}; class Session_Memcached extends Fuel\Core\Session_Memcached{}; class Session_Redis extends Fuel\Core\Session_Redis{}; class SimpleUserUpdateException extends Auth\SimpleUserUpdateException{}; class SimpleUserWrongPassword extends Auth\SimpleUserWrongPassword{}; class SmtpAuthenticationFailedException extends Email\SmtpAuthenticationFailedException{}; class SmtpCommandFailureException extends Email\SmtpCommandFailureException{}; class SmtpConnectionException extends Email\SmtpConnectionException{}; class Str extends Fuel\Core\Str{}; class TestCase extends Fuel\Core\TestCase{}; class Theme extends Fuel\Core\Theme{}; class ThemeException extends Fuel\Core\ThemeException{}; class Unzip extends Fuel\Core\Unzip{}; class Upload extends Fuel\Core\Upload{}; class Uri extends Fuel\Core\Uri{}; class Validation extends Fuel\Core\Validation{}; class Validation_Error extends Fuel\Core\Validation_Error{}; class View extends Fuel\Core\View{}; abstract class ViewModel extends Fuel\Core\ViewModel{};
It looks like you're new here. If you want to get involved, click one of these buttons!