I want to configure my index types of Elastica dynamically based on entity list which I can get from entity repository. To do this I must have instance of repository so doctrine EntityManager must exist so Depedency Inject container must by compiled. But when it is compiled is too late for configure Elastica because container is frozen.
This is what i tried:
#config.yml
fos_elastica:
clients:
default: { host: 127.0.0.1, port: 9200 }
indexes:
app:
types: %elastic_types%
#application bundle
public function build(ContainerBuilder $container){
$types = array(
'tag' => array(
'mappings' => array(
'text' => array()
),
'persistence' => array(
'driver' => 'orm',
'model' => 'Cloud\AdmBundle\Entity\Tag',
'provider' => array(),
'listener' => array(),
'finder' => array()
)
)
);
$container->setParameter('elastic_types', $types);
}
It works but i don't have capabilities to use EntityRepository here.
#application bundle
public function setContainer(ContainerInterface $container = null) {
parent::setContainer($container);
$container->setParameter('elastic_types', array('anything param'));
}
Here is too late to set any params because container is compiled and i get execption:
ParameterNotFoundException in ParameterBag.php line 106:
You have requested a non-existent parameter "elastic_types".
How can i do this ?