Creates the arguments from the current class state.

@param ArgsFormat $format  The format.
@param RawArgs    $rawArgs The raw arguments.

@return Args The created console arguments.
501476
private function createArgs(ArgsFormat $format, RawArgs $rawArgs)
    {
        $args = new Args($format, $rawArgs);

        foreach ($this->arguments as $name => $value) {
            // Filter command names
            if ($format->hasArgument($name)) {
                $args->setArgument($name, $value);
            }
        }

        foreach ($this->options as $name => $value) {
            // Filter command options
            if ($format->hasOption($name)) {
                $args->setOption($name, $value);
            }
        }

        return $args;
    }
760217
public static function format($format, ...$args): self
    {
        Assert::typeOf(['string', __CLASS__], $format);

        return new static(sprintf((string) $format, ...$args));
    }
311726
public function setEmailFormat($format)
    {
        if (!in_array($format, $this->_emailFormatAvailable)) {
            throw new InvalidArgumentException('Format not available.');
        }
        $this->_emailFormat = $format;

        return $this;
    }
274287
protected function applyDefaultFormat($format, $options, $data)
    {
        $aClassFunc = $this->getFuncParams($options);

        $params = array_key_exists('params', $format) && isset($options['params']) ? $format['params'] : [];

        if (!is_array($params)) {
            $params = [$params];
        }

        array_unshift($params, $data);

        $object = (new \ReflectionClass($aClassFunc['class']))->newInstance();

        $data = call_user_func_array([$object, $aClassFunc['method']], $params);

        return $data;
    }
499739
public static void print(String format, Object... args) {

        Object[] stringArgs = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            stringArgs[i] = ObjectUtils.toString(args[i]);
        }
        print(String.format(format, stringArgs));
    }
717796
public function format($format = 'date', $timestamp = null)
    {
        $timestamp = is_numeric($timestamp) ? '@'.intval($timestamp) : $timestamp;
        $timestamp = is_a($timestamp, 'DateTime') ? $timestamp : new DateTime($timestamp);

        $key = $this->getTranslationKey("date.formats.{$format}");
        $format = $this->translator->has($key) ? $this->translator->get($key) : null;

        if (is_null($format)) {
            throw new \InvalidArgumentException('Date format is invalid or does not exists in current language');
        }

        return strftime($format, $timestamp->format('U'));
    }
1293996
public function format($format = true)
    {
        if (!is_bool($format)) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 1 to be boolean, %s given', __METHOD__, gettype($format)));
        }

        $this->document->formatOutput = $format;

        return $this;
    }
864480
protected function getDefinition(
        /*# string */ $rawId,
        array $args
    )/*# : array */ {
        // get the definition
        $def = $this->getResolver()->getService($rawId);

        // fix class
        if (!is_array($def) || !isset($def['class'])) {
            $def = ['class' => $def];
        }

        // add arguments
        if (!empty($args)) {
            $def['args'] = $args;
        }

        return (array) $def;
    }
400379
private function parseArgs($rawArgs) {
        if (!is_array($rawArgs)) {
            throw new ServiceContainerException('constructor-args or call argument must be array!');
        }

        if (empty($rawArgs)) {
            return [];
        }

        $args = [];
        foreach ($rawArgs as $rawArg) {
            $args[] = $this->parseArg($rawArg);
        }
        return $args;
    }
605471
public static function createFromFormat($time, $format = null)
    {
        if (self::isNull($format)) {
            $format = self::$defaultFormat;
        }

        try {
            $date = \DateTime::createFromFormat($format, $time);
            if (!$date) {
                throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT);
            }
        } catch (\Exception $e) {
            throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT);
        }

        try {
            $dt = new DateTimeObject();
            $dt->setTimestamp($date->getTimestamp());
            $dt->setFormat($format);
        } catch (\Exception $e) {
            throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT);
        }

        return $dt;
    }
594028
public function format(?string $format = null, array $config = []): self
    {
        if (! \is_null($format) && ! empty($format)) {
            $this->setFormat($format);

            if (! empty($config)) {
                $this->when($format, $config);
            }
        }

        return $this;
    }
661466
private function createBuilderForElements(array $elements, ArgsFormat $baseFormat = null)
    {
        $builder = new ArgsFormatBuilder($baseFormat);

        foreach ($elements as $element) {
            if ($element instanceof CommandName) {
                $builder->addCommandName($element);
            } elseif ($element instanceof CommandOption) {
                $builder->addCommandOption($element);
            } elseif ($element instanceof Option) {
                $builder->addOption($element);
            } elseif ($element instanceof Argument) {
                $builder->addArgument($element);
            } else {
                throw new InvalidArgumentException(sprintf(
                    'Expected instances of CommandName, CommandOption, '.
                    'Option or Argument. Got: %s',
                    is_object($element) ? get_class($element) : gettype($element)
                ));
            }
        }

        return $builder;
    }
893702
private function processDefaultCommands(RawArgs $args, CommandCollection $defaultCommands)
    {
        $firstResult = null;

        foreach ($defaultCommands as $defaultCommand) {
            $resolvedCommand = new ResolveResult($defaultCommand, $args);

            if ($resolvedCommand->isParsable()) {
                return $resolvedCommand;
            }

            if (!$firstResult) {
                $firstResult = $resolvedCommand;
            }
        }

        // Return the first default command if one was found
        return $firstResult;
    }
257789
public function setDataFormat($dataFormat)
    {
        if (!in_array($dataFormat, static::FORMATS)) {
            throw new \InvalidArgumentException("bad format '{$dataFormat}'");
        }
        $this->dataFormat = $dataFormat;

        return $this;
    }
1070804
public function formatArgs(array $args)
    {
        $result = [];
        foreach ($args as $key => $item) {
            if ('object' === $item[0]) {
                $parts = explode('\\', $item[1]);
                $short = array_pop($parts);
                $formattedValue = sprintf('<em>object</em>(<abbr title="%s">%s</abbr>)', $item[1], $short);
            } elseif ('array' === $item[0]) {
                $formattedValue = sprintf('<em>array</em>(%s)', \is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
            } elseif ('string' === $item[0]) {
                $formattedValue = sprintf("'%s'", htmlspecialchars($item[1], ENT_QUOTES, $this->getCharset()));
            } elseif ('null' === $item[0]) {
                $formattedValue = '<em>null</em>';
            } elseif ('boolean' === $item[0]) {
                $formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
            } elseif ('resource' === $item[0]) {
                $formattedValue = '<em>resource</em>';
            } else {
                $formattedValue = str_replace("\n", '', var_export(htmlspecialchars((string) $item[1], ENT_QUOTES, $this->getCharset()), true));
            }

            $result[] = \is_int($key) ? $formattedValue : sprintf("'%s' => %s", $key, $formattedValue);
        }

        return implode(', ', $result);
    }
950305
private function getException($format, $args = [])
    {
        /** @var FormatterHelper $formatter */
        $formatter = $this->getHelperSet()->get('formatter');
        return new \InvalidArgumentException($formatter->formatBlock(vsprintf($format, $args), 'bg=red', true));
    }
863877
public static function buildArgs($args)
    {
        if (!is_array($args)) {
            return '';
        }
        $ret = '';
        foreach ($args as $k => $v) {
            if (!is_int($v) && ($v !== null)) {
                $v = escapeshellarg($v);
            }
            if (is_int($k)) {
                $ret .= ' ' . $v;
            } else {
                if ($k{0} !== '-') {
                    $ret .= ' --' . $k . ($v !== null ? '=' . $v : '');
                } else {
                    $ret .= ' ' . $k . ($v !== null ? '=' . $v : '');
                }
            }
        }
        return $ret;
    }