Parse button definition.

@param string|array $definition Button definition.

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

            return $definition;
        }

        return $definition;
    }
1313100
public function map($definition)
    {
        $fixed = preg_replace('/\s+/', ' ', $definition);
        if (empty($fixed)) {
            return;
        }
        
        $names = explode(' ', $fixed);
        $newArgs = [];
        foreach ($this->args as $key => $value) {
            if (!is_int($key) && in_array($key, $names)) {
                throw new \Exception("Duplicate key {$key}");
            }

            if (is_int($key) && isset($names[$key])) {
                //Map command
                $newArgs[$names[$key]] = $value;
            } else {
                //Ignore options
                $newArgs[$key] = $value;
            }
        }
        $this->args = $newArgs;
    }
1032402
public static function get_definition_name($definition) {
        if ($definition instanceof cache_definition) {
            return $definition->get_name();
        }
        $identifier = 'cachedef_'.clean_param($definition['area'], PARAM_STRINGID);
        $component = $definition['component'];
        if ($component === 'core') {
            $component = 'cache';
        }
        return new lang_string($identifier, $component);
    }
249752
public function bind(Definition $definition) {
        $this->arguments = [];
        $this->options = [];
        $this->definition = $definition;

        $this->parse();
    }
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;
    }
579764
public function parse($definition)
    {
        $values = explode(' ', $definition);
        $direction = $this->getDirection($values);
        $values = explode('/', $values[0]);
        $type = $values[0];

        switch (strtolower($type)) {
            case 'depth':
                return new Depth($direction);
            case 'field':
                return $this->buildFieldSortClause($values, $direction);
            case 'modified':
                return new DateModified($direction);
            case 'name':
                return new ContentName($direction);
            case 'priority':
                return new Priority($direction);
            case 'published':
                return new DatePublished($direction);
        }

        throw new InvalidArgumentException(
            "Could not handle sort type '{$type}'"
        );
    }
1322758
protected function parsePropDefinition(string $propKey, $definition): PropDefinition
    {
        return new PropDefinition($propKey, $this->getDefinitionParser()
            ->parse($definition));
    }
478118
public function addDefinition(string $name, array $definition)
    {
        if (isset($this->_definition[$name])) {
            throw new Exception('Definition for "' . $name . '" already exists');
        }

        $this->_definition[$name] = $definition;

        return $this;
    }
1255926
private static function parseDropdownChild($dropdown, $button)
    {
        if ($dropdown === false || !$dropdown instanceof Dropdown) {
            // @codingStandardsIgnoreStart
            // TODO throw exception?
            // @codingStandardsIgnoreEnd
            return;
        }

        if ($button['type'] == 'child') {
            $child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
        } else {
            if ($dropdown->getChildren()) {
                $child = static::createDropdownDivider();
                $dropdown->addChild($child);
            }

            $child = static::createDropdownHeader($button['label'], $button['attributes'], true);
        }

        $dropdown->addChild($child);
    }
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);
    }
949378
private function parseRuleDefinition($key, $definition): Rule
    {
        if (is_string($definition)) {

            $parts = preg_split('/:/', $definition, 2);

            $factory_name = $parts[0];
            $parameters = $parts[1] ?? null;

            $parameters = ! is_null($parameters)
                ? explode(',', $parameters)
                : [];

            $factory_name = trim($factory_name);
            $parameters = array_map('trim', $parameters);

            $factory = $this->getRuleFactory($factory_name);

            $name = is_string($key) ? $key : $factory_name;
            $validate = $factory($parameters);

            return new Rule($name, $validate);

        }

        // is_callable must be AFTER is_string, otherwise factories named like a
        // php function can't be used (ex: date).
        if (is_callable($definition)) {

            return new Rule((string) $key, $definition);

        }

        throw new InvalidRuleFormatException($definition);
    }
870894
protected function extractParameters(\stdClass $definition)
    {
        $parameters = [];

        if (isset($definition->parameters)) {
            foreach ($definition->parameters as $parameterDefinition) {
                $parameters[] = $this->createParameter($parameterDefinition);
            }
        }

        return $parameters;
    }
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;
    }
447908
private function getOptions(InputDefinition $definition, array $options): array
    {
        $argv = [];
        foreach ($options as $name => $value) {
            $definition->getOption($name) && $argv[] = sprintf('--%s=%s', $name, $value);
        }
        return $argv;
    }
178557
protected function parseOperationData($definition)
    {
        $crawler = new Crawler($definition);

        $operationFilter = $crawler->filter('h2');
        $operation = str_replace(' ', '', $operationFilter->first()->text());

        $uriData = $crawler->filter('.uri div');

        preg_match('|[^/]*([^\n]*)\n|', $uriData->text(), $matches);
        $uri = $matches[1];

        $uriParams = array();
        if (strpos($uri, ':') !== false) {
            preg_match_all('|(:[^/]*)|', $uri, $uriParams);
            $uriParams = array_shift($uriParams);
        }

        $method = $uriData->filter('.muted')->text();

        $summaryNode = $crawler->filter('.leading-top p');
        $summary = ($summaryNode->count() > 0) ? $summaryNode->text() : null;

        $parameterList = $crawler->filter('dl.rounded-all dt span');
        $params = array();
        foreach ($parameterList as $parameter) {
            /* @var $parameter DOMElement */

            $params[$parameter->textContent] = array(
                'required' => ($parameter->getAttribute('class') == 'param_required'),
                'location' => ($method == 'GET') ? 'query' : 'postField',
            );
        }

        if (isset($uriParams) && count($uriParams) > 0) {
            foreach ($uriParams as $param) {
                $params[str_replace(':', '', $param)] = array(
                    'required' => true,
                    'location' => 'uri',
                );
            }
        }

        //Update Operation
        if ($method == 'GET') {
            $operation = ucfirst(strtolower($method).$operation);
        }

        return array(
            'operation'  => $operation,
            'httpMethod' => $method,
            'uri'        => $uri,
            'summary'    => $summary,
            'parameters' => $params,
        );
    }
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);
    }
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();
        };
    }