-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an interface for each condition factory to allow decorating #252
Comments
The alternative would be to expand each factory to support that use case out of the box, maybe also something to think about. |
@dkarlovi is this Elasticsearch specific? And if so, is it still relevant? |
It's definitely relevant, since now I have to extend the existing factory instead of implementing the interface. Currently I have: <?php
declare(strict_types=1);
namespace App\Infrastructure\RollerworksSearch\Elasticsearch;
use Rollerworks\Component\Search\Elasticsearch\ConditionGenerator;
use Rollerworks\Component\Search\Elasticsearch\ElasticsearchFactory;
use Rollerworks\Component\Search\SearchCondition;
class DynamicElasticsearchFactory extends ElasticsearchFactory
{
/**
* @var ElasticsearchFactory
*/
private $factory;
/**
* @var array
*/
private $mappings = [];
public function __construct(ElasticsearchFactory $factory)
{
$this->factory = $factory;
}
public function setMapping(string $name, array $mapping): void
{
$this->mappings[$name] = $mapping;
}
public function createConditionGenerator(SearchCondition $searchCondition): ConditionGenerator
{
$condition = $this->factory->createConditionGenerator($searchCondition);
$this->applyMappings($condition);
return $condition;
}
public function createCachedConditionGenerator(ConditionGenerator $conditionGenerator, $ttl = 0): ConditionGenerator
{
$condition = $this->factory->createCachedConditionGenerator($conditionGenerator, $ttl);
$this->applyMappings($condition);
return $condition;
}
private function applyMappings(ConditionGenerator $condition): void
{
foreach ($this->mappings as $name => $mapping) {
$condition->registerField($name, $mapping['mapping'], $mapping['conditions']);
}
}
} This allows me to decorate the condition factory with one which allows me to attach mappings before the condition is created (via The |
Description
Adding an interface to the factory allows to more easily decorate it for use cases such as #249 (comment)
The text was updated successfully, but these errors were encountered: