Skip to content

CallUserFunc Scalar Function #1707

@norberttech

Description

@norberttech

Describe the Proposal

Currently there is no easy way to apply simple php functions or static methods on a cell.
This means that every time we want to add a transformation that would require a custom logic, new scalar functions is required.

For simple scenarios where we just want to use a native php function or even a static method a ScalarFunction that would use call_user_func under the hood should be enough.

API Adjustments

This is the tricky part, I don't yet know what would be the best API for CallUserFunction scalar function.

We need to support at least this:

ref('array')->call('count')
ref('array')->call('\My\Namespace\Functions\count')
ref('array')->call('\My\Namespace\Class::count')

But we should also allow for:

  • passing additional arguments
  • passing a value from a row under different name. For example when columns is called array but the function expects $collection there should be a way to tell CallScalarFunction to pass value of array entry as a collection like for example `...[$refAlias => (new Parameter($this->ref))->eval()

So probably something like:

ref('collection')->call(
  callable: 'implode', // accepts a callable 
  arguments: ['separator' => ','], // default [] 
  refAlias: 'array', // default null
  returnType => type_string() // default null
)

Are you intenting to also work on proposed change?

Yes

Are you interested in sponsoring this change?

None

Integration & Dependencies

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions