Implementing a dirty to string method

This commit is contained in:
ahwelp
2019-03-21 04:33:37 +00:00
parent 57f3f7ec8e
commit 75c82cde78
+21 -9
View File
@@ -19,15 +19,7 @@ abstract class Entity {
const _properties = Array();
public static function get_properties() {
$properties = Array();
foreach (static::_properties as $propertie) {
$obj = new \stdClass();
$obj->data = $propertie;
$properties[] = $obj;
}
return json_encode($properties);
}
function __construct() {
if (isset($this->timestamps) && $this->timestamps) {
@@ -43,6 +35,26 @@ abstract class Entity {
$this->$property = $value;
}
public function __toString(){
if(isset($this->name)){
return $this->name;
}
if(isset($this->nome)){
return $this->nome;
}
return static::class;
}
public static function get_properties() {
$properties = Array();
foreach (static::_properties as $propertie) {
$obj = new \stdClass();
$obj->data = $propertie;
$properties[] = $obj;
}
return json_encode($properties);
}
public function save() {
if (isset($this->id)) {
$this->update();