mdiyakov /
DoctrineSolrBundle
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Mdiyakov\DoctrineSolrBundle\Indexer; |
||||
| 4 | |||||
| 5 | use Mdiyakov\DoctrineSolrBundle\Config\Config; |
||||
| 6 | use Mdiyakov\DoctrineSolrBundle\Exception\EntityNotIndexedException; |
||||
| 7 | use Mdiyakov\DoctrineSolrBundle\Query\UpdateQueryBuilder; |
||||
| 8 | |||||
| 9 | class IndexerBuilder |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * @var Config |
||||
| 13 | */ |
||||
| 14 | private $config; |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * @var UpdateQueryBuilder |
||||
| 18 | */ |
||||
| 19 | private $queryBuilder; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @param $config |
||||
| 23 | * @param UpdateQueryBuilder $queryBuilder |
||||
| 24 | */ |
||||
| 25 | public function __construct($config, UpdateQueryBuilder $queryBuilder) |
||||
| 26 | { |
||||
| 27 | $this->config = $config; |
||||
| 28 | $this->queryBuilder = $queryBuilder; |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * @param string $entityClass |
||||
| 33 | * @return Indexer |
||||
| 34 | * @throws EntityNotIndexedException |
||||
| 35 | */ |
||||
| 36 | public function createByEntityClass($entityClass) |
||||
| 37 | { |
||||
| 38 | $result = null; |
||||
| 39 | $classes = class_parents($entityClass); |
||||
| 40 | array_unshift($classes, $entityClass); |
||||
| 41 | |||||
| 42 | foreach ($classes as $entityClass) { |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 43 | $entityConfig = $this->config->getEntityConfig($entityClass); |
||||
| 44 | if (!$entityConfig) { |
||||
| 45 | continue; |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | $schema = $this->config->getSchemaByEntityClass($entityClass); |
||||
| 49 | $updateQuery = $this->queryBuilder->buildUpdateQuery($schema); |
||||
| 50 | $result = new Indexer($updateQuery, $schema, $entityConfig); |
||||
|
0 ignored issues
–
show
$entityConfig of type array<mixed,string[]> is incompatible with the type string[] expected by parameter $entityConfig of Mdiyakov\DoctrineSolrBun...\Indexer::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 51 | break; |
||||
| 52 | } |
||||
| 53 | |||||
| 54 | if (!$result) { |
||||
| 55 | throw new EntityNotIndexedException( |
||||
| 56 | sprintf('"%s" or parents is not indexed. Check config.yml', $entityClass) |
||||
| 57 | ); |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | return $result; |
||||
| 61 | } |
||||
| 62 | } |