public function testClearSQLComments() { $stringsToTest = ['SELECT * FROM TEST;' => 'SELECT * FROM TEST;', 'SELECT * FROM TEST; --comment here' => 'SELECT * FROM TEST;']; foreach ($stringsToTest as $key => $value) { $this->assertEquals($value, \Zazalt\Strink\Strink::turn($key)->clearSQLComments()); } }
/** * Generate model file with only database raws, setters and getters */ private function createModel($entity) { $autoGeneratedModelContent = file_get_contents(dirname(__FILE__) . '/Templates/AutoGenerated/Model.php'); $modelContent = file_get_contents(dirname(__FILE__) . '/Templates/Model.php'); $modelNameCamelCase = \Zazalt\Strink\Strink::turn(key($entity))->snakeCaseToCamelCase(true); $autoGeneratedModelContent = str_replace("##construct##", "protected \$modelName = '" . key($entity) . "';\n\n\t##construct##", $autoGeneratedModelContent); $autoGeneratedModelContent = strtr($autoGeneratedModelContent, ['___CLASS___' => $modelNameCamelCase, '___NAMESPACE___' => $this->namespace . '\\AutoGenerated\\Model', '___TABLE___' => key($entity), '___DATE___' => date('Y-m-d H:i:s'), '##extends##' => 'extends \\' . $this->namespace . '\\AutoGenerated\\Repository\\' . $modelNameCamelCase, '##construct##' => $this->extends ? "public function __construct()\n\t{\n\t\tparent::__construct();\n\t}" : '']); if ($this->constructInject) { $autoGeneratedModelContent = str_replace('__construct()', "__construct({$this->constructInject})", $autoGeneratedModelContent); } $modelContent = strtr($modelContent, ['___CLASS___' => $modelNameCamelCase, '___NAMESPACE___' => $this->namespace, '___TABLE___' => key($entity), '___DATE___' => date('Y-m-d H:i:s'), '##extends##' => 'extends \\' . $this->namespace . '\\AutoGenerated\\Model\\' . $modelNameCamelCase, '##construct##' => "public function __construct()\n\t{\n\t\tparent::__construct();\n\t}\n\n\t/* You can put your custom/logical code for this entity in this file. */\n\t/* This is the only file auto-generated only once (if not exists). */"]); if ($this->constructInject) { $modelContent = str_replace('::__construct()', "::__construct({$this->constructInject})", $modelContent); $modelContent = str_replace('parent::', "global {$this->constructInject};\n\t\tparent::", $modelContent); } $members = ''; $methods = ''; $index = 0; foreach ($entity as $entityName => $rows) { foreach ($rows as $rowName => $row) { $members .= $index > 0 ? "\n" : null; $members .= "\n\t/**"; $members .= "\n\t* @rowName\t\t" . $rowName; //$members .= "\n\t* @nullable\t\t{$entity['is_nullable']}"; $members .= "\n\t* @primaryKey\t" . (boolval($row['primaryKey']) ? 'true' : 'false'); $members .= "\n\t* @type\t\t\t{$row['type']}"; $members .= "\n\t* @default\t\t{$row['default']}"; $members .= "\n\t*/"; $members .= "\n\t"; $members .= 'private $' . \Zazalt\Strink\Strink::turn($rowName)->snakeCaseToCamelCase(false) . ';'; ++$index; } /* foreach($rows as $rowName => $row) { if($row['primaryKey']) { $rows = array_merge([ 'primaryKey' => array_merge(['primaryKey' => $rowName], $row) ], $rows); } } */ //print_r($rows);die; foreach ($rows as $rowName => $row) { $rowNameUcfCamelCase = \Zazalt\Strink\Strink::turn($rowName)->snakeCaseToCamelCase(true); $rowNameCamelCase = \Zazalt\Strink\Strink::turn($rowName)->snakeCaseToCamelCase(); $methods .= "\n\n\tpublic function set" . $rowNameUcfCamelCase . "(\${$rowNameCamelCase})\n\t{\n\t\t\$this->{$rowNameCamelCase} = \${$rowNameCamelCase};\n\t\treturn \$this;\n\t}"; $methods .= "\n\n\tpublic function get" . $rowNameUcfCamelCase . "()\n\t{\n\t\treturn \$this->{$rowNameCamelCase};\n\t}"; } } $autoGeneratedModelContent = str_replace('##members##', $members, $autoGeneratedModelContent); $autoGeneratedModelContent = str_replace('##methods##', $methods, $autoGeneratedModelContent); file_put_contents($this->exportTo . "/AutoGenerated/Model/{$modelNameCamelCase}.php", $autoGeneratedModelContent); $modelPath = $this->exportTo . "/{$modelNameCamelCase}.php"; if (!file_exists($modelPath)) { file_put_contents($this->exportTo . "/{$modelNameCamelCase}.php", $modelContent); } $this->createRepository($entity, \Zazalt\Strink\Strink::turn(key($entity))->snakeCaseToCamelCase(true)); }