@param ExpressionBuilderInterface $expressionBuilder
@param string $type
@param string $field
@param mixed $value

@return mixed

@throws \InvalidArgumentException
166112
private function getExpression(
        ExpressionBuilderInterface $expressionBuilder,
        string $type,
        string $field,
        $value
    ) {
        switch ($type) {
            case self::TYPE_EQUAL:
                return $expressionBuilder->equals($field, $value);
            case self::TYPE_NOT_EQUAL:
                return $expressionBuilder->notEquals($field, $value);
            case self::TYPE_EMPTY:
                return $expressionBuilder->isNull($field);
            case self::TYPE_NOT_EMPTY:
                return $expressionBuilder->isNotNull($field);
            case self::TYPE_IN:
                return $expressionBuilder->in($field, $value);
            case self::TYPE_NOT_IN:
                return $expressionBuilder->notIn($field, $value);
            case self::TYPE_LESS_THAN:
                return $expressionBuilder->lessThan($field, $value);
            case self::TYPE_LESS_THAN_OR_EQUAL:
                return $expressionBuilder->lessThanOrEqual($field, $value);
            case self::TYPE_GREATER_THAN:
                return $expressionBuilder->greaterThan($field, $value);
            case self::TYPE_GREATER_THAN_OR_EQUAL:
                return $expressionBuilder->greaterThanOrEqual($field, $value);
            case self::TYPE_BETWEEN:
                return $expressionBuilder->andX(
                    $expressionBuilder->greaterThanOrEqual($field, $value[0]),
                    $expressionBuilder->lessThanOrEqual($field, $value[1])
                );
            default:
                throw new \InvalidArgumentException(sprintf('Could not get an expression for type "%s"!', $type));
        }
    }
1363513
public function onRelationalExpression($expressionType, $left, $right)
    {
        $type = $this->unpackExpressionType($expressionType);
        switch ($type) {
            case ExpressionType::GREATERTHAN:
                return $this->prepareBinaryExpression(self::GREATER_THAN, $left, $right);
            case ExpressionType::GREATERTHAN_OR_EQUAL:
                return $this->prepareBinaryExpression(self::GREATER_THAN_OR_EQUAL, $left, $right);
            case ExpressionType::LESSTHAN:
                return $this->prepareBinaryExpression(self::LESS_THAN, $left, $right);
            case ExpressionType::LESSTHAN_OR_EQUAL:
                return $this->prepareBinaryExpression(self::LESS_THAN_OR_EQUAL, $left, $right);
            case ExpressionType::EQUAL:
                return $this->prepareBinaryExpression(self::EQUAL, $left, $right);
            case ExpressionType::NOTEQUAL:
                return $this->prepareBinaryExpression(self::NOT_EQUAL, $left, $right);
            default:
                throw new \InvalidArgumentException('onRelationalExpression');
        }
    }
144131
public function condition($field, $value = NULL, $expressionOperator = NULL)
    {

        if (!isset($expressionOperator)) {
            if (is_array($value)) {
                $expressionOperator = 'IN';
            }
            else {
                $expressionOperator = '=';
            }
        }
        $this->conditions[] = array(
            'field' => $field,
            'value' => $value,
            'operator' => $expressionOperator,
        );
        return $this;
    }
836144
public function resolveBind($field, $value, array $schema = []) {
        $type = null;

        // Exit early for functions since we don't have a valid field
        if ($field instanceof Func) {
            return [$value, $this->resolveType($value)];
        }

        // Use the raw value for binding
        if ($value instanceof RawExpr) {
            $value = $value->getValue();
        }

        // Type cast
        if ($value === null) {
            $type = PDO::PARAM_NULL;

        } else if (isset($schema[$field]['type'])) {
            $dataType = $this->getType($schema[$field]['type']);
            $value = $dataType->to($value);
            $type = $dataType->getBindingType();
        }

        // Fallback and resolve
        if (!$type) {
            $type = $this->resolveType($value);
        }

        return [$value, $type];
    }
381987
public function bindValue($parameter, $value, $type = null)
    {
        return $this->bindParam($parameter, $value, $type);
    }
685616
protected function addMatch(Builder $aggregationBuilder, string $field, string $matchField, string $operator, string $value)
    {
        switch ($operator) {
            case self::PARAMETER_BETWEEN:
                $rangeValue = explode('..', $value);

                $rangeValue = $this->normalizeBetweenValues($rangeValue);
                if (null === $rangeValue) {
                    return;
                }

                $aggregationBuilder->match()->field($matchField)->gte($rangeValue[0])->lte($rangeValue[1]);

                break;
            case self::PARAMETER_GREATER_THAN:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $aggregationBuilder->match()->field($matchField)->gt($value);

                break;
            case self::PARAMETER_GREATER_THAN_OR_EQUAL:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $aggregationBuilder->match()->field($matchField)->gte($value);

                break;
            case self::PARAMETER_LESS_THAN:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $aggregationBuilder->match()->field($matchField)->lt($value);

                break;
            case self::PARAMETER_LESS_THAN_OR_EQUAL:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $aggregationBuilder->match()->field($matchField)->lte($value);

                break;
        }
    }
35917
public static function compile($expression, $type = self::TYPE_CSS)
    {
        if (!is_string($expression)) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 1 to be string, %s given', __METHOD__, gettype($expression)));
        }

        if (!is_string($type)) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 2 to be string, %s given', __METHOD__, gettype($type)));
        }

        if (strcasecmp($type, self::TYPE_XPATH) !== 0 && strcasecmp($type, self::TYPE_CSS) !== 0) {
            throw new RuntimeException(sprintf('Unknown expression type "%s"', $type));
        }

        $expression = trim($expression);

        if ($expression === '') {
            throw new InvalidSelectorException('The expression must not be empty');
        }

        if (strcasecmp($type, self::TYPE_XPATH) === 0) {
            return $expression;
        }

        if (!array_key_exists($expression, static::$compiled)) {
            static::$compiled[$expression] = static::cssToXpath($expression);
        }

        return static::$compiled[$expression];
    }
452346
public function set($field, $value, $type = 0)
    {
        $this->_write_fields[] = $field;
        $this->_write_values[] = $value;
        $this->_write_field_types[] = $type;

        return $this;
    }
117715
public function handleBuilder($builder, $value)
    {
        foreach ($value as $orderByClause) {
            $builder->orderBy(
                $orderByClause['field'],
                $orderByClause['order']
            );
        }

        return $builder;
    }
332102
protected function buildFilter($field, $type, $filter, $value)
    {
        if ((is_array($value) && count($value) != 2)
                || (!is_array($value) && ($value !== false && strlen($value) == 0))) {
            return false;
        }
        if (strlen($field) == 0)
            throw new \Exception("Empty 'field'");
        if (strlen($type) == 0)
            throw new \Exception("Empty 'type'");

        if ($type == Table::TYPE_DATETIME) {
            if ($filter == Table::FILTER_BETWEEN
                    && is_array($value) && count($value) == 2) {
                $value = [
                    $value[0] ? new MongoDate($value[0]) : null,
                    $value[1] ? new MongoDate($value[1]) : null,
                ];
            } else if ($filter != Table::FILTER_BETWEEN
                    && is_scalar($value)) {
                $value = new MongoDate($value);
            } else {
                return false;
            }
        } else {
            if ($filter == Table::FILTER_BETWEEN) {
                if (!is_array($value) || count($value) != 2)
                    return false;
            } else if (!is_scalar($value)) {
                return false;
            }
        }

        switch ($filter) {
            case Table::FILTER_LIKE:
                if (!(isset($this->andOps[$field])))
                    $this->andOps[$field] = [];
                $this->andOps[$field][] = [
                    'operator'  => 'equals',
                    'value'     => new MongoRegex('/.*' . preg_quote($value) . '.*/i'),
                ];
                break;
            case Table::FILTER_EQUAL:
                if (!(isset($this->andOps[$field])))
                    $this->andOps[$field] = [];
                $this->andOps[$field][] = [
                    'operator'  => 'equals',
                    'value'     => $value,
                ];
                break;
            case Table::FILTER_BETWEEN:
                if (!(isset($this->andOps[$field])))
                    $this->andOps[$field] = [];
                $this->andOps[$field][] = [
                    'operator'  => 'range',
                    'value1'    => $value[0],
                    'value2'    => $value[1],
                ];
                break;
            case Table::FILTER_NULL:
                if (!(isset($this->andOps[$field])))
                    $this->andOps[$field] = [];
                $this->andOps[$field][] = [
                    'operator'  => 'exists',
                    'value'     => false,
                ];
                break;
            default:
                throw new \Exception("Unknown filter: $filter");
        }

        return true;
    }
963924
public function defineFormBuilder(FormBuilderInterface $formBuilder)
    {
        /** @var AbstractAdmin $admin */
        $admin = $this;

        $mapper = new \Compo\Sonata\AdminBundle\Form\FormMapper($admin->getFormContractor(), $formBuilder, $admin);

        $this->configureFormFields($mapper);

        foreach ($admin->getExtensions() as $extension) {
            $extension->configureFormFields($mapper);
        }

        $this->attachInlineValidator();
    }
1024245
private function parseValue($value, $types, \ReflectionProperty $property, $object)
    {
        foreach ($types as $type) {
            foreach ($this->context->getParsers() as $parser) {
                if ($parser instanceof ValueParserInterface) {
                    if (is_array($value) && strpos($type, '[]') !== false) {
                        foreach ($value as $key => &$arrayValue) {
                            $arrayValue = $parser->toArrayValue($arrayValue, str_replace('[]', null, $type), $property, $arrayValue);
                        }
                    } else {
                        $value = $parser->toArrayValue($value, $type, $property, $object);
                    }
                } else {
                    throw new \InvalidArgumentException(sprintf('%s is not a valid parser.', get_class($parser)));
                }
            }
        }

        return $value;
    }
281966
private function structParam($value, StructType $type)
    {
        if (!($value instanceof StructValue) && !is_array($value) && $value !== null) {
            throw new \InvalidArgumentException(
                'Struct value must be an array an instance of `Google\Cloud\Spanner\StructValue` or null.'
            );
        }

        $typeFields = $type->fields();

        // iterate through types and values separately to accurately align
        // unnamed and fields with duplicate names.
        // We also record the original position in order to return values in
        // the order given.
        $values = [];
        if (is_array($value)) {
            $idx = 0;
            foreach ($value as $name => $val) {
                if (!isset($values[$name])) {
                    $values[$name] = [];
                }

                // Nest values inside an array keyed by field name.
                // This allows for duplicate field names, and aligning
                // definitions by position.
                $values[$name][] = [
                    'index' => $idx,
                    'value' => $val
                ];

                $idx++;
            }
        } elseif ($value instanceof StructValue) {
            foreach ($value->values() as $idx => $val) {
                $name = $val['name'];
                $valValue = $val['value'];

                if (!isset($values[$name])) {
                    $values[$name] = [];
                }

                $values[$name][] = [
                    'index' => $idx,
                    'value' => $valValue
                ];
            }
        }

        // Iterate through given type fields and align them with corresponding values.
        $res = [];
        $fields = [];
        $names = [];
        foreach ($typeFields as $typeIndex => $paramType) {
            $fieldName = $paramType['name'];

            // Count the number of times the field name has been encountered thus far.
            // This lets us pick the correct index for duplicate fields.
            if (isset($names[$fieldName])) {
                $names[$fieldName]++;
            } else {
                $names[$fieldName] = 0;
            }

            // Get the value which corresponds to the current type.
            $index = $names[$fieldName];
            $paramValue = isset($values[$fieldName][$index])
                ? $values[$fieldName][$index]
                : null;

            // If the value didn't exist in the values structure, set it to null.
            // The $typeIndex will give us a hook to order fields properly.
            // Otherwise, remove the current field value from the list of values.
            if ($paramValue === null) {
                $paramValue = ['value' => null, 'index' => $typeIndex];
            } else {
                unset($values[$fieldName][$index]);
            }

            $param = $this->paramType($paramValue['value'], $paramType['type'], $paramType['child']);

            $fields[$paramValue['index']] = array_filter([
                'name' => $fieldName,
                'type' => $param[1]
            ]);

            $res[$paramValue['index']] = $param[0];
        }

        // Iterate over any remaining fields. If anything is left here, it means
        // no type was defined and its type must be inferred.
        foreach ($values as $name => $list) {
            foreach ($list as $value) {
                $index = $value['index'];
                $val = $value['value'];

                $type = null;
                $def = null;
                if (is_array($val) && !$this->isAssoc($val)) {
                    $type = Database::TYPE_ARRAY;
                    $def = new ArrayType(null);
                }

                $param = $this->paramType($val, $type, $def);

                $fields[$index] = array_filter([
                    'name' => $name,
                    'type' => $param[1]
                ]);

                $res[$index] = $param[0];
            }
        }

        // Sort values and fields by key to reset back to the order given by the user.
        ksort($res);
        ksort($fields);

        $type = [
            'code' => self::TYPE_STRUCT,
            'structType' => [
                'fields' => $fields
            ]
        ];

        // If the input is null, send null (but with the full type structure)
        $res = $value === null ? null : $res;

        return [
            $res,
            $type
        ];
    }
850369
public function elseValue($value = null, $type = null)
    {
        if (is_array($value)) {
            end($value);
            $value = key($value);
        }

        if ($value !== null && !$value instanceof ExpressionInterface) {
            $value = $this->_castToExpression($value, $type);
        }

        if (!$value instanceof ExpressionInterface) {
            $value = ['value' => $value, 'type' => $type];
        }

        $this->_elseValue = $value;
    }
736139
private function parseValue($value, $types, \ReflectionProperty $property, $object)
    {
        foreach ($types as $type) {
            foreach ($this->context->getParsers() as $parser) {
                if ($parser instanceof ValueParserInterface) {
                    if (is_array($value) && strpos($type, '[]') !== false) {

                        //support for nesting children
                        //https://github.com/rafrsr/lib-array2object/issues/1
                        if (count($value) === 1 && is_array(current($value))) {
                            if (array_key_exists(0, current($value))) {
                                $value = current($value);
                            }
                        }

                        $tmpArray = [];
                        foreach ($value as $key => $arrayValue) {
                            $parsedValue = $parser->toObjectValue($arrayValue, str_replace('[]', null, $type), $property, $object);
                            //the annotation [] is used alone to ignore array keys
                            if (in_array('[]', $types, true)) {
                                $tmpArray[] = $parsedValue;
                            } else {
                                $tmpArray[$key] = $parsedValue;
                            }
                        }
                        $value = $tmpArray;
                    } else {
                        $value = $parser->toObjectValue($value, str_replace('[]', null, $type), $property, $object);
                    }
                } else {
                    throw new \InvalidArgumentException(sprintf('%s is not a valid parser.', get_class($parser)));
                }
            }
        }

        return $value;
    }
1010294
private function process(MapperInterface $mapper, $result, $field = null, $type = null)
    {
        while ($value = pg_fetch_assoc($result)) {
            $value = json_decode($value['json'], true);

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

            if ($type !== null) {
                $value = $mapper->fromPg($value, $type);
            }

            yield $value;
        }

        pg_free_result($result);
    }
95022
private void field(AbstractClassTypeDeclarationBuilder declare) {
        FieldDescrBuilder field = null;
        String fname = null;
        try {
            fname = label(DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return;
        } catch (RecognitionException re) {
            reportError(re);
        }

        try {
            field = helper.start(declare,
                    FieldDescrBuilder.class,
                    fname);

            // type
            String type = type();
            if (state.failed)
                return;
            if (state.backtracking == 0)
                field.type(type);

            if (input.LA(1) == DRL6Lexer.EQUALS_ASSIGN) {
                // EQUALS_ASSIGN
                match(input,
                        DRL6Lexer.EQUALS_ASSIGN,
                        null,
                        null,
                        DroolsEditorType.SYMBOL);
                if (state.failed)
                    return;

                int first = input.index();
                exprParser.conditionalExpression();
                if (state.failed)
                    return;
                if (state.backtracking == 0 && input.index() > first) {
                    // expression consumed something
                    String value = input.toString(first,
                            input.LT(-1).getTokenIndex());
                    field.initialValue(value);
                }
            }

            while (input.LA(1) == DRL6Lexer.AT) {
                // annotation*
                annotation(field);
                if (state.failed)
                    return;
            }

            if (input.LA(1) == DRL6Lexer.SEMICOLON) {
                match(input,
                        DRL6Lexer.SEMICOLON,
                        null,
                        null,
                        DroolsEditorType.SYMBOL);
                if (state.failed)
                    return;
            }

        } catch (RecognitionException re) {
            reportError(re);
        } finally {
            helper.end(FieldDescrBuilder.class,
                    field);
        }
    }