解析bean配置

@param string $beanName   名称
@param array  $definition 数组定义格式

@return ObjectDefinition
772354
public function resolvedefinitation(string $beanName, array $definition)
    {
        if (!isset($definition['class'])) {
            throw new \InvalidArgumentException("definitions of bean 初始化失败，class字段没有配置,Data=" . json_encode($definition));
        }

        $className = $definition['class'];
        unset($definition['class']);

        // 初始化
        $objDefinitation = new ObjectDefinition();
        $objDefinitation->setName($beanName);
        $objDefinitation->setClassName($className);

        // 解析属性和构造函数
        list($propertyInjections, $constructorInjection) = $this->resolverPropertiesAndConstructor($definition);

        // 设置属性和构造函数
        $objDefinitation->setPropertyInjections($propertyInjections);
        if ($constructorInjection != null) {
            $objDefinitation->setConstructorInjection($constructorInjection);
        }

        return $objDefinitation;
    }
775788
public function getDefinitions()
    {
        $definitions = [];
        foreach ($this->definitions as $beanName => $definition) {
            $definitions[$beanName] = $this->resolvedefinitation($beanName, $definition);
        }

        return $definitions;
    }
1162467
public function newForm($name, array $definition)
    {
        $container = ContainerBuilder::buildContainer([
            $name => Definition::object('Slick\Form\Form')
                ->constructor([$name])
        ]);

        $this->_form = $container->get($name);

        foreach ($definition as $name => $element) {
            $this->addElement($this->_form, $name, $element);
        }
        return $this->_form;
    }
990755
public function loadFromFieldset($definition)
	{
		if(!is_array($definition))
		{
			$definition = deserialize($definition, true);
		}

		$buttons  = array();
		$group    = false;
		$dropdown = false;

		foreach($definition as $button)
		{
			if($button['label'] == '' && $button['type'] != 'group')
			{
				continue;
			}

			// encode value
			if(isset($button['button']) && $button['button'] == 'link')
			{
				if (substr($button['value'], 0, 7) == 'mailto:')
				{
					$button['value'] = \String::encodeEmail($button['value']);
				}
				else
				{
					$button['value'] = ampersand($button['value']);
				}
			}

			if($dropdown !== false && ($button['type'] != 'child' && $button['type'] != 'header'))
			{
				if($group !== false)
				{
					$this->addItemToTarget($group['items'], $dropdown);
				}
				else
				{
					$this->addItem($dropdown);
				}

				$dropdown = false;
			}

			// create new group
			if($button['type'] == 'group')
			{
				$this->toolbar = true;

				if($dropdown !== false)
				{
					if($group)
					{
						$this->addItemToTarget($group['items'], $dropdown);
					}
					else
					{
						$this->addItem($dropdown);
					}

					$dropdown = false;
				}

				if($group !== false)
				{
					$this->addItem($group);
				}

				$group = $button;
				$group['items'] = array();
			}

			// create dropdown
			elseif($button['type'] == 'dropdown')
			{
				$dropdown = $button;
				$dropdown['items'] = array();
			}

			// add dropdown child
			elseif($button['type'] == 'child' || $button['type'] == 'header')
			{
				$dropdown['items'][] = $button;
			}

			// add button
			elseif($group !== false)
			{
				$this->addItemToTarget($group['items'], $button);
			}
			else
			{
				$this->addItem($button);
			}
		}

		if($group !== false)
		{
			if($dropdown !== false)
			{
				$this->addItemToTarget($group['items'], $dropdown);
			}

			$this->addItem($group);
		}
		elseif($dropdown !== false)
		{
			$this->addItem($dropdown);
		}
	}
582349
private function addServiceConfigurator(Definition $definition, $variableName = 'instance')
    {
        if (!$callable = $definition->getConfigurator()) {
            return '';
        }

        if (is_array($callable)) {
            if ($callable[0] instanceof Reference
                || ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) {
                return sprintf("        %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
            }

            $class = $this->dumpValue($callable[0]);
            // If the class is a string we can optimize call_user_func away
            if (0 === strpos($class, "'") && false === strpos($class, '$')) {
                return sprintf("        %s::%s(\$%s);\n", $this->dumpLiteralClass($class), $callable[1], $variableName);
            }

            if (0 === strpos($class, 'new ')) {
                return sprintf("        (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
            }

            return sprintf("        \\call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
        }

        return sprintf("        %s(\$%s);\n", $callable, $variableName);
    }
1112402
public function autowireObject($className, $objectName = '', $pattern = 'Singleton')
    {

        if($objectName == '') $objectName = $className;
        if(!$this->objectAlreadyLoaded($objectName) && !$this->objectExistsInContext($objectName)) {
            $instantiator = new Instantiator(array('id'=>$objectName, 'class'=>$className),$this);
            $this->addObjectContext($instantiator->getNewDefinition());

            $pClass = $pattern.'Pattern';

            $cp = new ObjectService($objectName);
            $cp->setPattern(new $pClass($instantiator));

            $this->addObject($cp);
        }
        return $this->object($objectName);
    }
419354
public function getField(string $name): FieldInterface
    {
        if (!$this->hasField($name)) {
            throw new DefinitionException("Field '$name' is not defined.");
        }

        return $this->fields[$name];
    }
679716
public function set($name, $definition) {
        $this->services[$name] = new Service($name, $definition);
        return $definition;
    }
1321689
public static function getConfigInjects($className)
    {
        // 配置文件注入
        $beanData = BeanParser::getInstance()->getData();
        if(isset($beanData[$className]))
        {
            $beanName = $beanData[$className]['beanName'];
        }
        else
        {
            $beanName = $className;
        }

        $beanProperties = null;
        // 优先从服务器bean配置获取
        try{
            $beanProperties = Config::get('@server.' . RequestContext::getServer()->getName() . '.beans.' . $beanName, null);
        }
        catch(\Throwable $ex)
        {
            $beanProperties = null;
        }
        // 全局bean配置
        if(null === $beanProperties)
        {
            $beanProperties = Config::get('@app.beans.' . $beanName, []);
        }
        return $beanProperties ?? [];
    }
1093229
public function buildCommand(string $name, array $definition): CommandInterface
    {
        $command = new Command($name);
        $command->setExecutable($definition[static::CONFIG_COMMAND]);

        $this->setExcluded($command, $definition);
        $this->setGroups($command, $definition);
        $this->setEnv($command, $definition);
        $this->setIsStoreAware($command, $definition);
        $this->setStores($command, $definition);
        $this->addCommandConditions($command, $definition);
        $this->setPreCommand($command, $definition);
        $this->setPostCommand($command, $definition);
        $this->setBreakOnFailure($command, $definition);
        $this->setTimeout($command, $definition);

        return $command;
    }
1281126
public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException
	{
		return Beans.instantiate(getClass().getClassLoader(), beanName, getBeanContextPeer());
	}
369957
public function bindPrototype(string $name, $definition)
    {
        $this->definitions[$name] = new Prototype($name, $definition);
        return $this;
    }
964830
protected final Definition bean(Class<?> clazz) {
    Definition def = new Definition(clazz.getName(), clazz, Scope.SINGLETON.toString());
    def.beanName = clazz.getName() + "#" + Math.abs(System.identityHashCode(def));
    return def;
  }
1173783
public function getDefinitionOf($definitionName) {
        $definitions = $this->getDefinitions();

        return isset($definitions[$definitionName]) ? $definitions[$definitionName] : [];
    }
856785
public function buildDefinition($definition)
    {
        if (is_callable($definition)) {
            return $definition;
        }

        if (is_array($definition) && isset($definition['component'])) {
            return new Listener(
                $definition['component'],
                $definition['method'] ?: null,
                $definition['arguments'] ? (array) $definition['arguments'] : []
            );
        }

        throw new AppException('Invalid listener format, must be callable or array with component key');
    }
338516
public static function create($name, $definition)
    {
        if (preg_match('/^(.*?)KEY\s*\((.*?)\)/', $definition, $matches)) {
            return new self([
                'name' => $name,
                'columns' => preg_split('/\s*,\s*/', $matches[2]),
                'type' => trim($matches[1])
            ]);
        } else {
            throw new \InvalidArgumentException("Invalid index definition '$definition'");
        }
    }
664808
@Nullable
    protected <T> BeanRegistration<T> getActiveBeanRegistration(BeanDefinition<T> beanDefinition, Qualifier qualifier) {
        if (beanDefinition == null) {
            return null;
        }
        return singletonObjects.get(new BeanKey(beanDefinition, qualifier));
    }