You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The metadata for the InArray validator is not complete. It is missing the haystack key. However, this might have been intentional as there is no way to set an array to the haystack via the admin. But then you could argue why even have this validator in Apigility admin at all.
I solved this in a project by extending the InArray validator and adding a haystack and haystack_delimiter key to the validator metadata which allows me to pass a comma separated string to the setHaystack() method, exploding it to an array based on the haystack_delimiter key. Not sure if this is the best way to do it, but it is working for my needs.
namespaceValidator;
useZend\Validator\InArrayasZendInArray;
/** * Class InArray * @package Validator */classInArrayextendsZendInArray {
/** * The delimiter to be used to explode the string to an array * @var string */protected$haystackDelimiter = ',';
/** * @return string */publicfunctiongetHaystackDelimiter()
{
return$this->haystackDelimiter;
}
/** * @param string $haystackDelimiter * @return InArray */publicfunctionsetHaystackDelimiter($haystackDelimiter)
{
$this->haystackDelimiter = $haystackDelimiter;
return$this;
}
/** * @param array|string $haystack * @return ZendInArray */publicfunctionsetHaystack($haystack)
{
if( is_string($haystack) ) {
if( ! strstr($haystack, $this->getHaystackDelimiter()) ) {
$haystack = array($haystack);
} else {
$haystack = explode($this->getHaystackDelimiter(), $haystack);
}
}
returnparent::setHaystack($haystack);
}
}
The metadata for the InArray validator is not complete. It is missing the haystack key. However, this might have been intentional as there is no way to set an array to the haystack via the admin. But then you could argue why even have this validator in Apigility admin at all.
I solved this in a project by extending the InArray validator and adding a haystack and haystack_delimiter key to the validator metadata which allows me to pass a comma separated string to the setHaystack() method, exploding it to an array based on the haystack_delimiter key. Not sure if this is the best way to do it, but it is working for my needs.
And the config of:
Originally posted by @spectravp at zfcampus/zf-apigility-admin#242
The text was updated successfully, but these errors were encountered: