thankswave

woomwave
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-03-14 16:03:41 -05:00
parent 93a221c957
commit 3b0319fef8
4 changed files with 57 additions and 4 deletions

View file

@ -2,5 +2,5 @@
namespace AroMVC\Base; namespace AroMVC\Base;
abstract class Controller { abstract class Controller {
} }

View file

@ -21,7 +21,7 @@ abstract class Model {
->asArray(); ->asArray();
if(count($row) == 0) if(count($row) == 0)
throw new \Exception("Cannot instantiate new ". get_class(new static) ." with id '$id' because it does not exist"); throw new \Exception("Cannot instantiate new ". static::class ." with id '$id' because it does not exist");
return self::withRow($row[0]); return self::withRow($row[0]);
} }
@ -36,7 +36,7 @@ abstract class Model {
protected abstract function initialize(); protected abstract function initialize();
protected static function getTable(): string { protected static function getTable(): string {
$fqcn = get_class(new static); $fqcn = static::class;
return self::$table ?? substr($fqcn, strrpos($fqcn, "\\")+1); return self::$table ?? substr($fqcn, strrpos($fqcn, "\\")+1);
} }

View file

@ -2,5 +2,52 @@
namespace AroMVC\Database; namespace AroMVC\Database;
class Deletable extends Queryable { class Deletable extends Queryable {
protected $table = null;
protected $wheres = [];
protected $orders = [];
protected $limit = null;
public function __construct(string $table) {
$this->table = $table;
}
public function where(string $condition) : Deletable {
$this->wheres[] = $condition;
return $this;
}
public function orderBy($columns): Deletable {
if(!is_array($columns))
$columns = [$columns];
array_push($this->orders, $columns);
return $this;
}
public function limit(int $count): Deletable {
$this->limit = $count;
return $this;
}
public function execute() {
$sets = array_map(function($key) {
return "`$key` = :$key";
}, array_keys($this->params));
$this->query = implode(" ", ["UPDATE", "`$this->table`", "SET", implode(", ", $sets)]);
if(count($this->wheres) > 0) {
$this->query .= " WHERE " . implode(" AND ",
array_map(function($val) { return "($val)"; },
$this->wheres));
}
if(count($this->orders) > 0)
$this->query .= " ORDER BY " . implode(", ", $this->orders);
if($this->limit != null)
$this->query .= " LIMIT $this->limit";
parent::execute();
return $this;
}
} }

View file

@ -0,0 +1,6 @@
<?php
namespace AroMVC\Routing;
abstract class ActionResult {
}