@param array $definition

@return array
964554
protected function gatherRouteFacts(array $definition) {
        $route = array_get($definition, 'route');
        $method = null;
        $path = null;
        $action = null;

        // routes is expected to be in format like:
        // GET POST /some/path someAction
        if (is_string($route)) {
            $parts = preg_split('/\s+/', $route);
            $parts = array_map('trim', $parts);

            foreach ($parts as $part) {
                if (HttpRequestMethod::isValid($part) || $part === 'ANY') {
                    if ($method === null) {
                        $method = $part;
                    } else if ( ! is_array($method)) {
                        $method = [$method, $part];
                    } else {
                        $method[] = $part;
                    }
                } else if ($path === null) {
                    $path = $part;
                } else if ($action === null) {
                    $action = $part;
                }
            }
        }

        if ($method === null) {
            $method = array_get($definition, 'method');
        }

        if ($method === 'ANY' || (is_array($method) && array_contains($method, 'ANY'))) {
            $method = HttpRequestMethod::getMethods();
        }

        if ($path === null) {
            $path = array_get($definition, 'path');
        }

        if ($action === null) {
            $action = array_get($definition, 'action');
        }

        return [$method, $path, $action];
    }
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;
    }
232814
private function resolveDefinition(Definition $definition): Definition
    {
        $definition->setArguments($this->resolveArguments($definition->getArguments()));
        $definition->setFactory($this->resolveFactory($definition->getFactory()));
        $definition->setMethodCalls($this->resolveMethodCalls($definition->getMethodCalls()));

        return $definition;
    }
1173315
protected function parseDefinitionRights($definition)
    {
        $permissions = [];

        // We need to explode the definition in case it contains
        // multiple rights, for example: (GR,GE).
        $rights = explode(',', $definition);

        foreach ($rights as $right) {
            // We'll make sure the right exists inside the definitions
            // array before we try to instantiate it.
            if (array_key_exists($right, static::$definitions)) {
                $permissions[] =  new static::$definitions[$right];
            }
        }

        return $permissions;
    }
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;
    }
249752
public function bind(Definition $definition) {
        $this->arguments = [];
        $this->options = [];
        $this->definition = $definition;

        $this->parse();
    }
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;
    }
602649
private function getCompilerPass(Definition $definition)
    {
        $driver = $this->getResourceDriver($definition);

        if ($driver === null) {
            return;
        }

        $class = $this->getCompilerPassClass($driver);
        $method = $this->getCompilerPassMethod($this->getResourceDriverMappingFormat($definition));
        $path = $this->getResourceDriverMappingPath($definition);
        $model = $this->getResourceModel($definition);

        return $class::$method([$path => ClassUtils::getRealNamespace($model)], []);
    }
882451
public function newInputFilter(array $definition = array())
    {
        if (!empty($definition)) {
            $this->_definition = $definition;
        }
        $this->_inputFilter = new InputFilter();

        foreach ($this->_definition as $key => $item) {
            if (!is_string($key)) {
                $key = $item['name'];
            }
            $this->_addInput($item, $key);
        }

        return $this->_inputFilter;
    }
705143
public function addDefinition(Definition $definition)
    {
        if ($this->hasDefinition($definition)) {
            throw new \InvalidArgumentException(sprintf('Definition "%s" allready exists.', $definition->getName()));
        }

        $this->definitions[$definition->getName()] = $definition;

        return $this;
    }
582453
protected function createFromDefinition(array $definition)
    {
        if (!isset($definition['class'])) {
            throw new ContainerException(
                'Service could not be created from definition:'
                    . ' option "class" is not exists in definition array.'
            );
        }

        $className = $definition['class'];

        if (!class_exists($className)) {
            throw new ContainerException(sprintf(
                'Service could not be created from definition:'
                    . ' Class "%s" is not exists.',
                $className
            ));
        }

        $reflection = new \ReflectionClass($className);

        if (!$reflection->isInstantiable()) {
            throw new ContainerException(sprintf(
                'Service could not be created from definition:'
                    . ' Unable to create instance of class "%s".',
                $className
            ));
        }

        if (null !== ($constructor = $reflection->getConstructor())) {
            if (!isset($definition['args'])) {
                throw new ContainerException(
                    'Service could not be created from definition:'
                        . ' option "args" is not exists in definition array.'
                );
            }
            $params = $this->resolveArgs($constructor->getParameters(), $definition['args']);
            $service = $reflection->newInstanceArgs($params);
        } else {
            // we don't have a constructor
            $service = $reflection->newInstance();
        }

        if (!isset($definition['calls'])) {
            return $service;
        }

        $calls = isset($definition['calls']) ? $definition['calls'] : [];
        foreach ($calls as $method => $args) {
            if (!is_callable([$service, $method])) {
                throw new ContainerException(sprintf(
                    'Service could not be created from definition:'
                        . ' can not call method "%s" from class: "%s"',
                    $method,
                    $className
                ));
            }
            $method = new \ReflectionMethod($service, $method);
            $params = $method->getParameters();
            $arguments = is_array($args)
                    ? $this->resolveArgs($params, $args)
                    : [];
            $method->invokeArgs($service, $arguments);
        }

        return $service;
    }
669537
public function merge($definition)
    {
        $constraints = $this->explodeConstraints($definition);

        foreach ($constraints as $index=>$definition) {

            list($name, $parameters) = is_array($definition) ?
                                       [$index, $definition] :
                                       $this->nameAndParameters($definition);

            $constraint = $this->newConstraint(
                Type::snake_case($name),
                $parameters,
                ''
            );
            $this->constraints[$constraint->name()] = $constraint;

        }
        return $this;
    }
1250187
protected function buildSortedMap(array $definition) {
		$sortArgs = [];
		
		foreach ($definition as $definitionPart) {
			list($property, $direction) = $this->parseSortDefinition($definitionPart);
			
			$sortArgs[] = $this->getDataColumn($property);
			$sortArgs[] = $direction;
		}
		
		$this->_map = array_keys($this->_data);
		$sortArgs[] = &$this->_map;
		
		call_user_func_array('array_multisort', $sortArgs);
	}
632553
protected function formatDefinition($class, $definition)
    {
        if (empty($definition)) {
            return ['class' => $class];
        } elseif (is_callable($definition, false) || is_object($definition)) {
            return $definition;
        } elseif (is_string($definition)) {
        	if (strpos($definition, ':') !== false) {
        		return $definition;
        	}
        	
            return ['class' => $definition];
        } elseif (is_array($definition)) {
            if (!isset($definition['class'])) {
                if (strpos($class, '\\') !== false) {
                    $definition['class'] = $class;
                } elseif (isset($definition[0]) && is_string($definition[0]) && strpos($definition[0], '\\') !== false) {
                    $definition['class'] = $definition[0];
                    unset($definition[0]);
                } else {
                    throw new InvalidConfigException("A class definition requires a \"class\" member.");
                }
            }
            return $definition;
        } else {
            throw new InvalidConfigException("Unsupported definition type for \"$class\": " . gettype($definition));
        }
    }
1093803
public function createDictionary(DictionaryDefinition $definition): DictionaryInterface
    {
        $builder = $this->getDictionaryBuilder($definition);

        /** @var DictionaryBuilderInterface $builder */
        return $builder->build($this, $definition);
    }
991824
protected function getEntitiesSchemas(array $definitions) {
		$dataMapper = $this->dataMapper;
		$schema = new \Doctrine\DBAL\Schema\Schema;
		foreach($definitions as $definition) {
			$table = $schema->createTable($dataMapper->getTable($definition));

			foreach($definition->properties() as $name=>$prop) {
				$col = [];
				if(method_exists($prop, 'getORMParameters'))
					$col = $prop->getORMParameters();
				if($ormCol = $prop->get('orm'))
					$col = array_merge($col, $ormCol);
				if(!isset($col['notnull']))
					$col['notnull'] = false;

				#relations
				if($prop->get('type') == 'entity') {
					$relation = $dataMapper->relation($definition, $name);
					#relations with one entity
					if(!$relation->get('many')) {
						$table->addColumn($relation->getLink(), 'integer', [
							'length'         => 11,
							'notnull'        => $col['notnull'],
							'autoincrement'  => false,
						]);
						if($relation->isPolymorphic()) {
							$table->addColumn($relation->getLinkType(), 'string', [
								'length'         => 50,
								'notnull'        => $col['notnull'],
								'autoincrement'  => false,
							]);
						}
						else {
							$foreign_table = $dataMapper->getTable($relation->getTargetDefinition());
							$column = $relation->getLink();
							$options = [];
							if($relation->get('onUpdate'))
								$options['onUpdate'] = $relation->get('onUpdate');
							if($relation->get('onDelete'))
								$options['onDelete'] = $relation->get('onDelete');
							$table->addForeignKeyConstraint($foreign_table, [$column], ['id'], $options);
						}
					}
					#HMABT relations
					elseif($relation->type() == 'HMABT' && !$relation->isPolymorphic()) {
						$table_name = $relation->getAssociationTable();
						#if table was not already created by the opposite entity
						if(!$schema->hasTable($table_name)) {
							$relTable = $schema->createTable($table_name);
							$relTable->addColumn($relation->getLinkB(), 'integer', [
								'length'         => 11,
								'notnull'        => $col['notnull'],
								'autoincrement'  => false,
							]);
							$relTable->addColumn($relation->getLinkA(), 'integer', [
								'length'         => 11,
								'notnull'        => $col['notnull'],
								'autoincrement'  => false,
							]);

							$options = [
								'onDelete' => 'CASCADE',
							];
							$foreign_table = $dataMapper->getTable($relation->getTargetDefinition());
							$relTable->addForeignKeyConstraint($table, [$relation->getLinkA()], ['id'], $options);
							$relTable->addForeignKeyConstraint($foreign_table, [$relation->getLinkB()], ['id'], $options);
						}
						if($relation->reverse()->isPolymorphic()) {
							$schema->getTable($table_name)->addColumn($relation->reverse()->getLinkType(), 'string', [
								'length'         => 50,
								'notnull'        => $col['notnull'],
								'autoincrement'  => false,
							]);
						}
						#sortable
						if($relation->get('sortable')) {
							$schema->getTable($table_name)->addColumn($relation->getPositionField(), 'integer', [
								'length'         => 11,
								'notnull'        => $col['notnull'],
								'autoincrement'  => false,
							]);
						}
					}
					continue;
				}

				if($prop->get('many')) {
					$type = 'blob';
					$col['length'] = 65535;
				}
				elseif(!isset($col['type']))
					throw new \Exception('Cannot convert '.get_class($prop).' type to SQL type.');
				else
					$type = $col['type'];
				unset($col['type']);

				if(!isset($col['autoincrement']))
					$col['autoincrement'] = false;

				if($prop->get('i18n')) {
					$table_name = $dataMapper->getTranslationTable($definition);
					if(!$schema->hasTable($table_name)) {
						$i18nTable = $schema->createTable($table_name);
						$i18nTable->addColumn('id', 'integer', [
							'length'         => 11,
							'notnull'        => true,
							'autoincrement'  => false,
						]);
						$i18nTable->addColumn('locale', 'string', [
							'length'         => 50,
							'notnull'        => true,
							'autoincrement'  => false,
						]);
					}
					$schema->getTable($table_name)->addColumn($name, $type, $col);
				}
				else {
					if($name === 'id') {
						$col['autoincrement'] = true;
						$col['notnull'] = true;
					}
					$table->addColumn($name, $type, $col);
				}
			}

			if(isset($definition->get('orm')['indexes'])) {
				foreach($definition->get('orm')['indexes'] as $index) {
					$index['type'] = strtoupper($index['type']);

					foreach($index['columns'] as $col) {
						if($index['type'] !== 'FULLTEXT' && in_array($table->getColumn($col)->getType()->getName(), ['text', 'blob']))
							throw new \Exception('Table '.$table->getName().' cannot have indexes with text/blog columns.');
					}

					if($index['type'] == 'PRIMARY')
						$table->setPrimaryKey($index['columns'], 'PRIMARY');
					else {
						$indexName = $_indexName = implode('_', $index['columns']);
						$i = 1;
						while($table->hasIndex($indexName))
							$indexName = $_indexName.$i++;
						if($index['type'] == 'UNIQUE')
							$table->addUniqueIndex($index['columns'], $indexName);
						elseif($index['type'] == 'INDEX')
							$table->addIndex($index['columns'], $indexName);
						elseif($index['type'] == 'FULLTEXT') {
							$table->addIndex($index['columns'], $indexName);
							$table->getIndex($indexName)->addFlag('fulltext');
						}
					}
				}
			}
			
			$table->setPrimaryKey(['id']);
		}

		if($cb = $this->entitiesSchemaCallback)
			$cb($this, $schema);

		return $schema;
	}
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();
        };
    }