public function ECKEntity::__set in Entity Construction Kit (ECK) 7.3
Magic set.
File
- ./
eck.classes.inc, line 798 - Classes for all the different objects used in ECK.
Class
Code
public function __set($name, $value) {
// Lets implement non restrictive validation.
// If it is a property validate, if it isn't just set it.
// Try to load the entityType and property information.
if ($entity_type_name = $this
->entityType()) {
if (($entity_type = EntityType::loadByName($entity_type_name)) && is_object($entity_type)) {
if ($properties = $entity_type->properties) {
$property_names = array_keys($properties);
}
}
}
// @todo should look into loading the entity info through entity_get_info()
// and determining validation that way.
// Currently we don't validate when the ECKEntityType has not been
// instantiated yet. Not sure if it is needed though.
if (isset($property_names) && in_array($name, $property_names) && !$this->ignoreValidation) {
$property_type = $properties[$name]['type'];
$property_type_class = eck_get_property_type_class($property_type);
if (!isset($value)) {
$schema = $property_type_class::schema();
if (isset($schema['default'])) {
$this->PropertyValues[$name] = $schema['default'];
}
}
elseif ($property_type_class::validate($value)) {
$this->PropertyValues[$name] = $value;
}
else {
throw new Exception("Invalid value {$value} for property {$name} of type {$property_type} in\n Entity type: {$entity_type_name}");
}
}
else {
$this->{$name} = $value;
}
}