Set a virtual property

@param Entity $entity
@param string $name
@param Entity $value
@throws RelationException
@throws \Exception
776375
public function setLazy($entity, $name, $value)
    {
        // Verify if virtual property exists, if not then just don't set it!
        if (! in_array($name, $this->getEntityStructure($entity)->relationProperties)) {
            return;
        }

        // Verify if value is also an entity!
        if (! $value instanceof Entity && $value !== null) {
            throw new RelationException("Property '".$name."' is a reference to a relationship, you should set the entity of that relationship!");
        }

        // Pass to the relationmanager
        RelationManager::with($entity)->set($name, $value);
    }
772371
public function set($name, $value)
    {
        $this->stale = true;

        try {
            if ($value === null) {
                $this->model->where('name', '=', $name)->delete();
            } else {
                $this->model->updateOrCreate(compact('name'), compact('value'));
            }
        } catch (Exception $e) {
            throw new WriteException($e);
        }
    }
928754
private void setRelationToEntity(Object entity, Object relationEntity, Relation relation)
    {
        if (relation.getTargetEntity().isAssignableFrom(getEntity(relationEntity).getClass()))
        {

            if (relation.isUnary())
            {
                PropertyAccessorHelper.set(entity, relation.getProperty(), getEntity(relationEntity));
            }
            else
            {
                Object associationObject = PropertyAccessorHelper.getObject(entity, relation.getProperty());
                if (associationObject == null || ProxyHelper.isProxyOrCollection(associationObject))
                {
                    associationObject = PropertyAccessorHelper.getCollectionInstance(relation.getProperty());
                    PropertyAccessorHelper.set(entity, relation.getProperty(), associationObject);
                }

                ((Collection) associationObject).add(getEntity(relationEntity));
            }
        }
    }
634737
public function assignChild ($relationIdentifier, $id, $childId)
		{
			$relation = $this->getRelation($relationIdentifier);

			if (!$relation) {
				throw new RelationException('Invalid relation `' . $relationIdentifier);
			}

			if ($relation instanceof OneToMany) {
				$this->database->createQuery()
					->update()
					->table($relation->getRelatedTable())
					->set(
						array(
							$relation->getRelatedKey() => $id,
						)
					)
					->whereEqual($relation->getKey(), $childId)
					->execute();
			} else if ($relation instanceof ManyToMany) {
				if (! $this->getChild($relationIdentifier, $id, $childId)) {
					$this->database->createQuery()
						->insert()
						->into($relation->getRelationalTable())
						->set(
							array(
								$relation->getKey()         => $id,
								$relation->getRelatedKey()  => $childId,
							)
						)
						->execute();
				}
			} else {
				throw new RelationException('Invalid relation type `' . gettype($relation) . '`');
			}
		}
1209864
public function setEntityType(string $entityType): void {
		if (!class_exists($entityType)) {
			throw new EntityFactoryException("Unknown entity: $entityType.", EntityFactoryException::UNKNOWN_ENTITY);
		}
		
		// now that we know a class with the name of entityType exists, we need
		// to see if it is an implementation of our EntityInterface object.  the
		// use of the Aura DI container to inject dependencies seems to prevent
		// the use of the PHP is_a() and is_subclass_of() functions.  instead,
		// we'll try to instantiate it like it's an EntityInterface and then we
		// can use the instanceof operator to be sure.
		
		$this->entityType = $entityType;
		$temp = $this->newEntity([]);
		
		if (!($temp instanceof EntityInterface)) {
			
			// if that didn't work, then not only do we want to throw an
			// exception, but we also want to be sure that we set the
			// entityType property back to null so that it doesn't accidentally
			// get used elsewhere after the exception is caught.
			
			$this->entityType = null;
			throw new EntityFactoryException("Not an entity: $entityType.", EntityFactoryException::NOT_AN_ENTITY);
		}
	}
1007949
public function set($name, $value)
    {
        if (property_exists($this, $name)) {
            $this->$name = $value;

            return true;
        }

        return null;
    }
873636
public function processPreSet($entity, $name, &$value, $locale=null, $hook=true, $silentException=false) {
		if($hook)
			$this->trigger('set', [$entity, $name, &$value, $locale]);

		if($this->hasProperty($name)) {
			if($this->property($name)->get('hooks.set')) {
				$hook = $this->property($name)->get('hooks.set');
				$value = call_user_func_array($hook, [$value, $entity]);
			}

			if($this->property($name)->get('i18n')) {
				if($locale == 'all') {
					$val = [];
					foreach($value as $one => $v)
						$val[$one] = $this->property($name)->setDecorator($v, $entity, $name, $silentException);
					$value = $val;
				}
				else
					$value = $this->property($name)->setDecorator($value, $entity, $name, $silentException);
			}
			else
				$value = $this->property($name)->setDecorator($value, $entity, $name, $silentException);
		}
	}
908825
public function set(string $key, $value): void {
		if (!property_exists($this, $key)) {
			throw new EntityException(
				sprintf("Unknown property (%s) in %s.", $key, get_class()),
				EntityException::UNKNOWN_PROPERTY
			);
		}
		
		$this->{$key} = $value;
	}
843736
public function set($name, $value = null)
    {
        $property = $this->getEntityDescription()->getProperty($name);

        if (!$property instanceof AnDomainPropertyAbstract) {
            return parent::set($name, $value);
        }

        //if a value is mixin then get its mixer
        if ($value instanceof AnMixinAbstract) {
            $value = $value->getMixer();
        }

        $modify = false;
        $name = $property->getName();

        $context = $this->getRepository()->getCommandContext();

        $context['property'] = $property;
        $context['value'] = $value;
        $context['entity'] = $this;

        if ($this->getRepository()->getCommandChain()->run('before.setdata', $context) === false) {
            return $this;
        }

        $value = $context->value;

        if ($property->isSerializable()) {
            $modify = true;
            if ($property->isRelationship() && $property->isManyToOne() && $value) {
                if (!is($value, 'AnDomainEntityAbstract', 'AnDomainEntityProxy')) {
                    throw new AnDomainExceptionType('Value of '.$property->getName().' must be a AnDomainEntityAbstract');
                }

                //if a relationship is a belongs to then make sure the parent
                //is always saved before child
                //example if $topic->author = new author
                //then save the new author first before saving topic
                //only set the dependency
                if ($value->getEntityState() == AnDomain::STATE_NEW) {
                    //save the child before saving the parent
                    $this->getRepository()->getSpace()->setSaveOrder($value, $this);
                }
            }
            //if value is not null do a composite type checking
            if (!is_null($value)) {
                if ($property->isAttribute() && !$property->isScalar()) {
                    if (!is($value, $property->getType())) {
                        throw new AnDomainEntityException('Value of '.$property->getName().' must be a '.$property->getType().'. a '.get_class($value).' is given.');
                    }
                }
            }
        } elseif ($property->isRelationship() && $property->isOnetoOne()) {
            $child = $property->getChildProperty();
            $current = $this->get($property->getName());

            //if there's a current value and it's existence depends on
            //the parent entity then remove the current
            if ($current && $child->isRequired()) {
                $current->delete();
            }

            //if a one-to-one relationship then there must be a child key for the property
            //then must set the inverse
            if ($value) {
                $value->set($child->getName(), $this);
            }

            $this->_data[$property->getName()] = $value;
        } elseif ($property->isRelationship() && ($property->isManyToMany() || $property->isOneToMany())) {
            $current = $this->get($name);

            if ($current instanceof AnDomainDecoratorOnetomany) {
                $values = AnConfig::unbox($value);
                //can be an AnObjectArray or AnObjectSet object
                if ($values instanceof AnObject && $values instanceof Iterator) {
                    $current->delete();

                    foreach ($values as $value) {
                        $current->insert($value);
                    }
                }
            }
        }

        //only modify if the current value is differnet than the new value
        $modify = $modify && !is_eql($this->get($name), $value);

        if ($modify) {
            //lets bring them back to their orignal type
            if (!is_null($value) && $property->isAttribute() && $property->isScalar()) {
                settype($value, $property->getType());
            }

            if ($this->getEntityState() != AnDomain::STATE_NEW) {
                //store the original value for future checking
                if (!isset($this->_modified[$name])) {
                    $this->_modified[$name] = array('old' => $this->get($name));
                }

                $this->_modified[$name]['new'] = $value;

                //check if the new value is the same as the old one then remove the
                if (is_eql($this->_modified[$name]['old'], $this->_modified[$name]['new'])) {
                    //if there are no modified then reset the entity
                    unset($this->_modified[$name]);

                    if (count($this->_modified) === 0) {
                        $this->reset();
                    }
                }
            }

            $this->_data[$property->getName()] = $value;
            $this->getRepository()->getSpace()->setEntityState($this, AnDomain::STATE_MODIFIED);

            //only track modifications for the updated entities
            if ($this->getEntityState() !== AnDomain::STATE_MODIFIED) {
                $this->_modified = array();
            }
        }

        return $this;
    }
779842
public function processPreAdd($entity, $name, &$value, $locale=null, $hook=true, $silentException=false) {
		if($hook)
			$this->trigger('set', [$entity, $name, &$value, $locale]);

		if(!$this->hasProperty($name))
			return;

		if($this->property($name)->get('hooks.set')) {
			$hook  = $this->property($name)->get('hooks.set');
			$value = call_user_func_array($hook, [$value, $entity]);
		}

		$value = $this->property($name)->_doSet($value, $entity, $name, $silentException);
	}
896639
public function addPropertyValue(&$entity, $field, $value)
    {
        $container = $this->getPropertyValue($entity, $field, $entity);

        if (!is_array($container)) {
            $container = empty($container) ? [] : [$container];
        }
        $container[] = $value;

        $this->setPropertyValue($entity, $field, $container);
    }
249866
public function setAttribute($name,$value){
        try{
            common_Logger::d('setattri ' . $name . ' => ' . $value);
            $this->dbConnector->setAttribute($name, $value);
            
        } catch (PDOException $e){
            common_Logger::e('Fail to set attribute ' . $name . ' with value ' . $value);
            throw $e;
        }
    
    }
1249097
public function set(string $name, $value)
    {
        $this->_data[$name] = $value;

        if(!is_object($value)) {
            $this->_changed[$name] = $value;
        }
    }
536417
public function setOption($name, $value)
    {
        if ($name == 'cached_entity') {
            $this->setCachedEntity($value);
        } else {
            parent::setOption($name, $value);
        }
    }
539166
private function setObjectProperty($entity, $name, $value)
    {
        $setter = 'set'.ucfirst($name);

        if (!method_exists($entity, $setter)) {
            throw RestException::missingSetter($entity, $name, $setter);
        }

        return $entity->$setter($value);
    }
1253727
public static function setValue($entity, $field, $value)
    {
        $entity->{'set' . ucfirst(Str::camel($field))}($value);
    }
127861
public function setRelated($alias, Model $entity) {
        $foundRelation = $this->getRelationship($alias);
        if($foundRelation instanceof CustomRelationship) {
            call_user_func(array($this, 'set' . ucfirst($alias)), $entity);
        } else {
            $attribute = $foundRelation->getFields();
            $value = $foundRelation->getReferencedFields();
            if(is_array($attribute)) {
                $count = sizeOf($attribute);
                for($i = 0; $i < $count; $i++) {
                    $this->writeAttribute($attribute[$i], $entity->readAttribute($value[$i]));
                }
            } else {
                $this->writeAttribute($attribute, $entity->readAttribute($value));
            }
        }
    }