Process arguments

@param  array    $args
@param  stdClass $definition
@throws InvalidConfig
@return array
358974
protected function processArguments(array $args) {
		$definition = [];
		
		foreach ($args as $arg) {
			if ($arg->getName() !== 'argument') {
				throw new InvalidConfig('Unknown element "' . $arg->getName() . '" in arguments definition', null, null, $arg);
			}

			$definition[] = $this->processArgument($arg);
		}
		
		return $definition;
	}
330840
public function execute(array $args = [], array $options = [])
    {
        $options += [
            'format' => $this->getDefaultFormat(),
            'encode' => 'raw',
        ];

        $s = $this->getConfigService();

        switch ($options['format']) {
            case 'env':
                $s->setDumper(new ConfigDumper\ShellEnvironmentConfigDumper());
                break;
            case 'json':
                $s->setDumper(new ConfigDumper\JsonConfigDumper());
                break;
            case 'php':
                $s->setDumper(new ConfigDumper\PhpConfigDumper());
                break;
            case 'serialized':
                $s->setDumper(new ConfigDumper\SerializedConfigDumper());
                break;
            case 'yaml':
                $s->setDumper(new ConfigDumper\YamlConfigDumper());
                break;
            default:
                throw new \RuntimeException(sprintf("Unsupported format '%s'", $options['format']), 3);
        }

        switch ($options['encode']) {
            case 'base64':
                $s->addDumpEncoder(new DumpEncoder\Base64DumpEncoder());
                break;
            case 'sha1':
                $s->addDumpEncoder(new DumpEncoder\Sha1DumpEncoder());
                break;
            case 'md5':
                $s->addDumpEncoder(new DumpEncoder\Md5DumpEncoder());
                break;
            case 'raw':
                break;
            default:
                throw new \RuntimeException(sprintf("Unsupported dump encoder '%s'", $options['encoder']), 3);
        }

        $s->addPrinter(new Printer\ConsolePrinter());

        $input = $this->getInput();

        if (null === $input) {
            throw new \RuntimeException('No input available for command', 10);
        }

        $output = $this->getOutput();

        if (null === $output) {
            throw new \RuntimeException('No output available for command', 11);
        }

        $s->processLoaded($input, $output, $this->getData());
    }
122672
protected function createRule(string $className, array $args = [])
    {
        if (!class_exists($className)) {
            throw new InvalidArgumentException("Class \"$className\" does not exist");
        }

        /** @var IRule|IRuleWithArgs $rule */
        $rule = new $className;

        if ($rule instanceof IRuleWithArgs) {
            $rule->setArgs($args);
        }

        $this->addRule($rule);
    }
680693
public function resolver($definition, array $args = [])
    {
        if ($definition instanceof Closure) {
            $resolvedDefinition = call_user_func_array($definition, $args);
        } elseif (is_object($definition)) {
            $resolvedDefinition = $definition;
        } elseif (is_string($definition)) {
            if (class_exists($definition)) {
                $reflectionObj = new ReflectionClass($definition);
                $resolvedDefinition = $reflectionObj->newInstanceArgs($args);
            } else {
                throw new Exception(sprintf('Class "%s" does not exist.', $definition));
            }
        } elseif (is_array($definition)) {
            $resolvedDefinition = self::fromArray($definition);
        } else {
            throw new Exception(sprintf('Definition type "%s" does not support.', gettype($definition)));
        }

        return $resolvedDefinition;
    }
1038708
public function change($arg, $value = null) {
        $id = $this->getId();
        $this->reset();
        if (!$value) {
            if ($arg instanceof \stdClass) {
                $this->setEntity($arg);
            } else {
                if (!is_array($arg)) {
                    throw new InvalidArgumentException("values is not array");
                }
                foreach ($arg as $key_values) {
                    if (!is_array($key_values)) {
                        throw new InvalidArgumentException("values item must be [key, value]");
                        $this->set($key_values[0], $key_values[1]);
                    }
                };
            }
        } else {
            if (is_array($arg)) {
                $this->set($arg, $value);
            } else {
                $this->set([$arg], $value);
            }
        };
        $this->setId($id);
        return $this->partialUpdate(null);
    }
1337561
protected function processArgumentParameter(stdClass $argument) {
		if (! isset($argument->name)) {
			throw new Exceptions\InvalidConfig('Argument of type "parameter" must contain a "name" property');
		}
		
		$config = $this->container->getParametersConfig();
		$name   = trim($argument->name);
		
		if (! empty($argument->deferred)) {
			return new ConfigReference($config, $name);
		}
		
		if (! $config->has($name)) {
			throw new Exceptions\InvalidConfig('Config contains no "' . $name . '" parameter');
		}
		
		return $config->get($name);
	}
831320
protected function initValues(array $args)
    {
        $uses = class_uses(get_class($this));
        foreach ($uses as $use) {
            $resetMethod = 'init' . basename(strtr($use, '\\', '/'));
            if (method_exists($this, $resetMethod)) {
                $this->$resetMethod($args);
            }
        }
        return $this;
    }
1307789
public function create($class, $args = [])
    {
        $class = (string) $class;

        if (empty($class)) {
            throw new InvalidArgumentException(
                'Cannot create a migration from an empty class name!'
            );
        }

        if (!is_array($args)) {
            throw new InvalidArgumentException(
                'Argument "params" must be an array of parameters.'
            );
        }

        if (!empty($args)) {
            $class = new \ReflectionClass($class);
            $instance = $class->newInstanceArgs($args);
        } else {
            $instance = new $class();
        }

        return $instance;
    }
437474
public function execute(array $args = [], array $options = [])
    {
        /** @var CommandInterface[] $commands */
        $commands = $this->getConfig()->get('commands');

        $all = isset($options['all']) && true === $options['all'];

        $selectedCommands = [];
        foreach ($commands as $n => $c) {
            $hidden = false;
            $realName = $n;
            if ('_' === $n{0}) {
                if (!$all) {
                    continue;
                }
                $hidden = true;
                $n = substr($n, 1);
            }
            $selectedCommands[$n] = ['hidden' => $hidden, 'realName' => $realName, 'command' => $c];
        }

        ksort($selectedCommands);

        $user = $this->getConfig()->get('user_name');

        if ($user) {
            $this->writeln('<comment>DEV Console command</comment> (Happy hacking %s !)', $user);
        } else {
            $this->writeln('<comment>DEV Console command</comment>');
        }
        $this->writeln();
        $this->writeln('%d commands:', count($selectedCommands));

        $max = 0;

        foreach ($selectedCommands as $commandName => $def) {
            $len = strlen($commandName);
            $max = $max < $len ? $len : $max;
        }

        $lastLetter = null;

        foreach ($selectedCommands as $commandName => $def) {
            $letter = $commandName{0};
            if ($lastLetter !== $letter) {
                $this->writeln();
            }
            /** @var CommandInterface $command */
            $command = $def['command'];
            $command->setConfig($this->getConfig());
            $this->writeln("  <".($def['hidden'] ? 'comment' : 'info').">%-".$max."s</".($def['hidden'] ? 'comment' : 'info').">  <comment>%s</comment>", $commandName, $command->getDescription());
            $lastLetter = $letter;
        }

        $this->writeln();
    }
841911
public function execute($args)
    {
        self::$definedProps = new Properties();
        $this->searchForThis = null;

        // 1) First handle any options which should always
        // Note: The order in which these are executed is important (if multiple of these options are specified)

        if (in_array('-help', $args) || in_array('-h', $args)) {
            static::printUsage();

            return;
        }

        if (in_array('-version', $args) || in_array('-v', $args)) {
            static::printVersion();

            return;
        }

        if (in_array('-init', $args) || in_array('-i', $args)) {
            $key = array_search('-init', $args) ?: array_search('-i', $args);
            $path = isset($args[$key + 1]) ? $args[$key + 1] : null;

            self::init($path);

            return;
        }

        if (in_array('-diagnostics', $args)) {
            Diagnostics::doReport(new PrintStream(self::$out));

            return;
        }

        // 2) Next pull out stand-alone args.
        // Note: The order in which these are executed is important (if multiple of these options are specified)

        if (false !== ($key = array_search('-quiet', $args, true)) || false !== ($key = array_search(
            '-q',
            $args,
            true
        ))
        ) {
            self::$msgOutputLevel = Project::MSG_WARN;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-emacs', $args, true))
            || false !== ($key = array_search('-e', $args, true))
        ) {
            $this->emacsMode = true;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-verbose', $args, true))) {
            self::$msgOutputLevel = Project::MSG_VERBOSE;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-debug', $args, true))) {
            self::$msgOutputLevel = Project::MSG_DEBUG;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-silent', $args, true))
            || false !== ($key = array_search('-S', $args, true))
        ) {
            $this->silent = true;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-propertyfileoverride', $args, true))) {
            $this->propertyFileOverride = true;
            unset($args[$key]);
        }

        // 3) Finally, cycle through to parse remaining args
        //
        $keys = array_keys($args); // Use keys and iterate to max(keys) since there may be some gaps
        $max = $keys ? max($keys) : -1;
        for ($i = 0; $i <= $max; $i++) {
            if (!array_key_exists($i, $args)) {
                // skip this argument, since it must have been removed above.
                continue;
            }

            $arg = $args[$i];

            if ($arg == "-logfile") {
                try {
                    // see: http://phing.info/trac/ticket/65
                    if (!isset($args[$i + 1])) {
                        $msg = "You must specify a log file when using the -logfile argument\n";
                        throw new ConfigurationException($msg);
                    }

                    $logFile = new PhingFile($args[++$i]);
                    $out = new FileOutputStream($logFile); // overwrite
                    self::setOutputStream($out);
                    self::setErrorStream($out);
                    self::$isLogFileUsed = true;
                } catch (IOException $ioe) {
                    $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions.";
                    throw new ConfigurationException($msg, $ioe);
                }
            } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a buildfile when using the -buildfile argument.";
                    throw new ConfigurationException($msg);
                }

                $this->buildFile = new PhingFile($args[++$i]);
            } elseif ($arg == "-listener") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a listener class when using the -listener argument";
                    throw new ConfigurationException($msg);
                }

                $this->listeners[] = $args[++$i];
            } elseif (StringHelper::startsWith("-D", $arg)) {
                // Evaluating the property information //
                // Checking whether arg. is not just a switch, and next arg. does not starts with switch identifier
                if (('-D' == $arg) && (!StringHelper::startsWith('-', $args[$i + 1]))) {
                    $name = $args[++$i];
                } else {
                    $name = substr($arg, 2);
                }

                $value = null;
                $posEq = strpos($name, "=");
                if ($posEq !== false) {
                    $value = substr($name, $posEq + 1);
                    $name = substr($name, 0, $posEq);
                } elseif ($i < count($args) - 1 && !StringHelper::startsWith("-D", $args[$i + 1])) {
                    $value = $args[++$i];
                }
                self::$definedProps->setProperty($name, $value);
            } elseif ($arg == "-logger") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a classname when using the -logger argument";
                    throw new ConfigurationException($msg);
                }

                $this->loggerClassname = $args[++$i];
            } elseif ($arg == "-no-strict") {
                $this->strictMode = false;
            } elseif ($arg == "-strict") {
                $this->strictMode = true;
            } elseif ($arg == "-inputhandler") {
                if ($this->inputHandlerClassname !== null) {
                    throw new ConfigurationException("Only one input handler class may be specified.");
                }
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a classname when using the -inputhandler argument";
                    throw new ConfigurationException($msg);
                }

                $this->inputHandlerClassname = $args[++$i];
            } elseif ($arg === "-propertyfile") {
                $i = $this->handleArgPropertyFile($args, $i);
            } elseif ($arg === "-keep-going" || $arg === "-k") {
                $this->keepGoingMode = true;
            } elseif ($arg == "-longtargets") {
                self::$definedProps->setProperty('phing.showlongtargets', 1);
            } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") {
                // set the flag to display the targets and quit
                $this->projectHelp = true;
            } elseif ($arg == "-find") {
                // eat up next arg if present, default to build.xml
                if ($i < count($args) - 1) {
                    $this->searchForThis = $args[++$i];
                } else {
                    $this->searchForThis = self::DEFAULT_BUILD_FILENAME;
                }
            } elseif (substr($arg, 0, 1) == "-") {
                // we don't have any more args
                self::printUsage();
                self::$err->write(PHP_EOL);
                throw new ConfigurationException("Unknown argument: " . $arg);
            } else {
                // if it's no other arg, it may be the target
                $this->targets[] = $arg;
            }
        }

        // if buildFile was not specified on the command line,
        if ($this->buildFile === null) {
            // but -find then search for it
            if ($this->searchForThis !== null) {
                $this->buildFile = $this->_findBuildFile(self::getProperty("user.dir"), $this->searchForThis);
            } else {
                $this->buildFile = new PhingFile(self::DEFAULT_BUILD_FILENAME);
            }
        }

        try {
            // make sure buildfile (or buildfile.dist) exists
            if (!$this->buildFile->exists()) {
                $distFile = new PhingFile($this->buildFile->getAbsolutePath() . ".dist");
                if (!$distFile->exists()) {
                    throw new ConfigurationException(
                        "Buildfile: " . $this->buildFile->__toString() . " does not exist!"
                    );
                }
                $this->buildFile = $distFile;
            }

            // make sure it's not a directory
            if ($this->buildFile->isDirectory()) {
                throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is a dir!");
            }
        } catch (IOException $e) {
            // something else happened, buildfile probably not readable
            throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is not readable!");
        }

        $this->loadPropertyFiles();

        $this->readyToRun = true;
    }
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;
    }
1303048
public function make($concrete, array $args = [])
    {
        // build only from strings
        if (!is_object($concrete) && !is_scalar($concrete) && !is_null($concrete)) {
            throw new Exceptions\InvalidArgumentException();
        }

        // get reflection and parameters
        $reflection = new \ReflectionClass($concrete);
        $constructor = $reflection->getConstructor();

        // Return new instance
        $arguments = $constructor ? $this->inject($constructor, $args) : [];
        return $reflection->newInstanceArgs($arguments);
    }
109034
static public function formatName($definition)
	{
	    if (is_string($definition)) {
	        return $definition;
	    } elseif (is_object($definition)) {
	        return get_class($definition);
	    } elseif (is_array($definition)) {
	        if (!isset($definition['class'])) {
	            $name = $definition[0];
	        } else {
	            $name = $definition['class'];
	        }
	    } else {
	        throw new InvalidConfigException("Unsupported definition for :" . gettype($definition));
	    }
	}
139206
protected function _translateArgs($args) {
		foreach ((array)$args as $k => $arg) {
			if (is_string($arg)) {
				$args[$k] = __d($this->validationDomain, $arg);
			}
		}
		return $args;
	}
358159
public function loadArguments($data, callable $callable, Context $context): array
    {
        if (is_object($data) && $data instanceof \stdClass) {
            $data = get_object_vars($data);
        }

        if (!is_array($data)) {
            throw new InvalidDataException('Argument data must array or stdClass');
        }

        $metadata = $this->callableMetadataProvider->getCallableMetadata($callable);

        $args = [];
        $paramPos = 0;
        $argPos = 0;
        while ($paramPos < count($metadata->parameters)) {
            $param = $metadata->parameters[$paramPos];
            $mangledName = $this->nameMangler->mangle($param->name);

            $key = null;
            if (array_key_exists($argPos, $data)) {
                $key = $argPos;
            } elseif (array_key_exists($mangledName, $data)) {
                $key = $mangledName;
            }

            if ($key !== null) {
                $context->pushPath('$' . $key);
                try {
                    $args[] = $this->loader->load($data[$key], $param->type, $context);
                } finally {
                    unset($data[$key]);
                    $context->popPath();
                }
            } elseif ($param->optional) {
                if ($param->variadic) {
                    break;
                }
                $args[] = $param->defaultValue;
            } else {
                throw new InvalidDataException("Required argument $param->name missing");
            }

            $argPos++;
            if (!$param->variadic) {
                $paramPos++;
            }
        }

        if (!empty($data) && $this->throwOnUnknownArgument) {
            throw new InvalidDataException(
                'Some arguments could not be matched: ' . implode(', ', array_keys($data))
            );
        }

        return $args;
    }
282037
public function setArgDefaults(array $argData)
    {
        foreach ($argData as $argName => $default) {
            /* @var ArgumentScaffolder $arg */
            $arg = $this->args->find('argName', $argName);
            if (!$arg) {
                throw new InvalidArgumentException(sprintf(
                    'Tried to set default for %s, but it was not added to %s',
                    $argName,
                    $this->operationName ?: '(unnamed operation)'
                ));
            }

            $arg->setDefaultValue($default);
        }

        return $this;
    }
210895
private static function formatArgsForExpression(array $args)
    {
        $mapping = [];
        foreach ($args as $name => $config) {
            $mapping[] = \sprintf('%s: "%s"', $name, $config['type']);
        }

        return \sprintf('arguments({%s}, args)', \implode(', ', $mapping));
    }