Process argument of the type "value"

@param  stdClass $argument
@return mixed
@throws Exceptions\InvalidConfig
769466
protected function processArgumentValue(stdClass $argument) {
		if (! isset($argument->value)) {
			throw new Exceptions\InvalidConfig('Argument of type "value" must contain a "value" property');
		}

		if (is_array($argument->value)) {
			return $this->processArguments($argument->value);
		}

		return $argument->value;
	}
675176
protected function processArgumentBoolean(Element $arg) {
		$definition = new stdClass();
		$definition->type = 'value';
		
		if (isset($arg->value)) {
			$definition->value = (trim($arg->value) === 'true');
			return $definition;
		}
		
		$value = $arg->getValue();
		
		if (! empty($value)) {
			$definition->value = (trim($value) === 'true');
			return $definition;
		}
		
		throw new InvalidConfig('Definition of an argument type "boolean" must contain a value as content or the "value" attribute', null, null, $arg);
	}
527626
public function extract($value)
    {
        if (null === $value) {
            return $this->nullable ? null : [];
        }

        if (is_object($value)) {
            $objectPrototype = $this->getObjectPrototype();
            return $objectPrototype->getHydrator()->extract($value);
        }
                
        if (is_array($value)) {
            return $value;
        }

        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be null, or an array, or an object: "%s" given',
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
511980
private function normalizeDateValue($date)
    {
        if (is_string($date)) {
            $date = strtotime($date);
        } elseif ($date instanceof \DateTime) {
            $date = $date->format('U');
        } elseif (!is_int($date)) {
            throw new \InvalidArgumentException('Date values must be a '
                . 'string, an int, or a DateTime object.');
        }

        return $date;
    }
539994
public function setArguments(array $arguments)
    {
        switch ($this->argumentsType) {
            case self::ARGUMENTS_TYPE_EMPTY:
                if (!empty($arguments)) {
                    throw new InvalidCommandArgumentException($this, $arguments);
                }
                $arguments = [];
                break;
            case self::ARGUMENTS_TYPE_STRING:
                $this->checkStringArgument($arguments);
                $arguments = [$arguments[0]];
                break;
            case self::ARGUMENTS_TYPE_STRING_INT:
                $this->checkStringArgument($arguments, 2);
                if (!is_int($arguments[1])) {
                    throw new InvalidCommandArgumentException($this, $arguments);
                }
                $arguments = [$arguments[0], (int) $arguments[1]];
                break;
            case self::ARGUMENTS_TYPE_STRINGS:
                $this->checkStringArguments($arguments);
                break;
            // A fallback in case a non-existing argument type is defined.
            // This could be prevented by using an Enum as the argument type
            default:
                throw new InvalidCommandArgumentException($this, $arguments);
        }
        $this->arguments = $arguments;
    }
40650
protected function processArgumentService(Element $arg) {
		$definition = new stdClass();
		$definition->type = 'service';
		
		if (! isset($arg->id)) {
			throw new InvalidConfig('Definition of an argument type "service" must contain the "id" attribute', null, null, $arg);
		}
		
		$definition->id = trim($arg->id);
		
		$content = $arg->getContent();
			
		if (! empty($content)) {
			$this->processDefinitionParameters($content, $definition);
		}
		
		return $definition;
	}
1219293
protected function prepareHeaderValue($value)
    {
        if (is_string($value)) {
            $value = [$value];
        }
        if (! is_array($value)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid header value "%s"; must be a string or array of strings.',
                is_object($value) ? get_class($value) : gettype($value)
            ));
        }
        foreach ($value as &$item) {
            if (! is_string($item)) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid header value "%s"; must be a string.',
                    is_object($item) ? get_class($item) : gettype($item)
                ));
            }

            $item = trim($item);

            if ('' === $item) {
                throw new InvalidArgumentException(
                    'Empty header value provided.'
                );
            }

            if (preg_match('/[^\x09\x0a\x0d\x20-\x7E\x80-\xFE]/', $item)) {
                throw new InvalidArgumentException(sprintf(
                    'The header value "%s" contains illegal characters.',
                    $item
                ));
            }
            $item = preg_replace('/\s+/', ' ', $item);
        }

        return $value;
    }
836958
public function value($value, $type = null)
    {
        switch (true) {
            case is_object($value):
                if (!method_exists($value, '__toString')) {
                    throw new InvalidArgumentException('Object can not be converted to string value.');
                }
                $value = (string)$value;
                break;
            case is_bool($value):
                $value = (int)$value;
                break;
            case (is_numeric($value) && (string)($value + 0) === (string)$value):
                $value = $value + 0;
                break;
            case is_null($value):
                $value = 'NULL';
                break;
            case is_array($value):
                $value = array_map(function ($value) {
                    if (is_array($value)) {
                        $value = 'Array';
                    }
                    return $this->value($value);
                }, $value);
                $value = implode(', ', $value);
                break;
            default:
                $value = call_user_func($this->quoteFn, $value, $type);
        }

        return $value;
    }
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;
	}
618040
public function hydrate($value)
    {
        if ($value instanceof MongoId) {
            return (string)$value;
        }
        
        if ($this->nullable && $value === null) {
            return null;
        }
        
        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be an instance of MongoId, "%s" given.',
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
916504
public function check(...$args)
    {
        if (count($args) !== count($this->constraints)) {
            throw new InvalidArgumentException(
                'Argument number mismatch.'
            );
        }

        foreach ($args as $key => $arg) {
            if (!$this->constraints[$key]->check($arg, $args)) {
                throw new InvalidArgumentException(vsprintf(
                    'Argument %s does not meet its constraints.'
                    . "\nFailed constraint: %s\nValue provided:%s",
                    [
                        $key,
                        $this->constraints[$key]->toString(),
                        print_r($arg, true)
                    ]
                ));
            }
        }
    }
249926
public function processParameterValue($value)
    {
        if (is_scalar($value)) {
            return $value;
        }

        if ($value instanceof Mapping\ClassMetadata) {
            return $value->discriminatorValue ?: $value->getClassName();
        }

        if ($value instanceof Collection) {
            $value = $value->toArray();
        }

        if (is_array($value)) {
            foreach ($value as $key => $paramValue) {
                $paramValue  = $this->processParameterValue($paramValue);
                $value[$key] = is_array($paramValue) ? reset($paramValue) : $paramValue;
            }

            return $value;
        }

        if (is_object($value) && $this->em->getMetadataFactory()->hasMetadataFor(StaticClassNameConverter::getClass($value))) {
            $value = $this->em->getUnitOfWork()->getSingleIdentifierValue($value);

            if ($value === null) {
                throw ORMInvalidArgumentException::invalidIdentifierBindingEntity();
            }
        }

        return $value;
    }
101774
protected function processConfigVariables($value, $prefix = null)
    {
        if ($prefix && !preg_match('~^[a-z0-9._-]*$~i', $prefix)) {
            throw new exception\InvalidArgumentException('Invalid config var prefix: ' . $prefix);
        }

        if ($prefix) {
            // dots should be literal in regex
            $prefix = strtr($prefix, '.', '\\.');
        }

        $config = $this;
        $value = preg_replace_callback("~{{({$prefix}[a-z0-9._-]+)}}~i", function($match) use ($config) {
            return (string)$config->getConfigValue($match[1], '');
        }, $value);

        return $value;
    }
689422
protected function processArgument(Element $arg) {
		// Value of the special types:
		if (isset($arg->type)) {
			$type = strtolower(trim($arg->type));
			
			switch ($type) {
				case 'bool':
				case 'boolean':
					return $this->processArgumentBoolean($arg);
					
				case 'service':
					return $this->processArgumentService($arg);
					
				case 'parameter':
					return $this->processArgumentParameter($arg);
					
				case 'null':
					return $this->processArgumentNull($arg);
					
				case 'array':
					return $this->processArgumentArray($arg);
			}
			
			throw new InvalidConfig('Invalid type of argument: "' . $type . '"', null, null, $arg);
		}
		
		// Scalar value: string, int, float
		$definition = new stdClass();
		
		if (isset($arg->value)) {
			$definition->type  = 'value';
			$definition->value = Std::parseValue($arg->value);
			
			return $definition;
		}
		
		$value = $arg->getValue();
		
		if (! empty($value)) {
			$definition->type  = 'value';
			$definition->value = Std::parseValue($value);
			
			return $definition;
		}
		
		throw new InvalidConfig('Invalid definition of argument', null, null, $arg);
	}
461000
static function ensureValue($value)
    {
        if (!self::hasValue($value)) {
            throw new InvalidValueException(sprintf(
                'The value %s is not defined in enum class "%s", known values: %s',
                self::dumpValue($value),
                static::class,
                implode(', ', array_map([static::class, 'dumpValue'], self::getValues()))
            ));
        }
    }
95015
protected function processArguments($arguments) {
		$processedArgs = [];
		
		foreach ($arguments as $key => $argument) {
			if (! isset($argument->type)) {
				throw new Exceptions\InvalidConfig('Argument definition must contain a "type" property"');
			}
			
			$type = strtolower(trim($argument->type));
			
			if ($type === 'value') {
				$processedArgs[$key] = $this->processArgumentValue($argument);
				continue;
			}
			
			if ($type === 'service') {
				$processedArgs[$key] = $this->processArgumentService($argument);
				continue;
			}
			
			if ($type === 'parameter') {
				$processedArgs[$key] = $this->processArgumentParameter($argument);
				continue;
			}
			
			throw new Exceptions\InvalidConfig('Unknown type of argument: "' . $type . '"');
		}
		
		return $processedArgs;
	}
200688
public function setValue($value)
    {
        if ('checkbox' === $this->type && false === $value) {
            // uncheck
            $this->value = null;
        } elseif ('checkbox' === $this->type && true === $value) {
            // check
            $this->value = $this->options[0]['value'];
        } else {
            if (is_array($value)) {
                if (!$this->multiple) {
                    throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name));
                }

                foreach ($value as $v) {
                    if (!$this->containsOption($v, $this->options)) {
                        throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: %s).', $this->name, $v, implode(', ', $this->availableOptionValues())));
                    }
                }
            } elseif (!$this->containsOption($value, $this->options)) {
                throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: %s).', $this->name, $value, implode(', ', $this->availableOptionValues())));
            }

            if ($this->multiple) {
                $value = (array) $value;
            }

            if (is_array($value)) {
                $this->value = $value;
            } else {
                parent::setValue($value);
            }
        }
    }