Parse a short schema and return the associated schema.

@param array $arr The schema array.
@param mixed[] $args Constructor arguments for the schema instance.
@return static Returns a new schema.
510647
public static function parse(array $arr, ...$args) {
        $schema = new static([], ...$args);
        $schema->schema = $schema->parseInternal($arr);
        return $schema;
    }
1155240
private function recurseAndParseSchemas(array $array, $rootDir)
    {
        foreach ($array as &$value) {
            if (\is_array($value)) {
                if (isset($value['schema'])) {
                    $fileDir = $this->getCachedFilePath($value['schema']);
                    $schema = null;
                    foreach ($this->schemaParsers as $schemaParser) {
                        try {
                            $schemaParser->setSourceUri(
                                'file://' . ($fileDir ? $fileDir : $rootDir . DIRECTORY_SEPARATOR)
                            );
                            $schema = $schemaParser->createSchemaDefinition($value['schema']);

                            break;
                        } catch (\RuntimeException $e) {
                        }
                    }

                    if ($schema === null) {
                        throw new InvalidSchemaFormatException();
                    }

                    $value['schema'] = $schema;
                } else {
                    $value = $this->recurseAndParseSchemas($value, $rootDir);
                }
            }
        }

        return $array;
    }
720843
public function getFields(array $args = [])
    {
        if (empty($args)) {
            return $this->fields;
        }

        return \array_filter($this->fields, function (AbstractType $field) use ($args) {
            return $field->filter($args);
        });
    }
398358
public static function rearrangePostedFiles($arr)
    {
        $new = array();
        foreach ($arr as $key => $all) {
            if (is_array($all)) {
                foreach ($all as $i => $val) {
                    $new[$i][$key] = $val;
                }
            } else {
                $new[0][$key] = $all;
            }
        }

        return $new;
    }
921797
public function merge(...$args): self
    {
        $args = array_map([Arr::class, 'toArray'], $args);

        return new static(array_merge($this->storage, ...$args));
    }
967265
public static function schemaBasedArray($tname, $iArray) {

        if (empty($tname) or empty($iArray)) return array();
        
        $fields = self::fieldsKey($tname);
        $carray = array_merge(array_flip($fields), $iArray);
        return self::aIntersec($carray, $fields);
    }
25801
public function _parse($args)
    {
        $this->_values = [];
        $this->_options = [];

        if (in_array(end($args), ['', '-', '--'], true)) {
            array_pop($args);
        }

        while ($args) {
            $o = array_shift($args);
            if ($o[0] !== '-') {
                $this->_values[] = $o;
                continue;
            }

            if (preg_match('#^-((\w)|-([\w-_]+))=(.*)$#', $o, $match)) {
                $this->_options[$match[2]] = $match[4];
                continue;
            }

            if ($o[1] === '-') {
                if (strlen($o) < 3) {
                    throw new ArgumentsException(['long `:option` option is too short', 'option' => $o]);
                }

                $this->_options[substr($o, 2)] = !$args || $args[0] === '-' ? 1 : array_shift($args);
            } elseif (strlen($o) > 2) {
                if (!$args || $args[0][0] === '-') {
                    /** @noinspection PhpParamsInspection */
                    foreach (str_split(substr($o, 1), 1) as $c) {
                        $this->_options[$c] = 1;
                    }
                } else {
                    $this->_options[substr($o, 1)] = array_shift($args);
                }
            } else {
                $this->_options[substr($o, 1)] = !$args || $args[0] === '-' ? 1 : array_shift($args);
            }
        }

        return $this;
    }
326470
protected static function createInstance(array $args = [])
    {
        if (!self::$reflection) {
            self::$reflection = new \ReflectionClass('IntlDateFormatter');
        }

        $instance = self::$reflection->newInstanceArgs($args);

        self::checkInternalClass($instance, '\IntlDateFormatter', $args);

        return $instance;
    }
388797
public function data($args)
    {
        foreach (func_get_args() as $arg) {
            if (is_array($arg)) {
                $this->data = array_merge_recursive($arg, $this->data);
            } else {
                $this->data[] = $arg;
            }
        }

        return $this;
    }
516414
protected static function get_instances($arr) {
        $result = array();
        foreach ($arr as $key => $sub) {
            $result[$key] = new subscription($sub);
        }
        return $result;
    }
747560
public function decode(array $args)
    {
        $decoded = [];

        foreach ($args as $arg) {

            if (!is_string($arg)) {
                $decoded[] = $arg;
                continue;
            }

            $decoded[] = $this->deserialize($arg);

        }

        return $decoded;
    }
887906
public static function setInstance($args)
    {
        $name = array_shift($args);

        $name = self::getAccessor($name);

        $reflect = new \ReflectionClass($name);

        return $reflect->newInstanceArgs($args);
    }
378868
public function parse(Array $arguments)
    {
        $this->arguments = array();
        $arguments = new ArgumentIterator($arguments);

        foreach ($arguments as $current) {

            $arguments->next();
            $next = ($arguments->valid() ? $arguments->current() : '');
            $arguments->prev();

            $arg1 = substr($current, 0, 1);
            $arg2 = substr($current, 0, 2);

            if ('--' == $arg2) {

                // ~ Case '--test'
                $arg = array();
                $match = preg_match('`--([0-9a-z_-]+)="?(.+)"?`', $current, $arg);

                if ($match > 0) {
                    $this->arguments[$arg[1]] = $arg[2];
                } else
                    if (! empty($next) && '-' !== substr($next, 0, 1)) {
                        $this->arguments[substr($current, 2)] = $next;
                    } else {
                        $this->arguments[substr($current, 2)] = true;
                    }
            } elseif ('-' == $arg1) {

                // ~ case -t
                $arg = substr($current, 1);
                $len = strlen($arg);

                if (1 == $len && ! empty($next) && '-' != substr($next, 0, 1)) {
                    $this->arguments[$arg] = $next;
                } else {
                    for ($letter = 0; $letter < $len; $letter ++) {
                        $this->arguments[$arg[$letter]] = true;
                    }
                }
            }
        }

        return $this;
    }
600725
public function setResponseArray(array $args = [])
    {
        foreach ($args as $name => $text) {
            return $this->response[$name] = $text;
        }
        return $this;
    }
650901
private function parseArgs(array $args)
    {
        if (! count($args)) {
            return $this->createHelpArgument();
        }

        $arg1 = array_shift($args);

        if (in_array($arg1, ['-h', '--help', 'help'], true)) {
            return $this->createHelpArgument();
        }

        if (! count($args)) {
            return $this->createErrorArgument('Missing class name');
        }

        $configFile = $arg1;
        switch (file_exists($configFile)) {
            case true:
                $config = require $configFile;

                if (! is_array($config)) {
                    return $this->createErrorArgument(sprintf(
                        'Configuration at path "%s" does not return an array.',
                        $configFile
                    ));
                }

                break;
            case false:
                // fall-through
            default:
                if (! is_writable(dirname($configFile))) {
                    return $this->createErrorArgument(sprintf(
                        'Cannot create configuration at path "%s"; not writable.',
                        $configFile
                    ));
                }

                $config = [];
                break;
        }

        $class = array_shift($args);

        if (! class_exists($class)) {
            return $this->createErrorArgument(sprintf(
                'Class "%s" does not exist or could not be autoloaded.',
                $class
            ));
        }

        return $this->createArguments(self::COMMAND_DUMP, $configFile, $config, $class);
    }
662249
private static function schemaCache(...$args)
    {
        if (count($args) == 1) {
            $key = array_pop($args);
            if (isset(static::$schema_cache[$key])) {
                return static::$schema_cache[$key];
            }

            return false;
        }

        list($key, $value) = $args;

        static::$schema_cache[$key] = $value;
    }
836015
public static function flatten(array $arr)
    {
        $flat = [];
        foreach ($arr as $v) {
            if (is_array($v)) {
                $flat = array_merge($flat, self::flatten($v));
            } else {
                $flat[] = $v;
            }
        }
        return $flat;
    }