/**
  * process event
  *
  * @param Charcoal_IEventContext $context
  *
  * @return boolean|Charcoal_Boolean
  */
 public function processEvent($context)
 {
     /** @var GenerateModelEvent $event */
     $event = $context->getEvent();
     // get event parameters
     $db_name = $event->getDatabase();
     $table_name = $event->getTable();
     $out_dir = $event->getTargetDir();
     $entity = Charcoal_System::pascalCase($table_name);
     $config_key = Charcoal_System::snakeCase($table_name);
     $table_model_class_name = "{$entity}TableModel";
     $table_dto_class_name = "{$entity}TableDTO";
     $listing_dto_class_name = "{$entity}ListingDTO";
     /** @var Charcoal_SmartGateway $gw */
     $gw = $context->getComponent('smart_gateway@:charcoal:db');
     //=======================================
     // Mmake output directory
     //=======================================
     $out_dir = $this->prepareOutputDirectory($out_dir);
     //=======================================
     // confirm if the table exists
     //=======================================
     $sql = "SELECT count(*) FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? ";
     $params = array($table_name, $db_name);
     $count = $gw->queryValue(NULL, $sql, $params);
     if ($count < 1) {
         print "[ERROR] Specified table '{$table_name}' does not exist in schema: '{$db_name}'. Please check your database settings." . PHP_EOL;
         return b(true);
     }
     //=======================================
     // Retrieve column information
     //=======================================
     $sql = "SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA, COLUMN_COMMENT ";
     $sql .= " FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? ";
     $params = array($table_name, $db_name);
     $colmn_attr_list = $gw->query(NULL, $sql, $params);
     //=======================================
     // Genarate  table model file
     //=======================================
     $this->generateTableModelFile($table_name, $colmn_attr_list, $table_model_class_name, $table_dto_class_name, $out_dir);
     //=======================================
     // Genarate table DTO file
     //=======================================
     $this->generateTableDtolFile($table_name, $colmn_attr_list, $table_dto_class_name, $out_dir);
     //=======================================
     // Genarate listing DTO file
     //=======================================
     $this->generateListingDtolFile($table_name, $colmn_attr_list, $listing_dto_class_name, $out_dir);
     //=======================================
     // Genarate  config file
     //=======================================
     $this->generateTableConfigFile($table_name, $table_model_class_name, $config_key, $out_dir);
     return b(true);
 }
 /**
  * execute tests
  */
 public function test($action, $context)
 {
     $action = us($action);
     switch ($action) {
         case "get_object_var":
             $child = new ChildClass();
             $actual = Charcoal_System::getObjectVar($child, 'child_public_var');
             $this->assertEquals(4, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'child_protected_var');
             $this->assertEquals(5, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'child_private_var');
             $this->assertEquals(6, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'public_var');
             $this->assertEquals(4, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'protected_var');
             $this->assertEquals(5, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'private_var');
             $this->assertEquals(6, $actual);
             return TRUE;
         case "get_object_vars":
             $grandchild = new GrandChildClass();
             $grandchild_vars = Charcoal_System::getObjectVars($grandchild);
             //            foreach( $grandchild_vars as $k => $v ){
             //                echo "grandchild vars: [$k]=$v" . eol();
             //            }
             $grandchild_vars_actual = $grandchild->getObjectVars();
             //            foreach( $grandchild_vars_actual as $k => $v ){
             //                echo "grandchild vars_actual: [$k]=$v" . eol();
             //            }
             $this->assertEquals(1, $grandchild_vars_actual['grandparent_public_var']);
             $this->assertEquals(2, $grandchild_vars_actual['grandparent_protected_var']);
             $this->assertEquals(3, $grandchild_vars_actual['grandparent_private_var']);
             $this->assertEquals(4, $grandchild_vars_actual['child_public_var']);
             $this->assertEquals(5, $grandchild_vars_actual['child_protected_var']);
             $this->assertEquals(6, $grandchild_vars_actual['child_private_var']);
             $this->assertEquals(7, $grandchild_vars_actual['grandchild_public_var']);
             $this->assertEquals(8, $grandchild_vars_actual['grandchild_protected_var']);
             $this->assertEquals(9, $grandchild_vars_actual['grandchild_private_var']);
             $this->assertEquals(7, $grandchild_vars_actual['public_var']);
             $this->assertEquals(8, $grandchild_vars_actual['protected_var']);
             $this->assertEquals(9, $grandchild_vars_actual['private_var']);
             $child = new ChildClass();
             $child_vars = Charcoal_System::getObjectVars($child);
             //            foreach( $child_vars as $k => $v ){
             //                echo "child vars: [$k]=$v" . eol();
             //            }
             $child_vars_actual = $child->getObjectVars();
             //            foreach( $child_vars_actual as $k => $v ){
             //                echo "child vars_actual: [$k]=$v" . eol();
             //            }
             $this->assertEquals(1, $child_vars_actual['grandparent_public_var']);
             $this->assertEquals(2, $child_vars_actual['grandparent_protected_var']);
             $this->assertEquals(3, $child_vars_actual['grandparent_private_var']);
             $this->assertEquals(4, $child_vars_actual['child_public_var']);
             $this->assertEquals(5, $child_vars_actual['child_protected_var']);
             $this->assertEquals(6, $child_vars_actual['child_private_var']);
             $this->assertEquals(4, $child_vars_actual['public_var']);
             $this->assertEquals(5, $child_vars_actual['protected_var']);
             $this->assertEquals(6, $child_vars_actual['private_var']);
             $parent = new ParentClass();
             $parent_vars = Charcoal_System::getObjectVars($parent);
             //            foreach( $parent_vars as $k => $v ){
             //                echo "parent vars: [$k]=$v" . eol();
             //            }
             $parent_vars_actual = $parent->getObjectVars();
             //            foreach( $parent_vars_actual as $k => $v ){
             //                echo "parent vars_actual: [$k]=$v" . eol();
             //            }
             $this->assertEquals(1, $parent_vars_actual['grandparent_public_var']);
             $this->assertEquals(2, $parent_vars_actual['grandparent_protected_var']);
             $this->assertEquals(3, $parent_vars_actual['grandparent_private_var']);
             $this->assertEquals(1, $parent_vars_actual['public_var']);
             $this->assertEquals(2, $parent_vars_actual['protected_var']);
             $this->assertEquals(3, $parent_vars_actual['private_var']);
             return TRUE;
         case "snake_case":
             $data = array('CharcoalPhp' => 'charcoal_php', 'CharcoalPHP' => 'charcoal_php', 'charcoalPhp' => 'charcoal_php', 'charcoalPHP' => 'charcoal_php', 'charcoalphp' => 'charcoalphp', 'Charcoalphp' => 'charcoalphp', 'charcoalpHp' => 'charcoalp_hp', 'charcoalphP' => 'charcoalph_p', 'charCoalphp' => 'char_coalphp', 'charcoal_php' => 'charcoal_php', 'charcoal_PHP' => 'charcoal_php', 'Charcoal_PHP' => 'charcoal_php', 'Charcoal_Php' => 'charcoal_php', 'Charcoal_pHp' => 'charcoal_p_hp', 'Charcoal_phP' => 'charcoal_ph_p', 'CharCoal_php' => 'char_coal_php', 'charcoal_php_5.3' => 'charcoal_php_5.3', 'charcoal_php_ver5.3' => 'charcoal_php_ver5.3', 'charcoal_php_Ver5.3' => 'charcoal_php_ver5.3', 'charcoal_php_vEr5.3' => 'charcoal_php_v_er5.3', 'charcoal_php_5.3-dev' => 'charcoal_php_5.3-dev', 'charcoal_php_5.3-Dev' => 'charcoal_php_5.3-dev', 'charcoal_php_5.3-dEv' => 'charcoal_php_5.3-d_ev', 'charcoal_php0a2c' => 'charcoal_php0a2c');
             foreach ($data as $key => $expected) {
                 $actual = Charcoal_System::snakeCase($key);
                 //                echo "[original]$key [expected]$expected [actual]$actual" . eol();
                 $this->assertEquals($expected, $actual);
             }
             return TRUE;
         case "pascal_case":
             $data = array('CharcoalPhp' => 'Charcoalphp', 'CharcoalPHP' => 'Charcoalphp', 'charcoalPhp' => 'Charcoalphp', 'charcoalPHP' => 'Charcoalphp', 'charcoalphp' => 'Charcoalphp', 'Charcoalphp' => 'Charcoalphp', 'charcoalpHp' => 'Charcoalphp', 'charcoalphP' => 'Charcoalphp', 'charCoalphp' => 'Charcoalphp', 'charcoal_php' => 'CharcoalPhp', 'charcoal_PHP' => 'CharcoalPhp', 'Charcoal_PHP' => 'CharcoalPhp', 'Charcoal_Php' => 'CharcoalPhp', 'Charcoal_pHp' => 'CharcoalPhp', 'Charcoal_phP' => 'CharcoalPhp', 'CharCoal_php' => 'CharcoalPhp', 'charcoal_php_5.3' => 'CharcoalPhp5.3', 'charcoal_php_ver5.3' => 'CharcoalPhpVer5.3', 'charcoal_php_Ver5.3' => 'CharcoalPhpVer5.3', 'charcoal_php_vEr5.3' => 'CharcoalPhpVer5.3', 'charcoal_php_5.3-dev' => 'CharcoalPhp5.3-dev', 'charcoal_php_5.3-Dev' => 'CharcoalPhp5.3-dev', 'charcoal_php_5.3-dEv' => 'CharcoalPhp5.3-dev', 'charcoal_php0a2c' => 'CharcoalPhp0a2c');
             foreach ($data as $key => $expected) {
                 $actual = Charcoal_System::pascalCase($key);
                 //                echo "[original]$key [expected]$expected [actual]$actual" . eol();
                 $this->assertEquals($expected, $actual);
             }
             return TRUE;
         case "hash_collision":
             $hashes = array();
             $max = 1000000;
             for ($i = 0; $i < $max; $i++) {
                 $hash = Charcoal_System::hash();
                 if (!isset($hashes[$hash])) {
                     $hashes[$hash] = 0;
                 }
                 $hashes[$hash]++;
                 $p = (double) $i / $max * 100;
                 echo sprintf("[%0.2f %%]\r", $p);
             }
             $collisions = array_filter($hashes, function ($item) {
                 return $item >= 2;
             });
             ad($collisions);
             return TRUE;
     }
     return FALSE;
 }
 /**
  *    constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->obj_name = Charcoal_System::snakeCase(get_class($this));
 }