From f642090d47ee03c2540a929aca4dbb3b8763ad28 Mon Sep 17 00:00:00 2001 From: Malloc of Kuzkycyziklistan Date: Wed, 1 Mar 2017 15:58:13 -0600 Subject: [PATCH] not much wewmy --- AroMVC/Base/Controller.php | 6 ++++ AroMVC/{ => Base}/Model.php | 30 ++++++++++++++------ AroMVC/{ => Configuration}/ConfigSection.php | 2 +- AroMVC/{ => Configuration}/Configuration.php | 2 +- AroMVC/{ => Database}/Database.php | 4 +-- AroMVC/{ => Database}/Deletable.php | 2 +- AroMVC/{ => Database}/Insertable.php | 2 +- AroMVC/{ => Database}/Modifiable.php | 2 +- AroMVC/{ => Database}/Queryable.php | 2 +- AroMVC/{ => Database}/Selectable.php | 2 +- AroMVC/IO/Directory.php | 6 ++++ AroMVC/IO/File.php | 6 ++++ AroMVC/{ => Routing}/Router.php | 2 +- conf.ini | 3 ++ index.php | 21 ++++++++------ 15 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 AroMVC/Base/Controller.php rename AroMVC/{ => Base}/Model.php (71%) rename AroMVC/{ => Configuration}/ConfigSection.php (95%) rename AroMVC/{ => Configuration}/Configuration.php (95%) rename AroMVC/{ => Database}/Database.php (97%) rename AroMVC/{ => Database}/Deletable.php (61%) rename AroMVC/{ => Database}/Insertable.php (61%) rename AroMVC/{ => Database}/Modifiable.php (61%) rename AroMVC/{ => Database}/Queryable.php (98%) rename AroMVC/{ => Database}/Selectable.php (99%) create mode 100644 AroMVC/IO/Directory.php create mode 100644 AroMVC/IO/File.php rename AroMVC/{ => Routing}/Router.php (50%) diff --git a/AroMVC/Base/Controller.php b/AroMVC/Base/Controller.php new file mode 100644 index 0000000..f6af385 --- /dev/null +++ b/AroMVC/Base/Controller.php @@ -0,0 +1,6 @@ +initialize(); return $new; @@ -29,8 +29,8 @@ abstract class Model { } protected abstract function initialize(); - protected function setTable(string $tableName) { - $this->table = $tableName; + protected static function getTable(): string { + return self::$table ?? get_class(new static); } protected function get(string $name) { @@ -53,11 +53,15 @@ abstract class Model { $name = strtolower($name); if(array_key_exists($name, $this->associations)) - $rawData[$this->associations[$name]] = $value; + $modified = $this->associations[$name]; else if(array_key_exists($name, $this->rawData)) - $rawData[$name] = $value; + $modified = $name; else throw new \Exception("Cannot set the value for property '$name'."); + + $rawData[$modified] = $value; + if(!in_array($modified, $this->modified)) + $this->modified[] = $modified; } protected function addHook(string $name, $func) { @@ -69,14 +73,22 @@ abstract class Model { } public static function select(): Selectable { - return db::select("*", new static)->from(self::$table); + return db::select("*", new static)->from(self::getTable()); } public function update() { + if(count($this->modified) == 0) + return; + var $query = db::update(self::getTable()); + foreach($this->modified as $field) + // TODO set ... value + + db::batchQuery($query); + $this->modified = []; } - public function delete() { + public function delete(): void { } } \ No newline at end of file diff --git a/AroMVC/ConfigSection.php b/AroMVC/Configuration/ConfigSection.php similarity index 95% rename from AroMVC/ConfigSection.php rename to AroMVC/Configuration/ConfigSection.php index 13af851..a53f473 100644 --- a/AroMVC/ConfigSection.php +++ b/AroMVC/Configuration/ConfigSection.php @@ -1,5 +1,5 @@ value("namespace"); + $class = str_replace("_", "\\", $class); $class = ltrim($class, '\\'); $parts = explode("\\", $class); if($parts[0] == "AroMVC") { - if(count($parts) < 3) + if(count($parts) < 2) die("Autoloader failed: malformed class name $class"); if($parts[1] == "Core") require_once "AroMVC". DIRECTORY_SEPARATOR . $parts[2] .".php"; - else if(in_array($parts[1], ["Controllers", "Models", "ViewModels"])) - require_once $parts[1]. DIRECTORY_SEPARATOR. $parts[2] .".php"; else die("Autoloader failed: malformed class name $class"); + } else if($parts[0] == $userns) { + if(in_array($parts[1], ["Controllers", "Models", "ViewModels"])) + require_once $parts[1]. DIRECTORY_SEPARATOR. $parts[2] .".php"; } }); // TODO write error handler -Configuration::initialize(file_get_contents("conf.ini")); -Database::initialize(); - $tmp = new Selectable("*"); $tmp->from("Companies")