for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\FilterManagerBundle\Filter\Widget\Search;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Search;
use ONGR\FilterManagerBundle\Filter\FilterState;
use ONGR\FilterManagerBundle\Filter\Relation\RelationAwareTrait;
use ONGR\FilterManagerBundle\Search\SearchRequest;
use Symfony\Component\HttpFoundation\Request;
/**
* Filter for filtering on exact value in specified field.
class DocumentValue extends AbstractSingleValue
{
use RelationAwareTrait;
* {@inheritdoc}
public function getState(Request $request)
$state = new FilterState();
$document = $request->get('document');
if (is_object($document)) {
try {
$state->setValue(function ($document) {return $document->{$this->getOption('field')};});
$state->setActive(true);
} catch (\Exception $e) {}
}
return $state;
public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
$search->addPostFilter(new TermQuery($this->getDocumentField(), $state->getValue()));
$state
null
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:
function someFunction(A $objectMaybe = null) { if ($objectMaybe instanceof A) { $objectMaybe->doSomething(); } }