I am using Laminas DoctrineObjectInputFilter
and want to get the value of other properties in the callback input filter like this code is in the init function of the Filter
class which extends DoctrineObjectInputFilter
// input filter whose value is required $this->add([ 'name' => 'name', 'allow_empty' => false, 'filters' => [] ]); // Input filter in which I want value of input name $this->add([ 'name' => 'value', 'allow_empty' => true, 'filters' => [ [ 'name' => 'Callback', 'options' => [ 'callback' => function ($value) { $name = // want to get property name value here if (key_exists($name, $this->applicationConfig) && gettype($value) === 'string') { return trim(strip_tags($value)); } else { return trim($value); } return $value; }, ], ], ], ]);
Checked $this->getRawValues()
but it returns null for all inputs.
P粉8422150062024-03-29 13:22:50
A bit late, but I guess you are searching for $context
. Since the value of name is in the same InputFilter
instance, you only need to use $context
in the callback function.
add([ 'name' => 'name', 'required' => true, 'allow_empty' => false, 'filters' => [ [ 'name' => StripTags::class ], [ 'name' => StringTrim::class ], [ 'name' => ToNull::class, 'options' => [ 'type' => ToNull::TYPE_STRING, ], ], ], ]); $this->add([ 'name' => 'value', 'required' => true, 'allow_empty' => true, 'filters' => [], 'validators' => [ [ 'name' => Callback::class, 'options' => [ 'callback' => function($value, $context) { $name = $context['name']; ... }, ], ], ], ]); } }