Normalize a mount definition.

@param array|string $definition

@return array
An array containing at least 'source', and probably 'source_path'.
974820
private function normalizeDefinition($definition)
    {
        if (!is_array($definition)) {
            if (!is_string($definition) || strpos($definition, 'shared:files') === false) {
                throw new \RuntimeException('Failed to parse mount definition: ' . json_encode($definition));
            }
            $definition = [
                'source' => 'local',
                'source_path' => str_replace('shared:files', '', $definition),
            ];
        } elseif (!isset($definition['source'])) {
            throw new \InvalidArgumentException('Invalid mount definition: ' . json_encode($definition));
        }
        if (isset($definition['source_path'])) {
            $definition['source_path'] = $this->normalizeRelativePath($definition['source_path']);
        }

        return $definition;
    }
38773
private function filterOutAbstractDefinitions(array $definitions): array
    {
        foreach ($definitions as $key => $definition) {
            if ($definition->isAbstract()) {
                unset($definitions[$key]);
            }
        }

        return $definitions;
    }
1324778
public static function parseAdapter($definition)
    {
        preg_match_all('/\s*@adapter\s+([a-z-]+)(?:\(\s*([^)\s]+)\s*\))?/i', $definition, $matched);

        if (empty($matched[0])) {
            return false;
        }

        if (count($matched[0]) > 1) {
            throw new Exception\AnnotationException(
                "Only one adapter definition allowed!",
                $matched[0][1]
            );
        }

        return [$matched[1][0], $matched[2][0]];
    }
138990
public function load(\Asgard\Entity\Definition $definition) {
		$this->entityClass = $definition->getClass();

		if(!$definition->has('order_by'))
			$definition->set('order_by', 'id DESC');

		$definition->hook('get', [$this, 'hookGet']);
		$definition->hook('getTranslations', [$this, 'hookgetTranslations']);
		$definition->hook('validation', [$this, 'hookValidation']);
	}
583194
public static function normalize(array $context)
    {
        $diff = array_diff_key($context, self::$defaults);
        if (!empty($diff)) {
            $errorMessage = 'unknown index '.implode(', ', array_keys($diff));
            throw new InvalidContext($errorMessage);
        }
        if (!empty($context['namespace'])) {
            if (preg_match('/^\\\\?(.*?)\\\\?$/s', $context['namespace'], $ns)) {
                $context['namespace'] = $ns[1] ? $ns[1].'\\' : null;
            }
        } else {
            $context['namespace'] = null;
        }
        return array_replace(self::$defaults, $context);
    }
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;
    }
731245
public function normalizeMounts(array $mounts)
    {
        $normalized = [];
        foreach ($mounts as $path => $definition) {
            $normalized[$this->normalizeRelativePath($path)] = $this->normalizeDefinition($definition);
        }

        return $normalized;
    }
391229
private function getNormalizedDirective($directive)
    {
        $directive = strtolower($directive);

        if (ctype_alpha($directive) === true) {
            $directive = "'" . $directive . "'";
        }

        return $directive;
    }
753843
protected function parse(array $definitions)
    {
        foreach ($this->rawParams as $rKey => $rVal) {
            if (array_key_exists($rKey, $definitions)) {
                if (is_array($rVal)) {
                    $value = array();

                    foreach ($rVal as $key => $val) {
                        $value[$key] = $this->validateValue($val, $definitions[$rKey]);
                    }
                } else {
                    $value = $this->validateValue($rVal, $definitions[$rKey]);
                }

                $this->parsedParams[$rKey] = $value;
                unset($this->rawParams[$rKey]);

                if ($definitions[$rKey]->getIsRequired()) {
                    unset($this->requiredParams[array_search($rKey, $this->requiredParams)]);
                }
            }
        }

        $this->handleUndefinedParameters();
        $this->handleMissingRequiredParameters();
    }
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;
    }
1131619
public static function parseOptions($definition)
    {
        preg_match_all('/m:([a-z-]+)(?:\(([^)]*)\))?/i', $definition, $matched, PREG_SET_ORDER);

        $result = [];
        foreach ($matched as $match) {

            if (array_key_exists($match[1], $result)) {
                throw new Exception\AnnotationException(
                    "Duplicate option '" . $match[1] . "'!"
                );
            }

            $result[$match[1]] = isset($match[2]) ? trim($match[2]) : null;
        }
        return $result;
    }
49134
public function arrayToFunctionElement(array $definition)
    {
        $function = new Functions;
        if (isset($definition['docblock'])) {
            $docblock = $this->arrayToDocblockElement($definition['docblock']);
            $function->setDocbloc($docblock);
        }
        if (isset($definition['public'])) {
            $function->isPublic(true);
        }
        if (isset($definition['name'])) {
            $function->setName($definition['name']);
        }
        if (isset($definition['params'])) {
            foreach ($definition['params'] as $name => $type) {
                $function->addParam($name, $type);
            }
        }
        if (isset($definition['content'])) {
            $function->setContent($definition['content']);
        }
        return $function;
    }
169901
protected function pickCompiler($definition)
    {
        foreach ($this->compilers as $i => $compiler) {
            if ($compiler->supports($definition)) {
                if (0 != $i) {
                    // Move compiler to top to improve next pick
                    unset($this->compilers[$i]);
                    array_unshift($this->compilers, $compiler);
                }

                return $this->compilers[0];
            }
        }

        throw new \RuntimeException('No compiler is able to work with the resource');
    }
37930
private function normalizeDir($dir)
    {
        $dir = rtrim($dir, '/'.\DIRECTORY_SEPARATOR);

        if (preg_match('#^s?ftp://#', $dir)) {
            $dir .= '/';
        }

        return $dir;
    }
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);
	}
566975
public static function normalizePath($path)
    {
        if (is_string($path)) {
            return explode('.', $path);
        }

        if (!is_array($path)) {
            return [$path];
        }

        return $path;
    }
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;
    }