not much
wewmy
This commit is contained in:
parent
4fd5e5fbd9
commit
f642090d47
15 changed files with 64 additions and 28 deletions
6
AroMVC/Base/Controller.php
Normal file
6
AroMVC/Base/Controller.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
namespace AroMVC\Base;
|
||||
|
||||
class Controller {
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
use AroMVC\Core\Database as db;
|
||||
namespace AroMVC\Base;
|
||||
use AroMVC\Database\Database as db;
|
||||
|
||||
abstract class Model {
|
||||
protected $rawData = [];
|
||||
|
@ -14,7 +14,7 @@ abstract class Model {
|
|||
|
||||
public function __construct() {}
|
||||
public static function withId(int $id) {
|
||||
$new = new static();
|
||||
$new = new static;
|
||||
$new->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 {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Configuration;
|
||||
|
||||
class ConfigSection {
|
||||
protected $name = null;
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Configuration;
|
||||
|
||||
define("AMVC_CNF_DB", "Database");
|
||||
define("AMVC_CNF_DB_DSN", "dsn");
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
use AroMVC\Core\Configuration as conf;
|
||||
namespace AroMVC\Database;
|
||||
use AroMVC\Configuration\Configuration as conf;
|
||||
|
||||
define("AMVC_DB_FETCH_VOID", 0);
|
||||
define("AMVC_DB_FETCH_SCALAR", 1);
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Database;
|
||||
|
||||
class Deletable extends Queryable {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Database;
|
||||
|
||||
class Insertable extends Queryable {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Database;
|
||||
|
||||
class Modifiable extends Queryable {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Database;
|
||||
use AroMVC\Core\Database as db;
|
||||
|
||||
abstract class Queryable {
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Database;
|
||||
|
||||
define("AMVC_QRY_SEL_LCK_JOIN", 1);
|
||||
|
6
AroMVC/IO/Directory.php
Normal file
6
AroMVC/IO/Directory.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
namespace AroMVC\IO;
|
||||
|
||||
class Directory {
|
||||
|
||||
}
|
6
AroMVC/IO/File.php
Normal file
6
AroMVC/IO/File.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
namespace AroMVC\IO;
|
||||
|
||||
class File {
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace AroMVC\Core;
|
||||
namespace AroMVC\Routing;
|
||||
|
||||
class Router {
|
||||
|
3
conf.ini
3
conf.ini
|
@ -1,3 +1,6 @@
|
|||
[Project]
|
||||
namespace = "Fire"
|
||||
|
||||
[Database]
|
||||
dsn = "mysql:host=localhost;dbname=test"
|
||||
username = "root"
|
||||
|
|
21
index.php
21
index.php
|
@ -1,33 +1,36 @@
|
|||
<?php
|
||||
namespace AroMVC;
|
||||
use AroMVC\Core\Configuration;
|
||||
use AroMVC\Core\Database;
|
||||
use AroMVC\Core\Selectable;
|
||||
use AroMVC\Configuration\Configuration as conf;
|
||||
use AroMVC\Database\Database as db;
|
||||
use AroMVC\Database\Selectable;
|
||||
use AroMVC\Models\Company;
|
||||
|
||||
conf::initialize(file_get_contents("conf.ini"));
|
||||
db::initialize();
|
||||
|
||||
spl_autoload_register(function($class) {
|
||||
$userns = Configuration::section("Project")->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")
|
||||
|
|
Reference in a new issue