If we want to send data of array type in the http header, it must be written as an employeePersonal object, as in the following example.
/**
* @var object
* @OA\Property(
* @OA\Property(
* property="militaryStatusId",
* type="string",
* ),
* @OA\Property(
* property="militaryStartDate",
* type="string",
* ),
* @OA\Property(
* property="militaryEndDate",
* type="string",
* ),
* @OA\Property(
* property="marialStatusId",
* type="string",
* ),
* );
*/
public $employeePersonal;
{
"id": "string",
"name": "string",
"surname": "string",
"employeePersonal": {
"militaryStatusId": "string",
"militaryStartDate": "string",
"militaryEndDate": "string",
"marialStatusId": "string"
}
}
[
"id": "string",
"name": "string",
"surname": "string",
"employeePersonal": [
"militaryStatusId": "string",
"militaryStartDate": "string",
"militaryEndDate": "string",
"marialStatusId": "string"
],
]
Within the Employees\SaveFilter class, the App\Filter\ObjectInputFilter and the EmployeePersonal object can be defined as follows.
namespace App\Filter\Employees;
use Laminas\Validator\Uuid;
use Laminas\Validator\Date;
use Laminas\Validator\InArray;
use Laminas\Validator\StringLength;
use Laminas\Validator\Db\RecordExists;
use Laminas\Validator\Db\NoRecordExists;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\InputFilter\InputFilterPluginManager;
class SaveFilter extends InputFilter
{
public function __construct(
AdapterInterface $adapter,
InputFilterPluginManager $filter
)
{
$this->filter = $filter;
$this->adapter = $adapter;
}
public function setInputData(array $data)
{
$this->add([
'name' => 'id',
'required' => true,
'validators' => [
['name' => Uuid::class],
[
'name' => HTTP_METHOD == 'POST' ? NoRecordExists::class : RecordExists::class,
'options' => [
'table' => 'employees',
'field' => 'employeeId',
'adapter' => $this->adapter,
]
]
],
]);
$this->add([
'name' => 'name',
'required' => true,
'validators' => [
[
'name' => StringLength::class,
'options' => [
'encoding' => 'UTF-8',
'min' => 2,
'max' => 60,
],
],
],
]);
$this->add([
'name' => 'surname',
'required' => true,
'validators' => [
[
'name' => StringLength::class,
'options' => [
'encoding' => 'UTF-8',
'min' => 2,
'max' => 60,
],
],
],
]);
// Employee personal "object filter"
//
$objectFilter = $this->filter->get(ObjectInputFilter::class);
$objectFilter->add([
'name' => 'militaryStatusId',
'required' => false,
'validators' => [
[
'name' => InArray::class,
'options' => [
'haystack' => ['postponement','discharge','exempt'],
],
],
],
]);
$objectFilter->add([
'name' => 'militaryStartDate',
'required' => false,
'validators' => [
[
'name' => Date::class,
'options' => [
'format' => 'Y-m-d',
'strict' => true,
]
],
],
]);
$objectFilter->add([
'name' => 'militaryEndDate',
'required' => false,
'validators' => [
[
'name' => Date::class,
'options' => [
'format' => 'Y-m-d',
'strict' => true,
]
],
],
]);
$objectFilter->add([
'name' => 'marialStatusId',
'required' => false,
'validators' => [
[
'name' => InArray::class,
'options' => [
'haystack' => ['married','single'],
],
],
],
]);
$this->add($objectFilter, 'employeePersonal');
// Set input data
//
$this->renderInputData($data);
}
}