Format values for the API

@param mixed $value
@param bool $exclude [optional] If true, value will be excluded from datastore indexes.
@param int $meaning [optional] The Meaning value. Maintained only for backwards compatibility.
@return array
1996
public function valueObject($value, $exclude = false, $meaning = null)
    {
        switch (gettype($value)) {
            case 'boolean':
                $propertyValue = [
                    'booleanValue' => $value
                ];

                break;

            case 'integer':
                $propertyValue = [
                    'integerValue' => $value
                ];

                break;

            case 'double':
                $propertyValue = [
                    'doubleValue' => $value
                ];

                break;

            case 'string':
                $propertyValue = [
                    'stringValue' => $value
                ];

                break;

            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    $propertyValue = $this->convertArrayToEntityValue($value);
                } else {
                    $propertyValue = $this->convertArrayToArrayValue($value);
                }

                break;

            case 'object':
                $propertyValue = $this->objectProperty($value);
                break;

            case 'resource':
                $content = stream_get_contents($value);

                $propertyValue = [
                    'blobValue' => ($this->encode)
                        ? base64_encode($content)
                        : $content
                ];
                break;

            case 'NULL':
                $propertyValue = [
                    'nullValue' => null
                ];
                break;

            //@codeCoverageIgnoreStart
            case 'unknown type':
                throw new \InvalidArgumentException(sprintf(
                    'Unknown type for `%s',
                    $content
                ));
                break;

            default:
                throw new \InvalidArgumentException(sprintf(
                    'Invalid type for `%s',
                    $content
                ));
                break;
            //@codeCoverageIgnoreEnd
        }

        if ($exclude) {
            $propertyValue['excludeFromIndexes'] = true;
        }

        if ($meaning) {
            $propertyValue['meaning'] = $meaning;
        }

        return $propertyValue;
    }
216017
protected function normalizeValue($value)
    {
        if (false === $value) {
            return $value;
        }

        $value = $this->remapXml($value);

        $normalized = array();
        foreach ($value as $name => $val) {
            if (isset($this->children[$name])) {
                $normalized[$name] = $this->children[$name]->normalize($val);
                unset($value[$name]);
            } elseif (!$this->removeExtraKeys) {
                $normalized[$name] = $val;
            }
        }

        // if extra fields are present, throw exception
        if (count($value) && !$this->ignoreExtraKeys) {
            $msg = sprintf('Unrecognized option%s "%s" under "%s"', 1 === count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath());
            $ex = new InvalidConfigurationException($msg);
            $ex->setPath($this->getPath());

            throw $ex;
        }

        return $normalized;
    }
1335470
public static function readableFor($value, string $separator = '; '): string
    {
        if (!static::accepts($value)) {
            throw new InvalidValueException($value, static::class);
        }
        if ($value === self::NONE) {
            return static::readableForNone();
        }

        $humanRepresentations = static::readables();

        if (isset($humanRepresentations[$value])) {
            return $humanRepresentations[$value];
        }

        $parts = [];

        foreach ($humanRepresentations as $flag => $readableValue) {
            if ($flag === ($flag & $value)) {
                $parts[] = $readableValue;
            }
        }

        return implode($separator, $parts);
    }
204211
public function _prepValues($value)
    {
        if (is_array($value)) {
            if (isset($value["func"])) {
                return $value["func"];
            }
            foreach ($value as &$param) {
                $this->params[] = $param;
                $param = "?";
            }
            unset($param);
            return $value;
        }
        if (in_array(is_string($value) ? strtolower($value) : $value, [null, "null"]) === false) {
            $this->params[] = $value;
            $value = "?";
        }
        return $value;
    }
128559
protected function preparePublicObject($value, array $exclude)
  {
    $reflection = new \ReflectionObject($value);
    $properties = $reflection->getProperties();

    $object = new \stdClass();
    $this->level++;
    foreach ($properties as $property)
    {
      $key = $property->getName();
      if ($this->exclude($key, $exclude) === false)
      {
        $property->setAccessible(true);
        $object->$key = $property->getValue($value);

        if (is_object($object->$key))
        {
          if ($this->level <= $this->max_nesting_level)
          {
            $object->$key = $this->objectToPublicObject($object->$key, $this->excludeNext($key, $exclude));
          }
          else
          {
            $object->$key = null;
          }
        }
        elseif (is_array($object->$key))
        {
          $object->$key = $this->prepareArray($object->$key, $this->excludeNext($key, $exclude));
        }
      }
    }
    $this->level--;

    return $object;
  }
1267263
protected function compileIncludes($value)
	{
		$pattern = $this->createOpenMatcher('include');

		$replace = '$1<?php echo $__env->make$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';

		return preg_replace($pattern, $replace, $value);
	}
281618
public static function isAfter($value, $limit, $inclusive = false)
    {
        $value = self::convertToDateTime($value);
        $limit = self::convertToDateTime($limit);

        if (false === $inclusive) {
            return \strtotime($value->format('Y-m-d H:i:s')) > \strtotime($limit->format('Y-m-d H:i:s'));
        }

        return \strtotime($value->format('Y-m-d H:i:s')) >= \strtotime($limit->format('Y-m-d H:i:s'));
    }
1328429
public function prepareValue($value)
    {
        return $value === null ? null : Carbon::createFromFormat($this->format, $value)->toDateString();
    }
428167
protected function prepareValue($value)
    {
        $params = $this->getOperatorParams();
        $method = $params['method'];
        switch ($method) {
            case 'where':
            case 'whereNull':
            case 'whereNotNull':
                break;
            case 'whereBetween':
            case 'whereNotBetween':
                if (! is_array($value)) {
                    $value = explode(',', $value, 2);
                }
                break;
            case 'whereIn':
            case 'whereNotIn':
                if (! is_array($value)) {
                    $value = explode(',', $value);
                }
                break;
        }

        return $value;
    }
902144
protected function parseValue($value)
    {
        // Validate
        if (!static::hasValidLength($value)) {
            throw new Exception("No valid EAN, UPC or ISBN13 provided");
        }

        // Sanitize
        $value  = (int) $value;
        $length = strlen($value);

        // Set value
        $this->value = $value;

        // Set type
        if ($length < 13) {
            $this->type = static::UPC;
        } elseif (preg_match('/^97(?:8|9)/', $value)) {
            $this->type = static::ISBN13;
        } else {
            $this->type = static::EAN;
        }
    }
1039906
public function prepareValues($values)
    {
        if (empty($values)) {
            return [];
        }

        if (!is_array($values)) {
            $values = (array)$values;
        }

        $values = array_filter($values, 'is_scalar');
        $values = array_map('self::quoteValue', $values);

        return $values;
    }
4258
public function convertQueryCondition($value)
    {
        // First fetch the type
        if (null === $value) {
            return 0;
        }

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

        $hasOperator = false;

        // FIXME Sorry for this
        if (!Misc::isIndexed($value)) {
            // We have an operator.
            $operator = array_keys($value)[0];
            $values = $value[$operator][0];
            $hasOperator = true;
        } else {
            $values = $value;
        }

        foreach ($values as $key => $type) {
            if (null === $type) {
                $values[$key] = 0;
            } else if ($typeId = $this->getTypeId($type, false)) {
                $values[$key] = $typeId;
            } else {
                unset($values[$key]);
            }
        }

        if (empty($values)) {
            // It should not have been empty, this is an impossible
            // condition
            $values = [-1];
        }

        if ($hasOperator) {
            return [$operator => $values];
        } else {
            return $values;
        }
    }
33192
public function get($value) {
        //TODO throw exception instead?!
        if (\is_int($value)) {
            $info = $this->getIndexAndMask($value);
            $i = $info["i"];
            $k = $info["k"];

            $flag = 1;
            $flag = $flag << $k;

            if (isset($this->array[$i])) return (($this->array[$i] & $flag) !== 0);
            return false;
        }
        return false;
    }
858732
public function format($value): array
    {
        $coupons = [];

        foreach ($value as $coupon) {
            $coupons[] = $coupon->identifier();
        }

        return $coupons;
    }
1030486
public function prepare($value)
    {
        if (is_string($value) && preg_match_all('/\%([^\%]+)\%/', $value, $match)) {
            foreach ($match[1] as $match) {
                try {
                    $value = str_replace("%{$match}%", $this->get($match), $value);
                } catch (\Exception $e) {
                    throw new \Exception("Configuration Missing for %" . $match . "%");
                }
            }
        } elseif (is_array($value)) {
            $result = array();

            foreach ($value as $key => $item) {
                $result[$key] = $this->prepare($item);
            }

            $value = $result;
        }

        return $value;
    }
1123483
private function prepareFormat($value, $format)
    {
        if (!is_array($format)) {
            return [$format, [$value]];
        }
        if (!isset($format[0])) {
            throw new InvalidParamException('The $format array must contain at least one element.');
        }
        $f = $format[0];
        $format[0] = $value;
        $params = $format;
        $format = $f;
        return [$format, $params];
    }
361213
protected function format_value( $value, $raw ) {
		if ( $raw && '' === trim( $value ) ) {
			throw new Exception( 'Raw value for empty string not supported.' );
		}

		return ( $raw ) ? $value : var_export( $value, true );
	}