Force developers to use the correct method to set props to entities
This commit is contained in:
parent
e778fc5532
commit
fc1daab3dd
|
@ -150,13 +150,33 @@ class Entity {
|
|||
|
||||
/**
|
||||
* set the value of a mapped property
|
||||
*
|
||||
* This is a protected method. If you want to set an entity prop
|
||||
* using the prop name dynamically, use the set() method
|
||||
*
|
||||
* @param string $prop id of the property
|
||||
* @param mixed $value the value to be setted
|
||||
*/
|
||||
public function set_mapped_property($prop, $value) {
|
||||
protected function set_mapped_property($prop, $value) {
|
||||
$this->set_validated(false);
|
||||
$this->$prop = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* set 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 set($prop, $value) {
|
||||
$method = 'set_' . $prop;
|
||||
if ( method_exists($this, $method) ) {
|
||||
return $this->$method($value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the status of the entity
|
||||
|
|
|
@ -145,7 +145,7 @@ class Collections extends TAINACAN_UnitTestCase {
|
|||
$autor1_id,
|
||||
];
|
||||
|
||||
$collection_test->set_moderators_ids($moderators_ids);
|
||||
$collection_test->set('moderators_ids', $moderators_ids);
|
||||
|
||||
$this->assertEquals(2, sizeof( $collection_test->get_moderators_ids() ));
|
||||
|
||||
|
|
Loading…
Reference in New Issue