@param \Yosmanyga\Validation\Resource\Definition\ArrayDefinition $definition

@return \Yosmanyga\Validation\Validator\ArrayValidator
553341
public function compile($definition)
    {
        $validator = new ExceptionValidator($definition->createValidator());
        $validator->validate($definition);

        // Try to compile map option
        // Just works if map is a validator
        try {
            $definition->map = $this->compiler->compile($definition->map);
        } catch (\RuntimeException $e) {
            // Ignore it if fails
            // Map could be a closure or anything else callable
        }

        return new ArrayValidator($definition->export());
    }
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];
    }
228238
protected function createTaxRateAmountFromDefinition(array $definition)
    {
        $amount = new TaxRateAmount();
        $setValues = \Closure::bind(function ($definition) {
            $this->id = $definition['id'];
            $this->amount = $definition['amount'];
            if (isset($definition['start_date'])) {
                $this->startDate = new \DateTime($definition['start_date']);
            }
            if (isset($definition['end_date'])) {
                $this->endDate = new \DateTime($definition['end_date']);
            }
        }, $amount, '\CommerceGuys\Tax\Model\TaxRateAmount');
        $setValues($definition);

        return $amount;
    }
17368
public function configureInputDefinition(InputDefinition $definition)
    {
        foreach ($this->fields as $field) {
            if ($field->includeAsOption()) {
                $definition->addOption($field->getAsOption());
            }
        }
    }
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;
    }
777573
protected function _resolveDefinition(
        DefinitionInterface $definition, array $parameters = [])
    {
        $entryName = $definition->getName();
        $definitionResolver = $this->_getDefinitionResolver($definition);

        try {
            $value = $definitionResolver->resolve($definition, $parameters);
        } catch (\Exception $exception) {
            throw new DependencyException(
                "An error occurred while resolving " .
                "entry '{$entryName}': " . $exception->getMessage(),
                0,
                $exception
            );
        }

        return $value;
    }
109034
static public function formatName($definition)
	{
	    if (is_string($definition)) {
	        return $definition;
	    } elseif (is_object($definition)) {
	        return get_class($definition);
	    } elseif (is_array($definition)) {
	        if (!isset($definition['class'])) {
	            $name = $definition[0];
	        } else {
	            $name = $definition['class'];
	        }
	    } else {
	        throw new InvalidConfigException("Unsupported definition for :" . gettype($definition));
	    }
	}
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;
    }
1140211
public function applyDefaults($definition)
    {
        if (!is_array($definition) || !isset($definition['component'])) {
            return $definition;
        }

        if (is_callable($definition['component'])) {
            return array_merge($this->callableDefaults, $definition);
        }

        if (!isset($definition['component']['class'])) {
            throw new AppException('Missing required "class" key in component definition');
        }

        $definition = array_merge_recursive($this->classDefaults, $definition);

        array_walk(
            $definition['component']['calls'],
            function (&$call) {
                $call = (array) $call;
            }
        );

        return $definition;
    }
1203276
public static function run($definition) {
		$filterCollection = ScenarioHelper::forgeCollection($definition['filters']);
		$config = ScenarioHelper::runAll($filterCollection, []);
		$definition['commands'] = Helper::assignAttributesForList($definition['commands'], [
			'env' => $config,
		]);
		$commandCollection = ScenarioHelper::forgeCollection($definition['commands']);
		ScenarioHelper::runAll($commandCollection);
		return $config;
	}
577861
protected function getSubResources(JsonDefinition $definition)
    {
        $resources = [];
        foreach ($definition->getFields() as $field) {
            while ($field instanceof JsonDefinitionArray) {
                $field = $field->getElement();
            }
            if (!$field instanceof JsonDefinitionHash) {
                continue;
            }

            $subDefiniton = $field->getJsonDefinition();

            $resources = array_merge($this->getSubResources($subDefiniton), $resources);
            $resources[] = $subDefiniton;
        }

        return $resources;
    }
1051904
public function resolve(
        DefinitionInterface $definition, array $parameters = [])
    {
        /** @var CallableDefinition $definition */
        $args = (empty($parameters)) ? $definition->getArgs(): $parameters;
        return call_user_func_array($definition->getCallable(), $args);
    }
596747
private static function parseDefinitions(array $definitions): array
    {
        if (\count($definitions) === 0) {
            return $definitions;
        }

        return \array_map(
            function ($definition) {
                if (\is_array($definition)) {
                    return $definition;
                }

                return self::loadDefinitionsFromPath($definition);
            },
            $definitions
        );
    }
273213
public function parseMigrationDefinition(MigrationDefinition $definition)
    {
        $status = MigrationDefinition::STATUS_PARSED;

        /// validate that php file is ok, contains a class with good interface
        $className = $this->getClassNameFromFile($definition->path);

        if ($className == '') {
            $status = MigrationDefinition::STATUS_INVALID;
            $message = 'The migration definition file should contain a valid class name. The class name is the part of the filename after the 1st underscore';
        } else {

            // we use smart parsing instead before plain file inclusion, by usage of nikic/php-parser
            // this should help with broken php migrations

            $pf = new ParserFactory();
            $parser = $pf->create(ParserFactory::PREFER_PHP7);
            try {
                $parser->parse(file_get_contents($definition->path));

                include_once($definition->path);

                if (!class_exists($className)) {
                    $status = MigrationDefinition::STATUS_INVALID;
                    $message = "The migration definition file should contain a valid class '$className'";
                } else {
                    $interfaces = class_implements($className);
                    if (!in_array($this->mandatoryInterface, $interfaces)) {
                        $status = MigrationDefinition::STATUS_INVALID;
                        $message = "The migration definition class '$className' should implement the interface '{$this->mandatoryInterface}'";
                    }
                }
            } catch (Error $e) {
                $status = MigrationDefinition::STATUS_INVALID;
                $message = "The migration definition file '{$definition->path}' is not valid php'";
            }
        }

        if ($status != MigrationDefinition::STATUS_PARSED)
        {
            return new MigrationDefinition(
                $definition->name,
                $definition->path,
                $definition->rawDefinition,
                $status,
                array(),
                $message
            );
        }

        return new MigrationDefinition(
            $definition->name,
            $definition->path,
            $definition->rawDefinition,
            MigrationDefinition::STATUS_PARSED,
            array(
                new MigrationStep('php', array('class' => $className), array('path' => $definition->path))
            )
        );
    }
69756
private function hydrateDefinitionScopeProperty(Definition $definition, array &$definitionArray)
    {
        if (ContainerInterface::SCOPE_CONTAINER !== $definition->getScope()) {
            $definitionArray['scope'] = $definition->getScope();
        }
    }
910494
protected function resolveFieldsFunction($definition): Closure
    {
        return function () use ($definition): array {
            return (new Collection($definition->fields))
                ->mapWithKeys(function (FieldDefinitionNode $fieldDefinition) use ($definition): array {
                    $fieldValue = new FieldValue(
                        new NodeValue($definition),
                        $fieldDefinition
                    );

                    return [
                        $fieldDefinition->name->value => app(FieldFactory::class)->handle($fieldValue),
                    ];
                })
                ->toArray();
        };
    }
721138
public function addDefinitions(array $definitions)
    {
        foreach ($definitions as $name => $definition) {
            if (!($definition instanceof DefinitionInterface)) {
                throw new DcGeneralInvalidArgumentException(
                    'Definition ' . $name . ' does not implement DefinitionInterface.'
                );
            }

            $this->setDefinition($name, $definition);
        }

        return $this;
    }