for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of Solr Client Symfony package.
*
* (c) ingatlan.com Zrt. <[email protected]>
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace iCom\SolrClient\Query\Command;
use iCom\SolrClient\JsonHelper;
use iCom\SolrClient\Query\Command;
/**
* @see https://lucene.apache.org/solr/guide/8_3/uploading-data-with-index-handlers.html#adding-documents
* @psalm-immutable
final class Add implements Command
{
use JsonHelper;
* @psalm-var array{commitWithin: ?int, doc: ?array, overwrite: ?bool}
private array $options = [
'doc' => null,
'commitWithin' => null,
'overwrite' => null,
];
public function __construct(array $document)
$this->options['doc'] = $document;
}
* @psalm-pure
public static function create(array $document): self
return new self($document);
public function commitWithin(int $commitWithin): self
$add = clone $this;
$add->options['commitWithin'] = $commitWithin;
return $add;
public function enableOverWrite(): self
$add->options['overwrite'] = true;
public function disableOverWrite(): self
$add->options['overwrite'] = false;
public function toJson(): string
return self::jsonEncode(array_filter($this->options, static function ($option): bool { return null !== $option; }));
public function getName(): string
return 'add';