Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Latest commit

 

History

History
71 lines (61 loc) · 1.25 KB

IteratableToNodeConverter.md

File metadata and controls

71 lines (61 loc) · 1.25 KB

IteratableToNodeConverter

Without allowSerializeEmpty

<?php

use Saxulum\ElasticSearchQueryBuilder\Converter\IteratableToNodeConverter;
use Saxulum\ElasticSearchQueryBuilder\Converter\ScalarToNodeConverter;
use Saxulum\ElasticSearchQueryBuilder\Node\ObjectNode;

$iteratableConverter = new IteratableToNodeConverter(new ScalarToNodeConverter());
$node = $iteratableConverter->convert([
  'key' => [
      true,
      1.234,
      1,
      null,
      'string',
      []
   ]
]); // instanceof ObjectNode::class
echo $node->json(true));
{
  "key": [
      true,
      1.234,
      1,
      null,
      "string"
  ]
}

With allowSerializeEmpty

<?php

use Saxulum\ElasticSearchQueryBuilder\Converter\IteratableToNodeConverter;
use Saxulum\ElasticSearchQueryBuilder\Converter\ScalarToNodeConverter;
use Saxulum\ElasticSearchQueryBuilder\Node\ObjectNode;

$iteratableConverter = new IteratableToNodeConverter(new ScalarToNodeConverter());
$node = $iteratableConverter->convert([
  'key' => [
      true,
      1.234,
      1,
      null,
      'string',
      []
   ]
], true); // instanceof ObjectNode::class
echo $node->json(true));
{
  "key": [
      true,
      1.234,
      1,
      null,
      "string",
      []
  ]
}