Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Schema {
- public $name;
- public $engine;
- public $charset = 'utf8';
- public $collation;
- protected $fields = [];
- protected $current_field;
- function __construct($name){
- $this->name = $name;
- }
- // type
- function integer($name){
- $this->current_field = $name;
- $this->fields[$this->current_field] = [];
- $this->fields[$this->current_field]['type'] = 'integer';
- return $this;
- }
- function varchar($name){
- $this->current_field = $name;
- $this->fields[$this->current_field] = [];
- $this->fields[$this->current_field]['type'] = 'varchar';
- return $this;
- }
- // modifiers
- function auto(){
- // chequear si es un entero
- $this->fields[$this->current_field]['auto'] = true;
- return $this;
- }
- function unsigned(){
- // chequear si es un entero
- $this->fields[$this->current_field]['unsigned'] = true;
- return $this;
- }
- function nullable(){
- // chequear si es un entero
- $this->fields[$this->current_field]['nullable'] = true;
- return $this;
- }
- // reflexion
- function getSchema(){
- return $this->fields;
- }
- }
- $table = new Schema('test');
- $table->name = 'users';
- $table->engine = 'InnoDB';
- $table->charset = 'utf8';
- $table->collation = 'utf8_general_ci';
- $table->integer('id')->auto()->unsigned();
- $table->varchar('firstname');
- $table->varchar('lastname')->nullable();
- // ..
- echo '<pre>';
- var_dump($table->getSchema());
- echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement