mapConditionOperator example

            // broken.             // On top of that the database API relies on __toString() which             // does not allow to throw exceptions.             trigger_error('Invalid characters in query operator: ' . $condition['operator'], E_USER_ERROR);
            return;
          }

          // For simplicity, we convert all operators to a data structure to           // allow to specify a prefix, a delimiter and such. Find the           // associated data structure by first doing a database specific           // lookup, followed by a specification according to the SQL standard.           $operator = $connection->mapConditionOperator($condition['operator']);
          if (!isset($operator)) {
            $operator = $this->mapConditionOperator($condition['operator']);
          }
          $operator += ['operator' => $condition['operator']];
        }
        // Add defaults.         $operator += [
          'prefix' => '',
          'postfix' => '',
          'delimiter' => '',
          'use_value' => TRUE,
        ];


  /** * @covers ::compile * @dataProvider providerSimpleCondition */
  public function testSimpleCondition($expected$field_name) {
    $connection = $this->prophesize(Connection::class);
    $connection->escapeField($field_name)->will(function D$args) {
      return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]);
    });
    $connection->mapConditionOperator('=')->willReturn(['operator' => '=']);
    $connection->condition('AND')->willReturn(new Condition('AND'));
    $connection = $connection->reveal();

    $query_placeholder = $this->prophesize(PlaceholderInterface::class);

    $counter = 0;
    $query_placeholder->nextPlaceholder()->will(function D) use (&$counter) {
      return $counter++;
    });
    $query_placeholder->uniqueIdentifier()->willReturn(4);
    $query_placeholder = $query_placeholder->reveal();

    
/** * Get specified condition operator mapping value. * * @param string $operator * Condition operator. * * @return string * Specified condition operator mapping value. */
  protected function getConditionOperator($operator) {
    $mapping = $this->connection->mapConditionOperator($operator);
    return $mapping['operator'] ?? $operator;
  }

  /** * Add this filter to the query. * * Due to the nature of fapi, the value and the operator have an unintended * level of indirection. You will find them in $this->operator * and $this->value respectively. */
  public function query() {
    
Home | Imprint | This part of the site doesn't use cookies.