Factory.

@param IComponent $component
@param array      $events
@param string     $callbackOnSuccess
@param string     $callbackOnException
@return IEventContainer
3835
public static function factory(IComponent $component, array $events, $callbackOnSuccess = 'onSuccess', $callbackOnException = 'onException'): IEventContainer
    {
        $instance = new self($component, $events, $callbackOnSuccess, $callbackOnException);
        return $instance;
    }
721136
public function add(HtmlComponent $component)
    {

        if (isset($this->components[$component->id]) || isset($this->components[$component->id . ":" . $this->number])) {
            //   $id = substr($component->id,0,strpos($component->id,':'));
            //   $pid = substr($this->id,0,strpos($this->id,':'));
            throw new ZE(sprintf(ERROR_DATAROW_COMPONENT_EXISTS, $component->id, $pid));
        }
        $this->components[$component->id] = $component;
        $component->setOwner($this);
        return $component;
    }
277241
protected function createComponent($name)
	{
		$ucname = ucfirst($name);
		$method = 'createComponent' . $ucname;
		if ($ucname !== $name && method_exists($this, $method) && (new \ReflectionMethod($this, $method))->getName() === $method) {
			$component = $this->$method($name);
			if (!$component instanceof IComponent && !isset($this->components[$name])) {
				$class = get_class($this);
				throw new Nette\UnexpectedValueException("Method $class::$method() did not return or create the desired component.");
			}
			return $component;
		}
	}
510106
public function newInstance($id)
    {
        if (!isset($this->registered[$id])){
            throw new ComponentNotFoundException($id);
        }
        // create new object via factory
        $factory = $this->factories[$id] ?? null;
        if (!$factory || !is_callable($factory) || !method_exists($factory, '__invoke')){
            throw new FactoryNotFoundException($id);
        }
        // get current slot
        $slot = $this->slots[$id] ?? new Slot($id);
        // callback factory to get new instance
        $newInstance = $this->callbackFactory($id, $slot, $factory);
        return $newInstance;
    }
659306
public function registerEvent($event, $callback)
    {
        $eventManager = $this->getServiceLocator()->get(EventManager::CONFIG_ID);
        $eventManager->attach($event, $callback);
        $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
    }
229490
public function call($callback, array $parameters = [])
    {
        $this->_events[] = $event = new CallbackEvent($callback, $parameters);

        return $event;
    }
343516
protected function createInstanceCallback($name, $spec)
    {
        if (is_string($spec) && class_exists($spec)) {
            $spec = new $spec();
        }

        $callback = function () use ($name, $spec) {
            if ($spec instanceof \Closure) {
                return $spec($this);
            } elseif ($spec instanceof ServiceFactory) {
                return $spec->createService($this);
            } elseif (is_object($spec)) {
                return $spec;
            } elseif (is_array($spec)) {
                return $this->createFromArray($name, $spec);
            } elseif (is_null($spec)) {
                throw new Exception\NullServiceException($name);
            }

            throw new Exception\InvalidServiceException($name);
        };

        return $callback;
    }
1246630
public function createSuccessFromEventCollection(
        EventCollection $events
    ): EventCollection {
        $suiteClass = $this->suiteClass;
        $suiteClass::current()->assert($this->successConfig);

        return $events;
    }
928057
public function eventFactory()
    {
        if (null !== $this->eventPrototype) {
            return clone $this->eventPrototype;
        }

        try {
            /** @var ModuleOptions $moduleOptions */
            $moduleOptions = $this->get(ModuleOptions::class);

            $moduleOptionsEventClassName = $moduleOptions->getModuleOptionsEventClassName();
            $r = new ReflectionClass($moduleOptionsEventClassName);

            $eventPrototype = $r->newInstance();
            if (!$eventPrototype instanceof EventInterface) {
                $errMsg = sprintf(
                    'Event of type %s is invalid; must implement %s',
                    (is_object($eventPrototype) ? get_class($eventPrototype) : gettype($eventPrototype)),
                    ModuleOptionsEventInterface::class
                );
                throw new Exception\RuntimeException($errMsg);
            }
            $this->eventPrototype = $eventPrototype;
        } catch (\Exception $e) {
            throw new Exception\InvalidEventException($e->getMessage(), $e->getCode(), $e);
        }

        return clone $this->eventPrototype;
    }
1344759
protected function createEvent($eventName)
    {
        if (null === $this->defaultEvent) {
            return new Event($eventName);
        }
        $event = clone $this->defaultEvent;
        $event->setName($eventName);
        return $event;
    }
1027935
protected function iocContainer()
    {
        if (
            property_exists($this, 'container')
            && isset($this->container)
            && $this->container instanceof ContainerInterface
        ) {
            return $this->container;
        }

        /*
         * Technically your code can work without ever being using fallback container, all
         * spiral components can do that and only few traits will require few extra parameters.
         *
         * I'm planning one day (update: DONE) to run spiral as worker and later in async mode (few app
         * processes in memory), memory schemas might help a lot by minimizing runtime code by using
         * pre-calculated behaviours.
         */

        return self::$staticContainer;
    }
872232
public function with($selector, Closure $callback)
    {
        $browser = new static(
            $this->driver, new ElementResolver($this->driver, $this->resolver->format($selector))
        );

        if ($this->page) {
            $browser->onWithoutAssert($this->page);
        }

        if ($selector instanceof Component) {
            $browser->onComponent($selector, $this->resolver);
        }

        call_user_func($callback, $browser);

        return $this;
    }
39063
function createComponentFactory(selector, componentType, viewDefFactory, inputs, outputs, ngContentSelectors) {
    return new ComponentFactory_(selector, componentType, viewDefFactory, inputs, outputs, ngContentSelectors);
}
733509
public function onBootstrap(EventInterface $e)
    {
        /** @var MvcEvent $e */
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);

        /** @var Workflow $workflowService */
        $workflowService = $e->getApplication()->getServiceManager()->get(Workflow::class);
        $listener = $e->getApplication()->getServiceManager()->get(InjectTypeResolver::class);
        $workflowService->getEventManager()->attach($listener);
    }
1351513
function componentFactory(vConfig) {

		// Inherit cacheTokens from owner component if not defined in asyncHints
		if (!vConfig.asyncHints || !vConfig.asyncHints.cacheTokens) {
			var oOwnerComponent = Component.get(ManagedObject._sOwnerId);
			var mCacheTokens = oOwnerComponent && oOwnerComponent._mCacheTokens;
			if (typeof mCacheTokens === "object") {
				vConfig.asyncHints = vConfig.asyncHints || {};
				vConfig.asyncHints.cacheTokens = mCacheTokens;
			}
		}

		function createInstance(oClass) {

			// retrieve the required properties
			var sName = vConfig.name,
				sId = vConfig.id,
				oComponentData = vConfig.componentData,
				sController = sName + '.Component',
				mSettings = vConfig.settings;

			// create an instance
			var oInstance = new oClass(jQuery.extend({}, mSettings, {
				id: sId,
				componentData: oComponentData,
				_cacheTokens: vConfig.asyncHints && vConfig.asyncHints.cacheTokens
			}));
			assert(oInstance instanceof Component, "The specified component \"" + sController + "\" must be an instance of sap.ui.core.Component!");
			Log.info("Component instance Id = " + oInstance.getId());

			/*
			 * register for messaging: register if either handleValidation is set in metadata
			 * or if not set in metadata and set on instance
			 */
			var bHandleValidation = oInstance.getMetadata().handleValidation() !== undefined || vConfig.handleValidation;
			if (bHandleValidation) {
				// calculate handleValidation for registration
				if (oInstance.getMetadata().handleValidation() !== undefined) {
					bHandleValidation = oInstance.getMetadata().handleValidation();
				} else {
					bHandleValidation = vConfig.handleValidation;
				}
				sap.ui.getCore().getMessageManager().registerObject(oInstance, bHandleValidation);
			}

			// Some services may demand immediate startup
			activateServices(oInstance);

			if (typeof Component._fnOnInstanceCreated === "function") {

				// In async mode the hook can provide a promise which will be added to the promise chain
				var oPromise = Component._fnOnInstanceCreated(oInstance, vConfig);
				if (vConfig.async && oPromise instanceof Promise) {
					return oPromise.then(function() {
						// Make sure that the promise returned by the hook can not modify the resolve value
						return oInstance;
					});
				}

			}

			return oInstance;
		}

		// load the component class
		var vClassOrPromise = loadComponent(vConfig, {
			failOnError: true,
			createModels: true,
			waitFor: vConfig.asyncHints && vConfig.asyncHints.waitFor
		});
		if ( vConfig.async ) {
			// async: instantiate component after Promise has been fulfilled with component
			//        constructor and delegate the current owner id for the instance creation
			var sCurrentOwnerId = ManagedObject._sOwnerId;
			return vClassOrPromise.then(function(oClass) {
				return runWithOwner(function() {
					return createInstance(oClass);
				}, sCurrentOwnerId);
			});
		} else {
			// sync: constructor has been returned, instantiate component immediately
			return createInstance(vClassOrPromise);
		}
	}
1037172
public function make()
    {
        if (self::$newComponentCache === null) {
            self::$newComponentCache = new \IvoPetkov\BearFramework\Addons\HTMLServerComponents\Internal\Component();
        }
        return clone(self::$newComponentCache);
    }
175782
function onListeners($this, eventsInput, callback, context, type)
  {
    if ( !isFunction( callback ) )
    {
      return noop;
    }

    var callbackContext = context || $this;
    var events = toArray( eventsInput, ' ' );
    var listeners = $this.$$on;

    if ( !listeners )
    {
      Class.prop( $this, '$$on', listeners = {} );
    }

    var nodes = [];

    for (var i = 0; i < events.length; i++)
    {
      var eventName = events[ i ];
      var eventListeners = listeners[ eventName ];

      if ( !eventListeners )
      {
        eventListeners = listeners[ eventName ] = new EventNode();
      }

      nodes.push( new EventNode( eventListeners, callback, callbackContext, type, triggerId ) );
    }

    return function ignore()
    {
      for (var i = 0; i < nodes.length; i++)
      {
        nodes[ i ].remove();
      }

      nodes.length = 0;
    };
  }