Skip to content

Commit

Permalink
Improve documentation for the Doctrine ORM expression transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreyu committed Jul 13, 2024
1 parent fb63a32 commit 908c391
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions docs/src/docs/integrations/doctrine-orm/expression-transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The expression transformers can be passed using the `expression_transformers` op
use App\DataTable\Filter\ExpressionTransformer\UnaccentExpressionTransformer;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\ExpressionTransformer\CallbackExpressionTransformer;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\ExpressionTransformer\LowerExpressionTransformer;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\ExpressionTransformer\TrimExpressionTransformer;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;
Expand All @@ -30,6 +31,10 @@ class ProductDataTableType extends AbstractDataTableType
'expression_transformers' => [
new LowerExpressionTransformer(),
new TrimExpressionTransformer(),
new CallbackExpressionTransformer(function (mixed $expression) {
// ...
return $expression;
})
],
])
;
Expand Down Expand Up @@ -93,11 +98,6 @@ class UnaccentExpressionTransformer implements ExpressionTransformerInterface

$leftExpr = sprintf('UNACCENT(%s)', (string) $expression->getLeftExpr());
$rightExpr = sprintf('UNACCENT(%s)', (string) $expression->getRightExpr());

// or use expression API:
//
// $leftExpr = new Expr\Func('UNACCENT', $expression->getLeftExpr());
// $rightExpr = new Expr\Func('UNACCENT', $expression->getRightExpr());

return new Comparison($leftExpr, $expression->getOperator(), $rightExpr);
}
Expand All @@ -117,19 +117,11 @@ class UnaccentExpressionTransformer extends AbstractComparisonExpressionTransfor
protected function transformLeftExpr(mixed $leftExpr): mixed
{
return sprintf('UNACCENT(%s)', (string) $leftExpr);

// or use expression API:
//
// return new Expr\Func('UNACCENT', $leftExpr);
}

protected function transformRightExpr(mixed $rightExpr): mixed
{
return sprintf('UNACCENT(%s)', (string) $rightExpr);

// or use expression API:
//
// return new Expr\Func('UNACCENT', $rightExpr);
}
}
```
Expand Down Expand Up @@ -181,7 +173,7 @@ class ProductDataTableType extends AbstractDataTableType
}
```

## Adding an option to automatically apply transformer
## Adding an option to automatically apply the transformer

Following the above example of `UnaccentExpressionTransformer`, let's assume, that we want to create such definition:

Expand Down

0 comments on commit 908c391

Please sign in to comment.