Implementing a dirty to string method
This commit is contained in:
+21
-9
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user