Register an extension.

@param array $attributes
@return $this
@throws \Exception
176271
public function register(array $attributes)
    {
        $validator = $this->getValidationFactory()->make($attributes, [
            'type'                 => 'required',
            'name'                 => 'required',
            'parameters.class'     => 'required_if:type,widget',
            'parameters.templates' => 'required_if:type,widget',
            'parameters.template'  => 'required_if:type,menu',
        ]);

        if ($validator->fails()) {
            throw new InvalidManifestException("Invalid manifest file detected!");
        }

        $extension       = new Extension;
        $extension->type = $attributes['type'];
        $extension->name = $attributes['name'];
        if (isset($attributes['protected'])) {
            $extension->protected = $attributes['protected'];
        }
        if (isset($attributes['parameters'])) {
            $extension->parameters = $attributes['parameters'];
        }
        $extension->manifest = $attributes;
        $extension->save();

        return $this;
    }
521383
public function setAttributes($attributes)
    {
        foreach ($attributes as $key => $string_values) {
            $values = explode(' ', $string_values);

            // Trim the values
            $values = array_map('trim', $values);
            // Remove empty elements
            $values = array_filter($values);
            // Remove duplicate values
            $values = array_unique($values);

            $this->attributes[$key] = $values;
        }

        return $this;
    }
1072925
public function withAttributes(array $attributes = []): Element
    {
        $this->attributes = array_merge(
            $this->attributes,
            $attributes
        );

        return $this;
    }
81612
public function applyAttributes(array $attributes): ComponentInterface
    {
        if (count($attributes) > 0) {
            foreach ($attributes as $name => $value) {
                $this->setAttribute($name, $value);
            }
        }

        return $this;
    }
20688
public function map(array $attributes)
    {
        foreach ($attributes as $key => $value) {
            $this->{$key} = $value;
        }

        return $this;
    }
688106
public function setAttributes($attributes)
    {
        if (! is_array($attributes)) {
            $attributes = [$attributes];
        }

        $this->attributes = $attributes;

        return $this;
    }
580382
public static function create(array $attributes = [])
    {
        $user = new static($attributes);

        $user->setPassword($attributes['password']);

        $user->save();

        return $user;
    }
103220
public function addField($name, array $attributes)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $this->fields[$name] = $attributes;
        return $this;
    }
1047208
public static function fromArray(array $attributes)
    {
        $options = array_get($attributes, 'options', []);

        return new self($attributes['id'], $attributes['name'], $attributes['price'], $options);
    }
1324443
public function mergeWith(self $attributes)
    {
        $this->attributes = array_merge($this->attributes, $attributes->attributes);
        $this->classes = array_merge($this->classes, $attributes->classes);

        return $this;
    }
1325635
public function remove($attributes)
    {
        foreach ((array) $attributes as $attribute) {
            unset($this->defaults[$attribute],
                $this->types[$attribute],
                $this->requires[$attribute],
                $this->notNullables[$attribute]);
        }

        return $this;
    }
867163
public function setAttributes($attributes)
    {
        if (isset($attributes['class'])) {
            $class = $attributes['class'];
            $this->setClass([$class]);
            unset($attributes['class']);
        }
        $this->attributes = $attributes;
        return $this;
    }
695813
public function addField($name, array $attributes)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $this->addFields[$name] = $attributes;
        return $this;
    }
661649
public function containerAttributes(array $attributes = []): Builder
    {
        foreach ($this->containerAttributes as $name => $value) {
            if (is_null($param = array_get($attributes, $name))) {
                continue;
            }
            array_set($this->containerAttributes, $name, $value . ' ' . $param);
        }
        return $this;
    }
495515
public function update(array $attributes = [])
    {
        if (isset($attributes['password'])) {
            $attributes['password'] = bcrypt($attributes['password']);
        }

        if (!parent::update($attributes)) {
            throw new Exception('Cannot update user.'); // @codeCoverageIgnore
        }
        if (!parent::update($attributes)) {
            throw new Exception('Cannot update user.'); // @codeCoverageIgnore
        }

        return $this->fresh();
    }
449297
public function setAttributes(array $attributes = [])
    {
        $this->attributes = array_merge($this->attributes, $attributes);
        isset($attributes['id']) ? $this->id         = $attributes['id'] : null;
        return $this;
    }
1148503
public function mergeAttributes($attributes)
    {
        $attributes = self::prepareAttributes($attributes);
        foreach ($this->watchedAttributes as $watchedKey) {
            if (isset($attributes[$watchedKey])) {
                $this->onAttributeChange($watchedKey, $attributes[$watchedKey]);
                unset($attributes[$watchedKey]);
            }
        }
        $this->attributes = array_merge($this->attributes, $attributes);
        return $this;
    }