diff --git a/Core/Core.php b/Core/Core.php index 916da78..116d1a5 100644 --- a/Core/Core.php +++ b/Core/Core.php @@ -5,6 +5,7 @@ include_once "Helpers.php"; include_once "DatabaseConnection.php"; include_once "DatabaseORM.php"; + include_once "DatabaseMySQLEngine.php"; define("request", new Request(), false); define("response", new Response(), false); diff --git a/Core/DatabaseConnection.php b/Core/DatabaseConnection.php index ba5d64c..40d3404 100644 --- a/Core/DatabaseConnection.php +++ b/Core/DatabaseConnection.php @@ -1,6 +1,6 @@ table; + $sql[] = " ( "; + $columns = []; + foreach ($orm->columns as $name => $value) { + $type = $value[0]; + $propety = $value[1] ?? ""; + $columns[] = "$name $type $propety"; + } + $sql[] = implode(", ",$columns); + $sql[] = ") charset=" . $orm->charset; + + } + } + + ORM::$defaultConnection = new MySQLEngine("mysql","root",""); + + + ORM::migrate(function($table){ + $table->id("int","auto_increment primary key"); + $table->name("text"); + $table->value("text"); + }); \ No newline at end of file diff --git a/Core/DatabaseORM.php b/Core/DatabaseORM.php index bc9ad50..3c0544e 100644 --- a/Core/DatabaseORM.php +++ b/Core/DatabaseORM.php @@ -23,15 +23,37 @@ public $groupBy = []; public $having = []; public $orderby = []; - public $limit = []; + public $limit = false; public $union = []; public $set = []; public $join = []; public $alter = []; + public $israw = false; + public $raw = ""; + public static $defaultConnection = null; + public $connection; + public function __construct() + { + $this->connection = ORM::$defaultConnection; + } public static function name($args) { return name($args); } + public static function raw($sql) + { + $orm = new static(); + $orm->raw = $sql; + $orm->israw = true; + return $orm; + } + public static function migrate($class) + { + $orm = new static(); + $migration = new ORMMigrate(); + $class($migration); + $orm->connection->migrate($migration); + } public function from($orm) { foreach (get_class_vars($orm) as $key => $value) { @@ -74,24 +96,43 @@ } public function renameTable($from, $to) { + $this->mode = "alter"; $this->alter[] = ["renametable", $from, $to]; } public function renameColumn($from, $to) { + $this->mode = "alter"; $this->alter[] = ["renamecolumn", $from, $to]; } public function modifyColumn($from, $to) { + $this->mode = "alter"; $this->alter[] = ["modifyColumn", $from, $to]; } public function addColumn($from) { + $this->mode = "alter"; $this->alter[] = ["addColumn", $from, $to]; } public function removeColumn($from) { + $this->mode = "alter"; $this->alter[] = ["addColumn", $from, $to]; } + public function union(ORM $orm) + { + if($orm->mode == "select") + { + $this->union[] = $orm; + } + } + public function limit($offset = 0, $length = false) + { + $this->limit = [ + "offset" => $offset, + "length" => $length + ]; + } public function addWhere($statement, $name, $operator, $value) { $this->where = array_merge( @@ -278,12 +319,32 @@ } }; - - $t = new ORM(); - $t->table("argist"); - $t->whereIn("name",[1,2,3]); - $t->orWhere([ - "name"=>"value" - ]); - - dd($t); \ No newline at end of file + class ORMMigrate + { + use ReflectionHook; + public $table = ""; + public $charset = ""; + public $columns = []; + public $modifycolumns = []; + public $removecolumns = []; + public function table($name) + { + $this->table = name($name); + } + public function charset($charset) + { + $this->charset = $charset; + } + public function callable($name, $type = "int", $property = "") + { + $this->columns[name($name).""] = [$type,$property]; + } + public function setAttribute($name, $value) + { + $this->modifycolumns[name($name).""] = $value; + } + public function removeAttribute($name) + { + $this->removecolumns[] = name($name).""; + } + }; \ No newline at end of file diff --git a/Core/Reflection.php b/Core/Reflection.php index 14b25ce..82eeccb 100644 --- a/Core/Reflection.php +++ b/Core/Reflection.php @@ -22,11 +22,15 @@ return $this->{$formarlyA}(...$arguments); }else if(method_exists(__CLASS__, $formarlyB)) { - return (new static)->{$formarlyB}(...$arguments); + return $this->{$formarlyB}(...$arguments); } else if(method_exists(__CLASS__, "call$name")) { - return (new static)->{"call$name"}($name, ...$arguments); + return $this->{"call$name"}($name, ...$arguments); + } + else if(method_exists(__CLASS__, "callable")) + { + return $this->callable($name, ...$arguments); } } public function __get($name) @@ -80,14 +84,14 @@ { $this->{"set" . $formarly . "Attribute"}(); } + else if(method_exists($this, "removeAttribute")) + { + return $this->removeAttribute($name); + } else if(method_exists($this, "setAttribute")) { return $this->setAttribute($name, null); } - else if(method_exists($this, "remoteAttribute")) - { - return $this->remoteAttribute($name); - } else if(property_exists($this, "_attributes") && isset($this->_attributes[$name])) { unset($this->_attributes[$name]); @@ -99,17 +103,6 @@ { return $this->reflectionCall(...$args); } - else - { - if(property_exists(__CLASS__, "reflectionCallException")) - { - if(!(new static)->reflectionCallException) - { - return; - } - } - throw new Exception("\"".__CLASS__."()\" not callable"); - } } public function __toString() { @@ -117,17 +110,6 @@ { return $this->toString(); } - else - { - if(property_exists(__CLASS__, "reflectionCallException")) - { - if(!(new static)->reflectionCallException) - { - return ""; - } - } - throw new Exception("\"".__CLASS__."()\" not callable"); - } } public function __serialize() {