public function set($property, $value = null, array $options = [])
    {
        if (is_string($property) && $property !== '') {
            $guard = false;
            $property = [$property => $value];
        } else {
            $guard = true;
            $options = (array)$value;
        }

        if (!is_array($property)) {
            throw new InvalidArgumentException('Cannot set an empty property');
        }
        $options += ['setter' => true, 'guard' => $guard];

        foreach ($property as $p => $value) {
            if ($options['guard'] === true && !$this->isAccessible($p)) {
                continue;
            }

            $this->setDirty($p, true);

            if (!array_key_exists($p, $this->_original) &&
                array_key_exists($p, $this->_properties) &&
                $this->_properties[$p] !== $value
            ) {
                $this->_original[$p] = $this->_properties[$p];
            }

            if (!$options['setter']) {
                $this->_properties[$p] = $value;
                continue;
            }

            $setter = static::_accessor($p, 'set');
            if ($setter) {
                $value = $this->{$setter}($value);
            }
            $this->_properties[$p] = $value;
        }

        return $this;
    }
public function set($property, $value = null, array $options = [])
    {
        if (is_string($property) && $property !== '') {
            $guard = false;
            $property = [$property => $value];
        } else {
            $guard = true;
            $options = (array)$value;
        }

        if (!is_array($property)) {
            throw new InvalidArgumentException('Cannot set an empty property');
        }
        $options += ['setter' => true, 'guard' => $guard];

        foreach ($property as $p => $value) {
            if ($options['guard'] === true && !$this->isAccessible($p)) {
                continue;
            }

            $this->setDirty($p, true);

            if (!array_key_exists($p, $this->_original) &&
                array_key_exists($p, $this->_properties) &&
                $this->_properties[$p] !== $value
            ) {
                $this->_original[$p] = $this->_properties[$p];
            }

            if (!$options['setter']) {
                $this->_properties[$p] = $value;
                continue;
            }

            $setter = static::_accessor($p, 'set');
            if ($setter) {
                $value = $this->{$setter}($value);
            }
            $this->_properties[$p] = $value;
        }

        return $this;
    }
public function set ( $ property , $ value = null , array $ options = [ ] ) { if ( is_string ( $ property ) && $ property !== '' ) { $ guard = false ; $ property = [ $ property => $ value ] ; } else { $ guard = true ; $ options = ( array ) $ value ; } if ( ! is_array ( $ property ) ) { throw new InvalidArgumentException ( 'Cannot set an empty property' ) ; } $ options += [ 'setter' => true , 'guard' => $ guard ] ; foreach ( $ property as $ p => $ value ) { if ( $ options [ 'guard' ] === true && ! $ this -> isAccessible ( $ p ) ) { continue ; } $ this -> setDirty ( $ p , true ) ; if ( ! array_key_exists ( $ p , $ this -> _original ) && array_key_exists ( $ p , $ this -> _properties ) && $ this -> _properties [ $ p ] !== $ value ) { $ this -> _original [ $ p ] = $ this -> _properties [ $ p ] ; } if ( ! $ options [ 'setter' ] ) { $ this -> _properties [ $ p ] = $ value ; continue ; } $ setter = static :: _accessor ( $ p , 'set' ) ; if ( $ setter ) { $ value = $ this -> { $ setter } ( $ value ) ; } $ this -> _properties [ $ p ] = $ value ; } return $ this ; }
Sets a single property inside this entity.

### Example:

```
$entity->set('name', 'Andrew');
```

It is also possible to mass-assign multiple properties to this entity
with one call by passing a hashed array as properties in the form of
property => value pairs

### Example:

```
$entity->set(['name' => 'andrew', 'id' => 1]);
echo $entity->name // prints andrew
echo $entity->id // prints 1
```

Some times it is handy to bypass setter functions in this entity when assigning
properties. You can achieve this by disabling the `setter` option using the
`$options` parameter:

```
$entity->set('name', 'Andrew', ['setter' => false]);
$entity->set(['name' => 'Andrew', 'id' => 1], ['setter' => false]);
```

Mass assignment should be treated carefully when accepting user input, by default
entities will guard all fields when properties are assigned in bulk. You can disable
the guarding for a single set call with the `guard` option:

```
$entity->set(['name' => 'Andrew', 'id' => 1], ['guard' => true]);
```

You do not need to use the guard option when assigning properties individually:

```
// No need to use the guard option.
$entity->set('name', 'Andrew');
```

@param string|array $property the name of property to set or a list of
properties with their respective values
@param mixed $value The value to set to the property or an array if the
first argument is also an array, in which case will be treated as $options
@param array $options options to be used for setting the property. Allowed option
keys are `setter` and `guard`
@return $this
@throws \InvalidArgumentException
Sets a single property inside this entity .