Convert a optional value that when used is expected to be an array

@param mixed $value

@throws Exception\InvalidArgumentException

@return array
161184
public static function toArray($value)
    {
        if (is_array($value)) {
            return $value;
        }

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

        if (!$value instanceof Traversable) {
            throw new Exception\InvalidArgumentException(
                'An invalid value was provided, should either be an null, array or Traversable'
            );
        }

        return iterator_to_array($value);
    }
928179
public function transform($value)
    {
        if (null === $value) {
            $value = $this->fieldType->getEmptyValue();
        }

        return array_merge(
            $this->getDefaultProperties(),
            ['alternativeText' => $value->alternativeText]
        );
    }
1282103
protected function prepareValueAndOperator($value, $operator, $useDefault = false)
    {
        if ($useDefault) {
            return [$operator, '='];
        }
        if ($this->invalidOperatorAndValue($operator, $value)) {
            throw new InvalidArgumentException('Illegal operator and value combination.');
        }

        return [$value, $operator];
    }
892017
public function extract($value)
    {
        if ($value instanceof DateTime) {
            return $value->format($this->getFormat());
        }

        if ($this->nullable && $value === null) {
            return null;
        }

        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be an instance of DateTime, "%s" given.',
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
214494
public static function convertToDb($value)
    {
        if (!is_array($value)) {
            return [];
        }

        // see DateType::convertToDatabaseValue()
        $convertor = function ($value) {
            if ($value === null || $value instanceof \MongoDate) {
                return $value;
            }

            try {
                $datetime = DateType::getDateTime($value);
                return new \MongoDate($datetime->format('U'), $datetime->format('u'));
            } catch (\InvalidArgumentException $e) {
                return null;
            }
        };

        return array_values(array_filter(array_map($convertor, $value)));
    }
443579
public function extract($value)
    {
        if (!$value instanceof Money) {
            throw new \InvalidArgumentException(sprintf(
                '$value expected type SCL\Currency\Money, got "%s"',
                is_object($value) ? get_class($value) : gettype($value)
            ));
        }

        return $value->getValue();
    }
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;
    }
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;
    }
962115
public function lex(string $value): array
    {
        foreach (self::PATTERNS as $pattern => $tokenTypeConstant) {
            if (1 === preg_match($pattern, $value, $matches)) {
                if (null === $tokenTypeConstant) {
                    throw InvalidArgumentExceptionFactory::createForInvalidExpressionLanguageToken($value);
                }

                return [new Token($matches[0], new TokenType($tokenTypeConstant))];
            }
        }

        return $this->lexer->lex($value);
    }
1148968
public static function removeByValue($array, $value): array
    {
        if (! Assert::array($array)) {
            throw new InvalidArgumentException(
                '`Arr::removeByValue` first parameter must be `array` or implements interface `ArrayAccess`'
            );
        }

        foreach ($array as $i => $val) {
            if (trim($val) === trim($value)) {
                unset($array[$i]);
            }
        }

        return $array;
    }
386703
public static function fromValue($value) {
    if (is_array($value)) {
      $elements = [];
      foreach ($value as $k => $v) {
        $elements[] = ArrayPairNode::create(static::fromValue($k), static::fromValue($v));
      }
      return ArrayNode::create($elements);
    }
    elseif (is_string($value)) {
      return StringNode::create(var_export($value, TRUE));
    }
    elseif (is_integer($value)) {
      return new IntegerNode(T_LNUMBER, $value);
    }
    elseif (is_float($value)) {
      return new FloatNode(T_DNUMBER, $value);
    }
    elseif (is_bool($value)) {
      return BooleanNode::create($value);
    }
    elseif (is_null($value)) {
      return NullNode::create('NULL');
    }
    else {
      throw new \InvalidArgumentException();
    }
  }
254385
protected function sanitizeToArrayValue($value)
    {
        if ($value instanceof Message) {
            return (new self($value))->toArray();
        }

        if ($value instanceof RepeatedField) {
            $values = [];
            foreach ($value as $k => $v) {
                $values[] = $this->sanitizeToArrayValue($v);
            }

            return $values;
        }

        if ($value instanceof self) {
            return $value->toArray();
        }

        return $value;
    }
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;
    }
1105133
public function orx($value)
    {
        if(!is_array($value)) {
            // get arguments 
            $value = func_get_args();
        }
        // Convert all values to 
        $conds = array_map(function($v) {
                if(is_string($v) && $this->getQueryParser()) {
                    return $this->getQueryParser()->parseExpression($v);
                } else if(!$v instanceof Expr\ConditionalExpression) {
                    throw new \InvalidArgumentException('');
                } 
                return $v;
            }, $value);

        //return new Expr\OrX($conds);
        return new Expr\LogicalExpression($conds, Expr\LogicalExpression::TYPE_OR);
    }
262555
private function arrayValue($value) : Expr\Array_
    {
        $items = [];
        $lastKey = -1;
        foreach ($value as $itemKey => $itemValue) {
            // for consecutive, numeric keys don't generate keys
            if (null !== $lastKey && ++$lastKey === $itemKey) {
                $items[] = new Expr\ArrayItem(
                    $this->__invoke($itemValue)
                );
            } else {
                $lastKey = null;
                $items[] = new Expr\ArrayItem(
                    $this->__invoke($itemValue),
                    $this->__invoke($itemKey)
                );
            }
        }

        return new Expr\Array_($items);
    }
1338788
public function setValue($value) {
		if(!in_array($value, self::VALID_VALUES)) {
			throw new InvalidArgumentException('Value is not valid.');
		}

		$this->value = $value;

		return $this;
	}
1222985
public function toArray($value)
    {
        if (empty($value)) {
            return null;
        }

        $output = [];
        foreach ($value as $val) {
            $output[] = $this->field->toArray($val);
        }

        return $output;
    }