Removes try catch and use dinamic methods set and get
This commit is contained in:
parent
df4f90f974
commit
d8300243be
|
@ -24,22 +24,12 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
|
||||
if (is_array($attributes)) {
|
||||
foreach ( $attributes as $attribute ) {
|
||||
try {
|
||||
if(!is_array($attribute)) {
|
||||
$get_ = 'get_' . $attribute;
|
||||
$object_filtered[ $attribute ] = $object->$get_();
|
||||
}
|
||||
} catch ( \Exception $error ) {
|
||||
// Do nothing
|
||||
if ( ! is_array( $attribute ) ) {
|
||||
$object_filtered[ $attribute ] = $object->get( $attribute );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try{
|
||||
$get_ = 'get_' . $attributes;
|
||||
$object_filtered[$attributes] = $object->$get_();
|
||||
} catch (\Exception $error){
|
||||
// Do nothing
|
||||
}
|
||||
$object_filtered[ $attributes ] = $object->get( $attributes );
|
||||
}
|
||||
|
||||
return $object_filtered;
|
||||
|
@ -54,12 +44,7 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
protected function prepare_item_for_updating($object, $new_values){
|
||||
|
||||
foreach ($new_values as $key => $value) {
|
||||
try {
|
||||
$set_ = 'set_' . $key;
|
||||
$object->$set_( $value );
|
||||
} catch (\Exception $error){
|
||||
// Do nothing
|
||||
}
|
||||
$object->set($key, $value);
|
||||
}
|
||||
|
||||
return $object;
|
||||
|
|
|
@ -128,12 +128,7 @@ class REST_Filters_Controller extends REST_Controller {
|
|||
$filter_type = new $type();
|
||||
|
||||
foreach ($filter as $attribute => $value){
|
||||
try {
|
||||
$set_ = 'set_'. $attribute;
|
||||
$filter_obj->$set_($value);
|
||||
} catch (\Exception $error){
|
||||
//
|
||||
}
|
||||
$filter_obj->set($attribute, $value);
|
||||
}
|
||||
|
||||
if(isset($request['collection_id']) && isset($request['field_id'])) {
|
||||
|
|
|
@ -86,13 +86,7 @@ class REST_Terms_Controller extends REST_Controller {
|
|||
$taxonomy = $to_prepare[1];
|
||||
|
||||
foreach ($attributes as $attribute => $value){
|
||||
$set_ = 'set_'. $attribute;
|
||||
|
||||
try {
|
||||
$this->term->$set_( $value );
|
||||
} catch (\Exception $error){
|
||||
// Do nothing
|
||||
}
|
||||
$this->term->set($attribute, $value);
|
||||
}
|
||||
|
||||
$this->term->set_taxonomy($taxonomy);
|
||||
|
|
|
@ -191,9 +191,23 @@ class Entity {
|
|||
if ( method_exists($this, $method) ) {
|
||||
return $this->$method($value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the value property
|
||||
*
|
||||
*
|
||||
* @param string $prop id of the property
|
||||
* @param mixed $value the value to be setted
|
||||
* @return null|mixed Null on failure, the value that was set on success
|
||||
*/
|
||||
public function get($prop) {
|
||||
$method = 'get_' . $prop;
|
||||
if ( method_exists($this, $method) ) {
|
||||
return $this->$method();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the status of the entity
|
||||
* @param string $value
|
||||
|
|
Loading…
Reference in New Issue