Created
March 31, 2013 00:09
-
-
Save kissarat/5278918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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