- More work done on Update, Insert and Delete clause

- Added TOP property to select and delete to fit MSSQL limit's term.
- Added a new interface allowing object's manipulation on save() and load() queries
This commit is contained in:
Dave Mc Nicoll committed 2020-02-07 16:36:38 -05:00
1 parent 3dc82b1f0d
commit 2f43fb4559
13 files changed
+169 -58

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
<?php
namespace Ulmus\Entity;
interface EntityObjectInterface {
public function load(...$arguments);
public function save();
}
+2 -4
View File
@@ -2,13 +2,11 @@
namespace Ulmus\Entity\Field;
use DateTime;
class Date extends DateTime {
class Date extends Datetime {
public function __toString()
{
return $this->format("Y-m-d");
}
}
+21 -2
View File
@@ -2,11 +2,30 @@
namespace Ulmus\Entity\Field;
class Datetime extends \DateTime {
use Ulmus\Entity\EntityObjectInterface;
class Datetime extends \DateTime implements EntityObjectInterface {
public function load(...$arguments)
{
$value = $arguments[0];
# From Timestamp
if ( is_numeric($value) ) {
return new static("@$value");
}
return new static($value);
}
public function save()
{
return $this->getTimestamp();
}
public function __toString()
{
return $this->format("Y-m-d H:i:s");
}
}
}
+1 -3
View File
@@ -2,9 +2,7 @@
namespace Ulmus\Entity\Field;
use DateTime;
class Time extends DateTime {
class Time extends Datetime {
public function __toString()
{
+12
View File
@@ -11,11 +11,23 @@ class ObjectInstanciator {
if ( isset($this->objectCallbackDefinition[$type]) ) {
return $this->objectCallbackDefinition[$type](...$arguments);
}
elseif ( ($obj = new $type() ) instanceof EntityObjectInterface ) {
return $obj->load(...$arguments);
}
else {
return new $type(...$arguments);
}
}
public function convert(object $obj)
{
if ( $obj instanceof EntityObjectInterface ) {
return $obj->save();
}
return (string) $obj;
}
public function registerObject(string $type, Callable $callback) : void
{
$this->objectCallbackDefinition[$type] = $callback;