createObject

@param string $class
@param array  $args
@param bool   $shared
@param bool   $protected

@return  mixed
@since   3.0
551461
public function createObject($class, array $args = [], $shared = false, $protected = false)
    {
        $callback = function (Container $container) use ($class, $args) {
            return $container->newInstance($class, $args);
        };

        return $this->set($class, $callback, $shared, $protected)->get($class);
    }
1329891
private function createInstance($definition, $arguments, $shared)
    {
        if (is_string($definition)) {
            return new $definition(...$arguments);
        }

        if (is_callable($definition)) {
            return $definition(...$arguments);
        }

        if (is_object($definition)) {
            if ($shared) {
                return $definition;
            }
            else {
                return new $definition(...$arguments);
            }
        }

        throw new \RuntimeException('Invalid service definition!');
    }
245185
public function setInvokableClass($name, $invokableClass, $shared = null)
    {
        $invokableClass = strtr($invokableClass, '.', '\\');
        return parent::setInvokableClass($name, $invokableClass, $shared);
    }
238077
public function create($class, array $arguments = [])
    {
        $instanceType = $this->getInstanceType($class);
        $instanceArguments = $this->getInstanceArguments($class, $arguments);
        $reflection = new \ReflectionClass($instanceType);
        $constructor = $reflection->getConstructor();

        if (null === $constructor) {
            $instance = new $instanceType();
        } else {
            $args = $this->resolveArguments($constructor, $instanceArguments);
            $instance = $reflection->newInstanceArgs($args);
        }

        return $instance;
    }
228415
public function createObject(string $name, array $args): JavaProxy
    {
        $this->protocol->createObjectBegin($name);
        $this->writeArgs($args);
        $this->protocol->createObjectEnd();

        return $this->getInternalResult();
    }
107006
protected function _createObject( $args ) {
		$post_id = wp_insert_post( $args, true );
		if ( $post_id && ! is_wp_error( $post_id ) ) {
			$this->_debug( 'Generated post ID: ' . $post_id );
		} elseif ( is_wp_error( $post_id ) ) {
			$this->_debug(
				'Post generation failed with message [%s] %s',
				$post_id->get_error_code(),
				$post_id->get_error_messages()
			);
		} else {
			$this->_debug( 'Post generation failed' );
		}

		return $post_id;
	}
97648
public function create($class, array $options = array())
    {
        if (!is_subclass_of($class, Toolbar::class)) {
            throw new \InvalidArgumentException("Class '$class' must extends Toolbar class.");
        }

        /** @var Toolbar $toolbar */
        $toolbar = new $class($this->container);
        $resolver = new OptionsResolver();
        $toolbar->configureOptions($resolver);
        $resolvedOptions = $resolver->resolve($options);
        $toolbar->setOptions($resolvedOptions);

        // build Actions
        $actionsBuilder = new ActionsBuilder($this->container);
        $toolbar->buildActions($actionsBuilder, $resolvedOptions);
        $toolbar->actions = $actionsBuilder->getActions();

        // build form
        $formFactory = $this->container->get('form.factory');
        $formBuilder = $formFactory->createBuilder(FormType::class, null, $resolvedOptions['form_options']);
        $toolbar->buildForm($formBuilder, $resolvedOptions);
        $toolbar->form = $formBuilder->getForm();

        return $toolbar;
    }
1076894
public function createByClass($class,$constructorArgs=[],$singleton=true)
    {
        //使用类型名代替ID创建对象,异常代表类型未配置,无需抛出
        try{
            $obj=$this->create($class);
            return $obj;
        }catch (\Exception $ex){}

        //单例模式下,尝试从缓存获取
        if($singleton && array_key_exists($class, $this->m_singletonObjMap)){
            $obj=$this->m_singletonObjMap[$class];
            if(!is_null($obj)){
                return $obj;
            }
        }

        //直接从类型名创建对象
        if(!class_exists($class)){
            throw new \Exception("Class '".$class."' not found");
        }
        $obj=$this->newInstance($class,$constructorArgs);

        //注入全局属性(全局属性只有值类型)
        foreach ($this->m_config->getConfigValues(BuiltInConst::GLOBAL_CONFIG_SESSION) as $name=>$value){
            $this->setProperty($obj, $name, $value);
        }

        //通过配置接口注入配置实例
        if($obj instanceof IConfigurable){
            $obj->setConfiguration($this->m_config);
        }

        //如果为单态模式,则保存到缓存
        if($singleton){
            $this->m_singletonObjMap[$class]=$obj;
        }

        //返回对象
        return $obj;
    }
1343483
public function instanciate(string $class_name, ...$args): Interfaces\JavaObject
    {
        try {
            $java = new Java($class_name, ...$args);
        } catch (Pjb62BrokenConnectionException | Exception\InvalidUsageException $e) {
            PjbProxyClient::unregisterInstance();
            throw new BrokenConnectionException($e->getMessage(), $e->getCode(), $e);
        }

        return $java;
    }
1212545
public function make($class, $type, $slug, $arguments = [])
    {
        $field = $this->container->make($class);

        $field
            ->setType($type)
            ->setSlug($slug)
            ->setArguments($arguments)
            ->boot();

        return $field;
    }
728116
public function create(string $class, array $map = [], array $params = null)
    {
        try {
            return Builder::create($this, $class, $map, $params);
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException($e->getMessage());
        }
    }
11670
public static function create(string $signature, array $protectedHeader, ?string $encodedProtectedHeader, array $header = []): self
    {
        return new self($signature, $protectedHeader, $encodedProtectedHeader, $header);
    }
178608
public function singleton($contract, $class, $args = [])
    {
        $reflect = new \ReflectionClass($class);
        $instance = $reflect->newInstanceArgs($args);

        $this->bindings[$contract] = [
            'type' => 'singleton',
            'instance' => $instance,
            'class' => $class,
            'args' => $args
        ];

        if (!class_exists($contract, false)) {
            eval("class {$contract} extends \Hades\Container\Facade {} ");
        }
    }
483748
public function create($providerClass, IDictionary $shared) {
        $provider = $this->container->get($providerClass, ['shared' => $shared]);
        $this->container->set($providerClass, $provider);

        return $provider;
    }
772191
public static function constructClassInstance( $clazz, $args ) {
		// $args should be a non-associative array; show nice error if that's not the case
		if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
			throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
		}

		return new $clazz( ...$args );
	}
1057989
public static function instantiateClassByConstructor($class, $args)
    {
        switch (count($args)) {
            case 0:
                return new $class();
            case 1:
                return new $class($args[0]);
            case 2:
                return new $class($args[0], $args[1]);
            case 3:
                return new $class($args[0], $args[1], $args[2]);
            case 4:
                return new $class($args[0], $args[1], $args[2], $args[3]);
            default:
                $rClass = new \ReflectionClass($class);
                return $rClass->newInstanceArgs($args);
        }
    }
952362
public function create($class, $data = [], $created = false)
    {
        if (! is_array($data)) {
            $data = (array) $data;
        }

        if (strpos($class, 'Discord\\Parts') !== false) {
            $object = new $class($this, $this->discord, $this->http, $this->cache, $data, $created);
        } elseif (strpos($class, 'Discord\\Repository') !== false) {
            $object = new $class($this->http, $this->cache, $this, $data);
        } else {
            throw new \Exception('The class '.$class.' is not a Part or a Repository.');
        }

        return $object;
    }