Saves the instance of a class

@param string   $key
@param mixed $instance

@return void
165158
public function instance($key, $instance)
    {
        if (!is_object($instance)) {
            throw new \InvalidArgumentException('Le paramètre 2 est invalide');
        }

        $this->instances[$key] = $instance;
    }
521594
public function removeInstance(WidgetInstance $instance)
    {
        if ($this->instances->contains($instance)) {
            $this->instances->removeElement($instance);
        }
    }
1344091
public function setInstanceConfig($instanceConfig)
    {
        $this->instanceConfig = json_encode($instanceConfig);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(json_last_error_msg());
        }
    }
1369894
public function setInstance(PluginInstance $instance)
    {
        $this->instance = $instance;
        $this->pluginInstanceId = $instance->getInstanceId();
    }
1325565
protected function saveToCache(/*# string */ $key, $obj)
    {
        // clear stale cache
        if (isset($this->path_cache[$key[0]]) &&
            sizeof($this->path_cache[$key[0]]) > 1
        ) {
            $this->path_cache[$key[0]] = [];
        }

        $this->path_cache[$key[0]][$key] = $obj;
    }
1342712
public function updated($instance)
    {
        $before = $this->recordableAttributes(get_class($instance), $instance->getOriginal());

        $after = $this->recordableAttributes(get_class($instance), $instance->getAttributes());

        $instance->recordActivity('updated', $before, $after);
    }
1087333
public function form( $instance ) 
    {
        // Reset the names so that the form's update function works properly
        foreach ( $this->config->fields as $field )
        {
            $field->name = $field->init_name;
        }
        // Update values
        $this->form->updater->set_new_instance( $instance );
        $this->form->updater->update();
        
        // Set the widget specific field names and ids
        foreach ( $this->config->fields as $field )
        {
            $field->id   = $this->get_field_id( $field->init_name );
            $field->name = $this->get_field_name( $field->init_name );
        }
        
        // Print the form
        $this->form->render(true);
    }
1231718
public function remove($id, $instanceName)
    {
        $this->getConnection()->table($this->getTableName())
            ->where('id', $id)
            ->where('instance', $instanceName)
            ->delete();
    }
797588
public function set($name, $instance)
    {
        $key = $this->makeKey($name);

        $this->alias($name, $this->describe(get_class($instance)));

        $this->instances[$key] = $instance;

        return $this;
    }
1161212
public static function setInstance($instance)
    {
        if ($instance === null) {
            unset(Yii::getApp()->loadedModules[static::class]);
        } else {
            Yii::getApp()->loadedModules[\get_class($instance)] = $instance;
        }
    }
1263290
public function setInstance($instance)
    {
        $this->instance = $instance;
        $this->setClassName(get_class($this->instance));

        return $this;
    }
139930
public function addInstance(WidgetInstance $instance)
    {
        if (!$this->instances->contains($instance)) {
            $this->instances->add($instance);
            $instance->setContainer($this);
        }
    }
149400
public function deleted($instance)
    {
        $before = $this->recordableAttributes(get_class($instance), $instance->getAttributes());

        $instance->recordActivity('deleted', $before, null);
    }
538392
public function update_instance($instance, $data) {
        global $DB;
        $properties = array('status', 'name', 'password', 'customint1', 'customint2', 'customint3',
                            'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
                            'customchar1', 'customchar2', 'customchar3', 'customdec1', 'customdec2',
                            'customtext1', 'customtext2', 'customtext3', 'customtext4', 'roleid',
                            'enrolperiod', 'expirynotify', 'notifyall', 'expirythreshold',
                            'enrolstartdate', 'enrolenddate', 'cost', 'currency');

        foreach ($properties as $key) {
            if (isset($data->$key)) {
                $instance->$key = $data->$key;
            }
        }
        $instance->timemodified = time();

        $update = $DB->update_record('enrol', $instance);
        if ($update) {
            \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
        }
        return $update;
    }
930216
public function create(string $key = null)
    {
        if ($key) {
            $this->setStorageKey($key);
        }

        if ($this->exists()) {
            throw new \RuntimeException('Cannot create new object (Already exists)');
        }

        return $this->save();
    }
830388
protected function registerInstance($key, $name, $interface)
    {
        if (is_a($name, $interface, true)) {
            $instances = $this->getOption($key);
            if ($instances === null || array_search($name, $instances) === false) {
                $instances[] = $name;
                $this->setOption($key, $instances);
                $this->registerMetadataService();
            }
        }
    }
557227
@Override
    public void removeInstance(long key, T instance) {
    	if (first.value == key && instance == first.element) {
    		removeMin();
    		return;
    	}
    	if (last.value == key && instance == last.element) {
    		removeMax();
    		return;
    	}

    	// if both children of root are black, set root to red
    	if ((root.left == null || !root.left.red) && (root.right == null || !root.right.red))
            root.red = true;

        root = removeInstance(root, key, instance);
        if (root != null) root.red = false;
    }