The action that creates a new component instance.

@Action
@Logged
@param string $instanceName The name of the instance to create
@param string $instanceClass The class of the component to create
197092
public function createComponent($instanceName, $instanceClass, $selfedit) {
        $this->selfedit = $selfedit;

        if ($selfedit == "true") {
            $this->moufManager = MoufManager::getMoufManager();
        } else {
            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
        }


        $this->moufManager->declareComponent($instanceName, $instanceClass);
        $this->moufManager->rewriteMouf();

        // Redirect to the display component page:
        $this->displayComponent($instanceName, $selfedit);
    }
1231561
protected function invokeClass($instance, $action, $vars = []) {
        timer('controller response');
        if (is_string($instance)) {
            $instance = new $instance;
        }
        if (method_exists($instance, 'init')) {
            $instance->init();
        }
        if (method_exists($instance, 'invokeMethod')) {
            return call_user_func(array($instance, 'invokeMethod'), $action, $vars);
        }
        throw new Exception(
            __('UNKNOWN CLASS')
        );
    }
700390
public function deleteInstance($selfedit = "false", $instanceName=null, $returnurl = null) {
        $this->selfedit = $selfedit;

        if ($selfedit == "true") {
            $this->moufManager = MoufManager::getMoufManager();
        } else {
            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
        }

        $this->moufManager->removeComponent($instanceName);
        $this->moufManager->rewriteMouf();

        if ($returnurl) {
            header("Location:".$returnurl);
        } else {
            header("Location: .?selfedit=".$selfedit);
        }
    }
942013
protected function _buildInstance($instance, array $parameters = [])
  {
    if(is_scalar($instance) && class_exists($instance))
    {
      return Objects::create($instance, $parameters);
    }
    return $instance;
  }
335220
protected function finish_setup_course_module($instanceid) {
        global $DB, $USER;

        if (!$instanceid) {
            // Something has gone wrong - undo everything we can.
            course_delete_module($this->cm->id);
            throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
        }

        // Note the section visibility
        $visible = get_fast_modinfo($this->course)->get_section_info($this->section)->visible;

        $DB->set_field('course_modules', 'instance', $instanceid, array('id' => $this->cm->id));
        // Rebuild the course cache after update action
        rebuild_course_cache($this->course->id, true);

        $sectionid = course_add_cm_to_section($this->course, $this->cm->id, $this->section);

        set_coursemodule_visible($this->cm->id, $visible);
        if (!$visible) {
            $DB->set_field('course_modules', 'visibleold', 1, array('id' => $this->cm->id));
        }

        // retrieve the final info about this module.
        $info = get_fast_modinfo($this->course);
        if (!isset($info->cms[$this->cm->id])) {
            // The course module has not been properly created in the course - undo everything.
            course_delete_module($this->cm->id);
            throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
        }
        $mod = $info->get_cm($this->cm->id);

        // Trigger course module created event.
        $event = \core\event\course_module_created::create_from_cm($mod);
        $event->trigger();

        $this->send_response($mod);
    }
1118375
public void createInstance(
      final String my_instance_id, final String my_config_id, final String my_client_project) {
    // [START instance_admin_client_create_instance]
    final String instanceId = my_instance_id;
    final String configId = my_config_id;
    final String clientProject = my_client_project;

    OperationFuture<Instance, CreateInstanceMetadata> op =
        instanceAdminClient.createInstance(
            InstanceInfo.newBuilder(InstanceId.of(clientProject, instanceId))
                .setInstanceConfigId(InstanceConfigId.of(clientProject, configId))
                .setDisplayName(instanceId)
                .setNodeCount(1)
                .build());
    try {
      op.get();
    } catch (ExecutionException e) {
      throw (SpannerException) e.getCause();
    } catch (InterruptedException e) {
      throw SpannerExceptionFactory.propagateInterrupt(e);
    }
    // [END instance_admin_client_create_instance]
  }
1262003
public function form( $instance ) {
		parent::form( $instance );

		$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );

		$selected_menu = isset( $instance['menu'] ) ? $instance['menu'] : '';

		$menu_field_name = $this->get_menu_field_id();

		?>

		<p>

			<label for="<?php echo esc_attr( $menu_field_name ) ?>">Menu:</label>

			<select id="<?php echo esc_attr( $menu_field_name ) ?>"
					name="<?php echo esc_attr( $menu_field_name ) ?>">

				<?php foreach ( $menus as $menu ) : ?>

					<option value="<?php echo esc_attr( $menu->slug ) ?>"
						<?php selected( $selected_menu, $menu->slug ); ?> >
						<?php echo esc_html( $menu->name ) ?>
					</option>

				<?php endforeach ?>

			</select>

		</p>

		<?php
	}
456130
public function bindComponents($instanceName, $paramName, $paramValue) {
		if ($paramValue == null) {
			unset($this->declaredInstances[$instanceName]["fieldBinds"][$paramName]);
		} else {
			$this->declaredInstances[$instanceName]["fieldBinds"][$paramName] = $paramValue;
		}
	}
1344091
public function setInstanceConfig($instanceConfig)
    {
        $this->instanceConfig = json_encode($instanceConfig);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(json_last_error_msg());
        }
    }
580311
public function build(): EmulateTouchFromMouseEventRequest
	{
		$instance = new EmulateTouchFromMouseEventRequest();
		if ($this->type === null) {
			throw new BuilderException('Property [type] is required.');
		}
		$instance->type = $this->type;
		if ($this->x === null) {
			throw new BuilderException('Property [x] is required.');
		}
		$instance->x = $this->x;
		if ($this->y === null) {
			throw new BuilderException('Property [y] is required.');
		}
		$instance->y = $this->y;
		if ($this->button === null) {
			throw new BuilderException('Property [button] is required.');
		}
		$instance->button = $this->button;
		$instance->timestamp = $this->timestamp;
		$instance->deltaX = $this->deltaX;
		$instance->deltaY = $this->deltaY;
		$instance->modifiers = $this->modifiers;
		$instance->clickCount = $this->clickCount;
		return $instance;
	}
177003
public function instance($abstract, $instance)
    {
        $abstract = $this->normalize($abstract);
        if (is_array($abstract)) {
            list($abstract, $alias) = $this->extractAlias($abstract);
            $this->alias($abstract, $alias);
        }
        unset($this->aliases[$abstract]);
        $bound = $this->bound($abstract);

        $this->instances[$abstract] = $instance;
        if ($bound) {
            $this->rebound($abstract);
        }
    }
530108
public function create(string $className)
    {
        if (!class_exists($className)) {
            $classFileName = $this->fileNameforClass($className);
            $this->createFile($classFileName, $className, 'class.tmpl');
            $this->console->writeLine(
                    'Class ' . $className . ' created at ' . $classFileName
            );
        } else {
            $this->console->writeLine(
                    'Class ' . $className
                    . ' already exists, skipped creating the class'
            );
        }
    }
1240655
protected static function checkInternalClass($instance, $class, array $args = [])
    {
        if (null !== $instance) {
            return;
        }

        $messages = [];
        foreach ($args as $name => $value) {
            $messages[] = sprintf('%s => %s', $name, $value);
        }

        throw new \RuntimeException(sprintf(
            'Unable to create internal class: %s, with params: %s',
            $class,
            implode(', ', $messages)
        ));
    }
1197603
public function renameComponent($instanceName, $newInstanceName) {
		if ($instanceName == $newInstanceName) {
			return;
		}

		if (isset($this->declaredInstances[$newInstanceName])) {
			throw new MoufException("Unable to rename instance '$instanceName' to '$newInstanceName': Instance '$newInstanceName' already exists.");
		}

		if (isset($this->declaredInstances[$instanceName]['external']) && $this->declaredInstances[$instanceName]['external'] == true) {
			throw new MoufException("Unable to rename instance '$instanceName' into '$newInstanceName': Instance '$instanceName' is declared externally.");
		}

		$this->declaredInstances[$newInstanceName] = $this->declaredInstances[$instanceName];
		unset($this->declaredInstances[$instanceName]);
		
		foreach ($this->declaredInstances as $declaredInstanceName=>$declaredInstance) {
			if (isset($declaredInstance["constructor"])) {
				foreach ($declaredInstance["constructor"] as $index=>$propWrapper) {
					if ($propWrapper['parametertype'] == 'object') {
						$properties = $propWrapper['value'];
						if (is_array($properties)) {
							// If this is an array of properties
							$keys_matching = array_keys($properties, $instanceName);
							if (!empty($keys_matching)) {
								foreach ($keys_matching as $key) {
									$properties[$key] = $newInstanceName;
								}
								$this->setParameterViaConstructor($declaredInstanceName, $index, $properties, 'object');
							}
						} else {
							// If this is a simple property
							if ($properties == $instanceName) {
								$this->setParameterViaConstructor($declaredInstanceName, $index, $newInstanceName, 'object');
							}
						}
					}
				}
			}
		}
		
		
		foreach ($this->declaredInstances as $declaredInstanceName=>$declaredInstance) {
			if (isset($declaredInstance["fieldBinds"])) {
				foreach ($declaredInstance["fieldBinds"] as $paramName=>$properties) {
					if (is_array($properties)) {
						// If this is an array of properties
						$keys_matching = array_keys($properties, $instanceName);
						if (!empty($keys_matching)) {
							foreach ($keys_matching as $key) {
								$properties[$key] = $newInstanceName;
							}
							$this->bindComponents($declaredInstanceName, $paramName, $properties);
						}
					} else {
						// If this is a simple property
						if ($properties == $instanceName) {
							$this->bindComponent($declaredInstanceName, $paramName, $newInstanceName);
						}
					}
				}
			}
		}

		foreach ($this->declaredInstances as $declaredInstanceName=>$declaredInstance) {
			if (isset($declaredInstance["setterBinds"])) {
				foreach ($declaredInstance["setterBinds"] as $setterName=>$properties) {
					if (is_array($properties)) {
						// If this is an array of properties
						$keys_matching = array_keys($properties, $instanceName);
						if (!empty($keys_matching)) {
							foreach ($keys_matching as $key) {
								$properties[$key] = $newInstanceName;
							}
							$this->bindComponentsViaSetter($declaredInstanceName, $setterName, $properties);
						}
					} else {
						// If this is a simple property
						if ($properties == $instanceName) {
							$this->bindComponentViaSetter($declaredInstanceName, $setterName, $newInstanceName);
						}
					}
				}
			}
		}
		
		if (isset($this->instanceDescriptors[$instanceName])) {
			$this->instanceDescriptors[$newInstanceName] = $this->instanceDescriptors[$instanceName];
			unset($this->instanceDescriptors[$instanceName]);
		}
	}
1291423
public function isInstanceAnonymous($instanceName) {
		if (isset($this->declaredInstances[$instanceName]['anonymous'])) {
			return $this->declaredInstances[$instanceName]['anonymous'];
		} else {
			return false;
		}
	}
1084911
protected function call($instance, $route, $method)
	{
		$parameters = $route->parametersWithoutNulls();

		return $instance->callAction($method, $parameters);
	}
1094872
protected function execute($instance, $action)
    {
        $app = $this;
        $wei = $this->wei;
        $middleware = $this->getMiddleware($instance, $action);

        $callback = function () use ($instance, $action, $app) {
            $instance->before($app->request, $app->response);

            $method = $app->getActionMethod($action);
            $response = $instance->$method($app->request, $app->response);

            $instance->after($app->request, $response);

            return $response;
        };

        $next = function () use (&$middleware, &$next, $callback, $wei) {
            $config = array_splice($middleware, 0, 1);
            if ($config) {
                $class = key($config);
                $service = new $class(array('wei' => $wei) + $config[$class]);
                $result = $service($next);
            } else {
                $result = $callback();
            }

            return $result;
        };

        return $this->handleResponse($next())->send();
    }