Parses an externally provided value (query variable) to use as an input

@param mixed $value

@return mixed

@throws Error
320271
public function parseValue($value)
    {
        $date = \DateTime::createFromFormat(DATE_ATOM, $value);
        if (!$date) {
            throw new Error(sprintf("Cannot represent following value as date: %s", Utils::printSafeJson($value)));
        }

        return $date;
    }
1233674
function fromObject($value)
    {
        $this->clear();
        $this->orignalValue = $this->returnValue  = (string) (method_exists($value, '__toString') ? $value : null);
        return $this->parse();
    }
1170469
public static function parse($value)
    {
        if ($value instanceof Complex) return $value;
        if ($value instanceof Rational) return new Complex($value.p/$value.q, 0);

        if (is_int($value)) return new Complex($value, 0);
        if (is_float($value)) return new Complex($value, 0);

        if (!is_string($value)) throw new SyntaxErrorException();

        // Match complex numbers with an explicit i
        $matches = array();

        $valid = \preg_match(
            '#^([-,\+])?([0-9/,\.]*?)([-,\+]?)([0-9/,\.]*?)i$#',
            \trim($value),
            $matches
        );

        if ($valid == 1) {
            $real = $matches[2];
            if ($real === '') {
                $matches[3] = $matches[1];
                $real = '0';
            }
            $imaginary = $matches[4];
            if ($imaginary === '') $imaginary = '1';

            if ($matches[1] && $matches[1] == '-') {
                $real = '-' . $real;
            }
            if ($matches[3] && $matches[3] == '-') {
                $imaginary = '-' . $imaginary;
            }

            try {
                $a = Rational::parse($real);
                $realPart = $a->p/$a->q;
            } catch(SyntaxErrorException $e)
            {
                $realPart = static::parseReal($real);
            }

            try {
                $b = Rational::parse($imaginary);
                $imaginaryPart = $b->p/$b->q;
            } catch(SyntaxErrorException $e)
            {
                $imaginaryPart = static::parseReal($imaginary);
            }

        }
        else {
            // That failed, try matching a rational number
            try {

                $a = Rational::parse($value);
                $realPart = $a->p/$a->q;
                $imaginaryPart = 0;

            } catch(SyntaxErrorException $e) {
                // Final attempt, try matching a real number
                $realPart = static::parseReal($value);
                $imaginaryPart = 0;
            }
        }

        $z = new Complex($realPart, $imaginaryPart);

        return $z;
    }
862792
public static function parse($value)
    {
        $values = explode(':', $value, 2);
        if (count($values) !== 2) {
            return;
        }

        return new static($values[0], trim($values[1]));
    }
756936
public function parse($value)
    {
        if (is_array($value)) {
            return $this->parseSet($value);
        } else {
            return $this->parseValue($value);
        }
    }
540973
protected function parseScope($value)
    {
        switch ($value) {
            case 'singleton':
                return Configuration::SCOPE_SINGLETON;
            case 'prototype':
                return Configuration::SCOPE_PROTOTYPE;
            case 'session':
                return Configuration::SCOPE_SESSION;
            default:
                throw new InvalidObjectConfigurationException('Invalid scope "' . $value . '"', 1167574991);
        }
    }
733751
private static function _parseDateTimeString($value)
    {
        $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d \d\d:\d\d:\d\d$/', $value);
        if ($result !== 1)
            return null;
        $timestamp = strtotime($value);
        if ($timestamp === false)
            return null;

        return $timestamp;
    }
321902
public function filter($value)
    {
        $isInternalAllowed = $this->builder->isVisibilityAllowed(Settings::VISIBILITY_INTERNAL);
        if ($isInternalAllowed) {
            $value->setDescription(preg_replace('/\{@internal\s(.+?)\}\}/', '$1', $value->getDescription()));

            return $value;
        }

        // remove inline @internal tags
        $value->setDescription(preg_replace('/\{@internal\s(.+?)\}\}/', '', $value->getDescription()));

        // if internal elements are not allowed; filter this element
        if ($value->getTags()->get('internal')) {
            return null;
        }

        return $value;
    }
192725
protected function parseValue($value){
		switch( true ){
			case ($value === 'false' || $value === 'true'):
				return  ( $value === 'true' ) ? true : false ;
			
			case ctype_digit($value):
				return (int) $value; 

			case is_float($value):
				return (float) $value;

			default:
				return $value;
		}
	}
1344641
private function parse($value): array
    {
        if (is_array($value)) {
            if ($value[0] !== $value[1]) {
                return $this->error('PASSWORDS_NOT_EQUAL');
            }

            $value = $value[0];
        }

        if (empty($value) === 0) {
            return [null, []];
        }

        return [Secret::create($value), []];
    }
613105
public static function parseValue($value)
    {
        if ($value instanceof DateTimeInterface) {
            $value = $value->format('Y-m-d H:i:s');
        } elseif ($value instanceof DateTimeProperty) {
            $value = $value->storageVal($value->val());
        } elseif (is_string($value)) {
            $str = strtolower($value);
            if ($str === 'true') {
                $value = true;
            } elseif ($str === 'false') {
                $value = false;
            }
        }

        return $value;
    }
550709
public static function parseAddress($value) {
        if (!is_string($value)) throw new IllegalTypeException('Illegal type of parameter $value: '.gettype($value));

        $value = trim($value);

        if (strEndsWith($value, '>')) {
            // closing angle bracket found, check for a matching opening bracket
            $name    = trim(strLeftTo($value, '<', -1));
            $address = strRightFrom($value, '<', -1);           // omits the opening bracket
            $address = trim(strLeft($address, -1));             // omit the closing bracket
        }
        else {
            // no closing angle bracket found, it must be a simple address
            $name  = '';
            $address = $value;
        }

        if (strlen($address) && filter_var($address, FILTER_VALIDATE_EMAIL)) {
            return [
                'name'    => $name,
                'address' => $address
            ];
        }
        return null;
    }
821699
private function getValue($value)
    {
        if ($value === null) {
            return null;
        }

        if ($value instanceof String_ || $value instanceof LNumber || $value instanceof DNumber) {
            return $value->value;
        } elseif ($value instanceof ConstFetch) {
            $value = (string)$value->name;
            if ($value === 'null') {
                return null;
            } elseif ($value === 'true') {
                return true;
            } elseif ($value === 'false') {
                return false;
            }

            return $value;
        } elseif ($value instanceof Array_) {
            return $this->getArray($value);
        }

        return null;
    }
435608
public function parse($value)
  {
    $this->currentLineNb = -1;
    $this->currentLine = '';
    $this->lines = explode("\n", $this->cleanup($value));

    if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
    {
      $mbEncoding = mb_internal_encoding();
      mb_internal_encoding('UTF-8');
    }

    $data = array();
    while ($this->moveToNextLine())
    {
      if ($this->isCurrentLineEmpty())
      {
        continue;
      }

      // tab?
      if (preg_match('#^\t+#', $this->currentLine))
      {
        throw new InvalidArgumentException(sprintf('A YAML file cannot contain tabs as indentation at line %d (%s).', $this->getRealCurrentLineNb() + 1, $this->currentLine));
      }

      $isRef = $isInPlace = $isProcessed = false;
      if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values))
      {
        if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches))
        {
          $isRef = $matches['ref'];
          $values['value'] = $matches['value'];
        }

        // array
        if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))
        {
          $c = $this->getRealCurrentLineNb() + 1;
          $parser = new sfYamlParser($c);
          $parser->refs =& $this->refs;
          $data[] = $parser->parse($this->getNextEmbedBlock());
        }
        else
        {
          if (isset($values['leadspaces'])
            && ' ' == $values['leadspaces']
            && preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches))
          {
            // this is a compact notation element, add to next block and parse
            $c = $this->getRealCurrentLineNb();
            $parser = new sfYamlParser($c);
            $parser->refs =& $this->refs;

            $block = $values['value'];
            if (!$this->isNextLineIndented())
            {
              $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
            }

            $data[] = $parser->parse($block);
          }
          else
          {
            $data[] = $this->parseValue($values['value']);
          }
        }
      }
      else if (preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values))
      {
        $key = sfYamlInline::parseScalar($values['key']);

        if ('<<' === $key)
        {
          if (isset($values['value']) && '*' === substr($values['value'], 0, 1))
          {
            $isInPlace = substr($values['value'], 1);
            if (!array_key_exists($isInPlace, $this->refs))
            {
              throw new InvalidArgumentException(sprintf('Reference "%s" does not exist at line %s (%s).', $isInPlace, $this->getRealCurrentLineNb() + 1, $this->currentLine));
            }
          }
          else
          {
            if (isset($values['value']) && $values['value'] !== '')
            {
              $value = $values['value'];
            }
            else
            {
              $value = $this->getNextEmbedBlock();
            }
            $c = $this->getRealCurrentLineNb() + 1;
            $parser = new sfYamlParser($c);
            $parser->refs =& $this->refs;
            $parsed = $parser->parse($value);

            $merged = array();
            if (!is_array($parsed))
            {
              throw new InvalidArgumentException(sprintf("YAML merge keys used with a scalar value instead of an array at line %s (%s)", $this->getRealCurrentLineNb() + 1, $this->currentLine));
            }
            else if (isset($parsed[0]))
            {
              // Numeric array, merge individual elements
              foreach (array_reverse($parsed) as $parsedItem)
              {
                if (!is_array($parsedItem))
                {
                  throw new InvalidArgumentException(sprintf("Merge items must be arrays at line %s (%s).", $this->getRealCurrentLineNb() + 1, $parsedItem));
                }
                $merged = array_merge($parsedItem, $merged);
              }
            }
            else
            {
              // Associative array, merge
              $merged = array_merge($merge, $parsed);
            }

            $isProcessed = $merged;
          }
        }
        else if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches))
        {
          $isRef = $matches['ref'];
          $values['value'] = $matches['value'];
        }

        if ($isProcessed)
        {
          // Merge keys
          $data = $isProcessed;
        }
        // hash
        else if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))
        {
          // if next line is less indented or equal, then it means that the current value is null
          if ($this->isNextLineIndented())
          {
            $data[$key] = null;
          }
          else
          {
            $c = $this->getRealCurrentLineNb() + 1;
            $parser = new sfYamlParser($c);
            $parser->refs =& $this->refs;
            $data[$key] = $parser->parse($this->getNextEmbedBlock());
          }
        }
        else
        {
          if ($isInPlace)
          {
            $data = $this->refs[$isInPlace];
          }
          else
          {
            $data[$key] = $this->parseValue($values['value']);
          }
        }
      }
      else
      {
        // 1-liner followed by newline
        if (2 == count($this->lines) && empty($this->lines[1]))
        {
          $value = sfYamlInline::load($this->lines[0]);
          if (is_array($value))
          {
            $first = reset($value);
            if ('*' === substr($first, 0, 1))
            {
              $data = array();
              foreach ($value as $alias)
              {
                $data[] = $this->refs[substr($alias, 1)];
              }
              $value = $data;
            }
          }

          if (isset($mbEncoding))
          {
            mb_internal_encoding($mbEncoding);
          }

          return $value;
        }

        switch (preg_last_error())
        {
          case PREG_INTERNAL_ERROR:
            $error = 'Internal PCRE error on line';
            break;
          case PREG_BACKTRACK_LIMIT_ERROR:
            $error = 'pcre.backtrack_limit reached on line';
            break;
          case PREG_RECURSION_LIMIT_ERROR:
            $error = 'pcre.recursion_limit reached on line';
            break;
          case PREG_BAD_UTF8_ERROR:
            $error = 'Malformed UTF-8 data on line';
            break;
          case PREG_BAD_UTF8_OFFSET_ERROR:
            $error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point on line';
            break;
          default:
            $error = 'Unable to parse line';
        }

        throw new InvalidArgumentException(sprintf('%s %d (%s).', $error, $this->getRealCurrentLineNb() + 1, $this->currentLine));
      }

      if ($isRef)
      {
        $this->refs[$isRef] = end($data);
      }
    }

    if (isset($mbEncoding))
    {
      mb_internal_encoding($mbEncoding);
    }

    return empty($data) ? null : $data;
  }
583689
public function convert($value)
    {
        switch (gettype($value)) {
            case 'string':
                $result = '\'' . pg_escape_string($value) . '\'';
                break;
            case 'array':
                $data = array_map(function ($item) {
                    return $this->convert($item);
                }, $value);

                $result = '[' . implode(',', $data) . ']';
                break;
            case 'double':
            case 'integer':
                $result = $value < -2147483648 || 2147483647 < $value ? $value . '::bigint' : $value;
                break;
            case 'NULL':
                $result = 'null';
                break;
            case 'boolean':
                $result = $value ? 'true' : 'false';
                break;
            default:
                throw new DbException('Unsupported type ' . gettype($value), DbException::WRONG_TYPE);
        }

        return $result;
    }
1222027
public static function decode($value)
    {
        if (empty($value)) {
            return null;
        }

        if (!is_string($value)) {
            throw new \InvalidArgumentException(sprintf(
                "Value type '%s' is not a PHP string so it cannot be unserialized.",
                gettype($value)
            ));
        }

        $data = unserialize($value);

        return $data;
    }
1233346
private function convertValue($value)
    {
        if (empty($value)) {
            return null;
        }

        if (\is_array($value)) {
            return $value;
        }

        switch ($this->fieldType) {
            case 'radio':
                return $value;
            case 'checkbox':
                $delimiter = (false !== \stripos($value, "\t")) ? "\t" : ',';

                return StringUtil::trimsplit($delimiter, $value);
            default:
        }
        throw new \RuntimeException('Unknown field type encountered: ' . $this->fieldType);
    }