Creates a definition stdClass object using the values from the definition
array that is passed in as a parameter

@param array $definition
@return stdClass definition object
@since Moodle 2.8
549398
private static function create_definition_object($definition) {
        global $CFG;

        $method = $definition['method'];
        $definitionobject = new stdClass();
        foreach ($definition as $key => $value) {
            if (!is_array($value)) {
                $definitionobject->$key = $value;
            }
        }
        $text = '';
        $format = FORMAT_MOODLE;
        if (isset($definition['description'])) {
            $text = $definition['description'];
            if (isset($definition['descriptionformat'])) {
                $format = $definition['descriptionformat'];
            }
        }
        $definitionobject->description_editor = array('text' => $text, 'format' => $format);

        require_once("$CFG->libdir/filelib.php");
        require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php');
        $details  = call_user_func('gradingform_'.$method.'_controller::get_external_definition_details');
        $methodarray = array();
        foreach (array_keys($details) as $definitionkey) {
            $items = array();
            $idnumber = 1;
            foreach ($definition[$method][$definitionkey] as $item) {
                $processeditem = self::set_new_ids($item, $idnumber);
                $items[$processeditem['id']] = $processeditem;
                $idnumber++;
            }
            $definitionobjectkey = substr($definitionkey, strlen($method.'_'));
            $methodarray[$definitionobjectkey] = $items;
            $definitionobject->$method = $methodarray;
        }

        return $definitionobject;
    }
235037
public function setDefinitions($definitions)
    {
        if (\is_string($definitions)) {
            $definitions = [$definitions];
        }

        if ($definitions instanceof \Traversable) {
            $definitions = \iterator_to_array($definitions);
        }

        if (!\is_array($definitions)) {
            throw new \InvalidArgumentException(
                \sprintf('Definitions must be a string or traversable. %s given', \gettype($definitions))
            );
        }

        \array_walk(
            $definitions,
            function ($definition) {
                if (!\is_array($definition) && !\is_string($definition)) {
                    throw new \InvalidArgumentException(
                        \sprintf(
                            'A definition must be an array or a file or directory path. %s given',
                            \gettype($definition)
                        )
                    );
                }
            }
        );

        $this->definitions = $definitions;

        return $this;
    }
234794
private function convertDefinitionToPhpArray(Definition $definition)
    {
        $definitionArray = [];
        if ($definition->isSynthetic()) {
            $definitionArray = $this->convertSyntheticDefinitionToPhpArray($definition);
        }

        $this->hydrateDefinitionClass($definition, $definitionArray);
        $this->hydrateDefinitionArguments($definition, $definitionArray);
        $this->hydrateDefinitionFactory($definition, $definitionArray);
        $this->hydrateDefinitionTags($definition, $definitionArray);
        $this->hydrateDefinitionMethodCalls($definition, $definitionArray);
        $this->hydrateDefinitionConfigurator($definition, $definitionArray);
        $this->hydrateDefinitionParent($definition, $definitionArray);
        $this->hydrateDefinitionScopeProperty($definition, $definitionArray);
        $this->hydrateDefinitionPublicProperty($definition, $definitionArray);
        $this->hydrateDefinitionAbstractProperty($definition, $definitionArray);
        $this->hydrateDefinitionFileProperty($definition, $definitionArray);

        return $definitionArray;
    }
642625
private function setDefinitionFactory(Definition $definition, array $array)
    {
        if (isset($array['factory'])) {
            $factory = [];
            foreach ($array['factory'] as $argument) {
                $factory[] = $this->convertArgument($argument);
            }

            $definition->setFactory($factory);
        }
    }
801363
protected function createTaxRateFromDefinition(array $definition)
    {
        $rate = new TaxRate();
        $setValues = \Closure::bind(function ($definition) {
            $this->id = $definition['id'];
            $this->name = $definition['name'];
            if (isset($definition['default'])) {
                $this->default = $definition['default'];
            }
        }, $rate, '\CommerceGuys\Tax\Model\TaxRate');
        $setValues($definition);

        foreach ($definition['amounts'] as $amountDefinition) {
            $amount = $this->createTaxRateAmountFromDefinition($amountDefinition);
            $rate->addAmount($amount);
        }

        return $rate;
    }
337621
protected static function parseDefinition($definition)
    {
        if (!is_array($definition)) {
            $definition = deserialize($definition, true);

            return $definition;
        }

        return $definition;
    }
1324453
private function resolverPropertiesAndConstructor(array $definition)
    {
        $propertyInjections = [];
        $constructorInjection = null;

        // 循环解析
        foreach ($definition as $name => $property) {
            // 构造函数
            if (is_array($property) && $name === 0) {
                $constructorInjection = $this->resolverConstructor($property);
                continue;
            }

            // 数组属性解析
            if (is_array($property)) {
                $injectProperty = $this->resolverArrayArgs($property);
                $propertyInjection = new PropertyInjection($name, $injectProperty, false);
                $propertyInjections[$name] = $propertyInjection;
                continue;
            }

            // 普通解析
            list($injectProperty, $isRef) = $this->getTransferProperty($property);
            $propertyInjection = new PropertyInjection($name, $injectProperty, (bool)$isRef);
            $propertyInjections[$name] = $propertyInjection;
        }

        return [$propertyInjections, $constructorInjection];
    }
817019
protected function processDefinitions(array $definitions)
    {
        foreach ($definitions['subdivisions'] as $code => &$definition) {
            // Add common keys from the root level.
            $definition['country_code'] = $definitions['country_code'];
            if (isset($definitions['locale'])) {
                $definition['locale'] = $definitions['locale'];
            }
            // Ensure the presence of code and name.
            $definition['code'] = $code;
            if (!isset($definition['name'])) {
                $definition['name'] = $code;
            }
            if (isset($definition['local_code']) && !isset($definition['local_name'])) {
                $definition['local_name'] = $definition['local_code'];
            }
        }

        return $definitions;
    }
791336
public function bind(InputDefinition $definition)
    {
        $hasCodeArgument = false;

        if ($definition->getArgumentCount() > 0) {
            $args    = $definition->getArguments();
            $lastArg = \array_pop($args);
            foreach ($args as $arg) {
                if ($arg instanceof CodeArgument) {
                    $msg = \sprintf('Unexpected CodeArgument before the final position: %s', $arg->getName());
                    throw new \InvalidArgumentException($msg);
                }
            }

            if ($lastArg instanceof CodeArgument) {
                $hasCodeArgument = true;
            }
        }

        $this->hasCodeArgument = $hasCodeArgument;

        return parent::bind($definition);
    }
449892
private function hydrateDefinitionMethodCalls(Definition $definition, array &$definitionArray)
    {
        foreach ($definition->getMethodCalls() as $methodToCall) {
            $method_call_array = [];

            // retrieving method to call name
            $method_name = array_shift($methodToCall);
            $method_call_array[] = $method_name;

            // retrieving method to call arguments
            $methodArgs = [];
            foreach (array_shift($methodToCall) as $arg) {
                $methodArgs[] = $this->convertArgument($arg);
            }

            $method_call_array[] = $methodArgs;

            // finally add method call to definition array
            $definitionArray['calls'][] = $method_call_array;
        }
    }
346941
public function setDefinitions(array $definitions) : ContainerAwareInterface
    {
        $this->set('definition.config', $definitions);
        parent::setPropertyDefinition($definitions['property.definition']);

        return $this;
    }
1184141
public function resolve(string $definition, array $args = [])
    {
        $def = $this->getDefinition($definition);
        if ($def === null) {
            throw new ClassDefinitionNotFoundException($definition);
        }

        return $this->binding_resolver->resolve($def, $this, $args);
    }
535941
public function addCodeDefinition(CodeDefinition $definition)
    {
        $this->bbcodes[$definition->getTagName()][$definition->usesOption()] = $definition;
        return $this;
    }
1265095
private function populateObjectItems($object, array $definition)
    {
        $output = clone $object;
        foreach ($definition as $key => $node) {
            if (isset($node['required'])) {
                if ((!$node['required']) && (!isset($output->{$key}))) {
                    $output->{$key} = $node['default'];
                }
            } else {
                if (!isset($output->{$key})) {
                    $output->{$key} = new stdClass();
                }
                $output->{$key} = $this->populateObjectItems($output->{$key}, $node);
            }
        }
        return $output;
    }
1342167
public function setDefinition(array $definition) {
        $arguments = [];
        $options = [];
        foreach ($definition as $item) {
            if ($item instanceof Option) {
                $options[] = $item;
            }
            else {
                $arguments[] = $item;
            }
        }

        $this->setArguments($arguments);
        $this->setOptions($options);
    }
277393
public static function createFromApiJsonDocs($definition)
    {
        if (arr::get('group', $definition) == 'deprecated') {
            return;
        }

        $operation = new static();

        $operation->version = (arr::get('group', $definition) == 'streams')
            ? 'stream'
            : arr::get('api_version', $definition, '1');

        $operation->httpMethod = arr::get('http_method', $definition);
        $operation->summary = arr::get('desc', $definition);
        $operation->notes = arr::get('param_notes', $definition);
        $operation->parsePath(arr::get('path', $definition));

        foreach (arr::get('params', $definition, array()) as $param => $desc) {
            // Always false due to complex rules on meetup's side (one of x is required)
            $operation->addParameter(str_replace('*', '', $param), 'query', false, $desc);
        }

        foreach (arr::get('orders', $definition, array()) as $param => $desc) {
            $operation->addParameter($param, 'query', false, $desc);
        }

        $operation->addStandardParameters(arr::get('http_method', $definition));

        $operation->name = OperationNameConverter::parseOperationName($operation);

        return $operation;
    }
166956
protected function createParameterSchema(\stdClass $definition): Schema
    {
        // Remove non-JSON-Schema properties
        $schemaDefinition     = clone $definition;
        $swaggerPropertyNames = [
            'name',
            'in',
            'description',
            'required',
            'allowEmptyValue',
            'collectionFormat',
        ];
        foreach ($swaggerPropertyNames as $propertyName) {
            if (property_exists($schemaDefinition, $propertyName)) {
                unset($schemaDefinition->$propertyName);
            }
        }

        return $this->schemaFactory->create($schemaDefinition);
    }