add

When the corresponding attribute is an array, call this method
to set values.

@access public
@param  string         $var
@param  mixed          $value
@return FlexibleEntity $this
@throws ModelException
437144
public function add($var, $value)
    {
        if ($this->has($var)) {
            if (is_array($this->container[$var])) {
                $this->container[$var][] = $value;
            } else {
                throw new ModelException(sprintf("Field '%s' exists and is not an array.", $var));
            }
        } else {
            $this->container[$var] = [$value];
        }
        $this->touch();

        return $this;
    }
296919
public function set($var, $value = null)
	{
		if ( ! is_array($var))
		{
			$var = array ($var => $value);
		}

		foreach ($var as $key => $value)
		{
			$value = $this->validateConfig($key, $value);

			if (isset($this->config[$key]))
			{
				// preserve the type
				if (is_bool($this->config[$key]))
				{
					$this->config[$key] = (bool) $value;
				}
				elseif (is_string($this->config[$key]))
				{
					$this->config[$key] = (string) $value;
				}
				else
				{
					$this->config[$key] = (int) $value;
				}
			}
		}
	}
291679
public function set($attribute, $value=null) :self {
		// array is passed
		if(is_array($attribute)) {
			// for each associative value in the array
			foreach($attribute as $single_attribute => $single_value) {
				// recurse with a single pair or attribute/value
				$this->set($single_attribute, $single_value);
			}
			// return self
			return($this);
		}
		// specific case of text
		if($attribute == 'text') {
			// use the setter
			$this->setText($value);
		}
		// specific case of html
		elseif($attribute == 'html') {
			// use the setter
			$this->setHtml($value);
		}
		// specific case of style
		elseif($attribute == 'style' && is_array($value)) {
			// use the setter
			$this->setStyle($value);
		}
		// specific case of value
		elseif($attribute == 'value') {
			// use the setter
			$this->setValue($value);
		}
		// any normal attribute
		else {
			// if the value is an array we assemble its content or we set directly
			$this->attributes[$attribute] = is_array($value) ? implode(' ', $value) : $value;
		}
		// return self
		return($this);
	}
710013
public function addItem($value)
    {
        if ($value instanceof LayoutItem) {
            $value = $value->jsonSerialize();
        } elseif (!is_array($value)) {
            throw new DomainException('Invalid layout item');
        }

        $items = $this->getAttribute('items') ?: [];
        $items[] = $value;

        return $this->setAttribute('items', $items);
    }
760857
public function setVar($name, $value)
    {
        $context = $this->_context;

        $context->vars[$name] = $value;

        return $this;
    }
525158
public function setType($value)
    {
        if (!in_array($value, self::allowedRejectionTypes(), true)) {
            throw new DomainException(self::MSG_UNSUPPORTED_TYPE);
        }

        return $this->setAttribute('type', $value);
    }
297064
final public function set($varname, $value)
    {

        //If its lock we can't edit
        if ($this->lock)
            return false;

        //Continue
        $previous = isset($this->data[$varname]) ? $this->data[$varname] : null;
        $this->data[$varname] = $value;

        //what to do with previous?

        return $this;
    }
1051625
public function set($key, $value = '')
    {
        if (is_array($key)) {
            foreach ($key as $k => $v) {
                if ($k !== '$id') {
                    $this->set($k, $v);
                }
            }
        } elseif ($key === '$id') {
            throw new Exception('[Norm/Model] Restricting set for $id.');
        } else {
            $this->attributes[$key] = $this->prepare($key, $value);
        }

        return $this;
    }
1287355
public function setData(
        array $value)
    {
        $this->_cache = $value;

        $newObjectData = [];
        foreach ($this->_cache as $k => $v) {
            $newObjectData[$k] = is_object($v) && $v instanceof LazyJsonMapper
                               ? $v->asArray() // Throws.
                               : $v; // Is already a valid value.
        }

        $this->assignObjectData($newObjectData); // Throws.

        return $this;
    }
628685
public function set($name, $value = null): self
    {
        if (!is_array($name)) {
            $name = [$name => $value];
        }

        foreach ($name as $property => $value) {
            $this->_data[$property] = $value;
        }

        return $this;
    }
705288
public function set($name, $value = UNDEFINED)
    {
        if (is_array($name)) {
            foreach ($name as $key => $val) {
                $this->set($key, $val);
            }

            return $this;
        }
        if ($name === false || $name === null) {
            return $this->reset();
        }

        // Verify if such a field exists
        if ($this->strict_fields && !$this->hasElement($name)) {
            throw $this->exception('No such field', 'Logic')
            ->addMoreInfo('name', $name);
        }

        if ($value !== UNDEFINED
            && (
                is_object($value)
                || is_object($this->data[$name])
                || is_array($value)
                || is_array($this->data[$name])
                || (string) $value != (string) $this->data[$name] // this is not nice..
                || $value !== $this->data[$name] // considers case where value = false and data[$name] = null
                || !isset($this->data[$name]) // considers case where data[$name] is not initialized at all
                                              //    (for example in model using array controller)
            )
        ) {
            $this->data[$name] = $value;
            $this->setDirty($name);
        }

        return $this;
    }
1368217
public function setAttribute($key, $value = null)
    {
        if (is_array($key) && is_null($value)) {
            $this->attributes = $key;
        } else {
            array_set($this->attributes, $key, $value);
        }

        return $this;
    }
870384
public function add($value): AbstractArray
    {
        $value = $this->filterValue($value);
        if (is_null($value)) {
            return $this;
        }

        if (!in_array($value, $this->values)) {
            array_push($this->values, $value);
        }

        $this->atomics['$addToSet']['$each'][] = $value;

        return $this;
    }
180132
public function setValue($value) {
		if ($value instanceof \ArrayObject)
			$this->value = $value->getArrayCopy();
		elseif (is_object($value))
			$this->value = get_object_vars($value);
		elseif (is_array($value))
			$this->value = $value;
		else
			throw new \InvalidArgumentException("Method 'setValue' expected an object or array value");
		
		return $this;
	}
96074
public function model($var, $model = null, $exception = true)
    {
        if ($var instanceof \Closure) {
            $this->option['model'][] = $var;
        } elseif (is_array($var)) {
            $this->option['model'] = $var;
        } elseif (is_null($model)) {
            $this->option['model']['id'] = [$var, true];
        } else {
            $this->option['model'][$var] = [$model, $exception];
        }

        return $this;
    }
459551
public function setAttribute(string $attribute, $value = []): self
    {
        $this->attributes[$attribute] = $this->wrap($value);

        return $this;
    }
942930
public function setRelated($value)
    {
        $this->loadData(true);

        if (is_null($value)) {
            $value = [];
        }

        if (!is_array($value)) {
            throw new RelationException("HasMany relation can only be set with array of entities");
        }

        //Do not add items twice
        $matched = [];
        foreach ($value as $index => $item) {
            if (is_null($item)) {
                unset($value[$index]);
                continue;
            }

            $this->assertValid($item);
            if (!empty($instance = $this->matchOne($item))) {
                $matched[] = $instance;
                unset($value[$index]);
            }
        }

        $this->deleteInstances = array_diff($this->instances, $matched);
        $this->instances = $matched + $value;
    }