Skip to content

Commit

Permalink
Criteria: Added support for LENGTH(), LOWER(), UPPER(), `LTRIM(…
Browse files Browse the repository at this point in the history
…)`, `RTRIM()` and `TRIM()`
  • Loading branch information
mahagr committed Jul 5, 2018
1 parent 07f8dfb commit b414880
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#improved)
* Made `ObjectCollection::matching()` criteria expressions to behave more like in Twig
* Criteria: Added support for `LENGTH()`, `LOWER()`, `UPPER()`, `LTRIM()`, `RTRIM()` and `TRIM()`
1. [](#bugfix)
* Fixed regression in 1.5.0-beta.1 blueprint extend and embed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,69 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
*/
public static function getObjectFieldValue($object, $field)
{
if (isset($object[$field])) {
return $object[$field];
$op = $value = null;

$pos = strpos($field, '(');
if (false !== $pos) {
list ($op, $field) = explode('(', $field, 2);
$field = rtrim($field, ')');
}

$accessors = array('', 'get', 'is');
if (isset($object[$field])) {
$value = $object[$field];
} else {
$accessors = array('', 'get', 'is');

foreach ($accessors as $accessor) {
$accessor .= $field;

foreach ($accessors as $accessor) {
$accessor .= $field;
if (!method_exists($object, $accessor)) {
continue;
}

if (!method_exists($object, $accessor)) {
continue;
$value = $object->{$accessor}();
break;
}
}

return $object->{$accessor}();
if ($op) {
$function = 'filter' . ucfirst(strtolower($op));
if (method_exists(static::class, $function)) {
$value = static::$function($value);
}
}

return null;
return $value;
}

public static function filterLower($str)
{
return mb_strtolower($str);
}

public static function filterUpper($str)
{
return mb_strtoupper($str);
}

public static function filterLength($str)
{
return mb_strlen($str);
}

public static function filterLtrim($str)
{
return ltrim($str);
}

public static function filterRtrim($str)
{
return rtrim($str);
}

public static function filterTrim($str)
{
return trim($str);
}

/**
Expand Down

0 comments on commit b414880

Please sign in to comment.