Garden\Schema::parseShortParam PHP Méthode

parseShortParam() public static méthode

Parse a short parameter string into a full array parameter.
public static parseShortParam ( string $str, array $other = [] ) : array
$str string The short parameter string to parse.
$other array An array of other information that might help resolve ambiguity.
Résultat array Returns an array in the form [name, [param]].
    public static function parseShortParam($str, $other = [])
    {
        // Is the parameter optional?
        if (self::strEnds($str, '?')) {
            $required = false;
            $str = substr($str, 0, -1);
        } else {
            $required = true;
        }
        // Check for a type.
        $parts = explode(':', $str);
        if (count($parts) === 1) {
            if (isset($other['type'])) {
                $type = $other['type'];
            } else {
                $type = 'string';
            }
            $name = $parts[0];
        } else {
            $name = $parts[1];
            if (isset(self::$types[$parts[0]])) {
                $type = self::$types[$parts[0]];
            } else {
                throw new \InvalidArgumentException("Invalid type {$parts[1]} for field {$name}.", 500);
            }
        }
        $result = ['name' => $name, 'type' => $type, 'required' => $required];
        return $result;
    }