Skip to content

Instantly share code, notes, and snippets.

@kissarat
Created March 31, 2013 00:09
Show Gist options
  • Save kissarat/5278918 to your computer and use it in GitHub Desktop.
Save kissarat/5278918 to your computer and use it in GitHub Desktop.
<?php
/**
* User: Taras Labiak
* Date: 3/9/13
* Time: 2:39 PM
*/
class EntityGenerator {
private $entityName;
private $tableName;
function __construct($entityName, $tableName = null) {
$this->entityName = $entityName;
$this->tableName = $tableName ? $tableName : $entityName;
}
function generate(PDOStatement $pdoStatement) {
echo '<pre>';
echo "class $this->entityName extends Entity {\n";
$columnCount = $pdoStatement->columnCount();
for($i=0; $i<$columnCount; $i++) {
$meta = $pdoStatement->getColumnMeta($i);
extract($meta, EXTR_OVERWRITE);
echo "\tprivate \$$name;\n";
}
echo "\n\tpublic function __set(\$name, \$value) {\n\t\t\$this->modified[] = \"\$name\";\n\t\t\$this->\$name = \$value;\t\n\t}\n}</pre>";
}
function generateJSON(PDOStatement $pdoStatement) {
}
public function __set($name, $value) {
$this->$name = $value;
}
}
$table = $_GET['table'];
$userGenerator = new EntityGenerator($table);
$userGenerator->generate($pdo->query("SELECT * FROM `$table`"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment