Skip to content

Commit 47c3419

Browse files
authored
Merge branch 'main' into meili-bot/update-documentation-links
2 parents 3ad00f6 + 5cf666e commit 47c3419

32 files changed

+333
-123
lines changed

.code-samples.meilisearch.yaml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
landing_getting_started_1: |-
2-
```yml
3-
# Configure your entities by adding them in config/packages/meilisearch.yaml
4-
meilisearch:
5-
url: 'http://127.0.0.1:7700'
6-
api_key: 'masterKey'
7-
indices:
8-
- name: movies
9-
class: App\Entity\Movie
10-
```
11-
12-
```php
2+
// # Configure your entities by adding them in config/packages/meilisearch.yaml
3+
// meilisearch:
4+
// url: 'http://127.0.0.1:7700'
5+
// api_key: 'masterKey'
6+
// indices:
7+
// - name: movies
8+
// class: App\Entity\Movie
9+
1310
<?php
1411
// src/Controller/MoviesController.php
1512
namespace App\Controller;
@@ -40,4 +37,3 @@ landing_getting_started_1: |-
4037
//...
4138
}
4239
}
43-
```

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'import_functions' => false,
1717
'import_constants' => false,
1818
],
19+
'no_superfluous_phpdoc_tags' => false,
1920
]
2021
)
2122
->setRiskyAllowed(true)

config/services.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
class="Meilisearch\Bundle\EventListener\DoctrineEventSubscriber"
1313
public="true">
1414
<argument type="service" id="search.service"/>
15-
<argument type="collection"/> <!-- doctrine subscribed events -->
16-
<tag name="doctrine.event_subscriber"/>
17-
<tag name="doctrine_mongodb.odm.event_subscriber"/>
1815
</service>
1916

2017
<service id="search.client" class="Meilisearch\Client" public="true" lazy="true">

src/Collection.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ final class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
1717
*/
1818
private array $items;
1919

20-
/**
21-
* @param mixed $items
22-
*/
2320
public function __construct($items = [])
2421
{
2522
$this->items = $this->getArrayableItems($items);
@@ -30,12 +27,6 @@ public function all(): array
3027
return $this->items;
3128
}
3229

33-
/**
34-
* @param mixed $key
35-
* @param mixed $default
36-
*
37-
* @return mixed
38-
*/
3930
public function get($key, $default = null)
4031
{
4132
if (array_key_exists($key, $this->items)) {
@@ -151,10 +142,6 @@ public function unique($key = null, bool $strict = false)
151142

152143
/**
153144
* Get the first item from the collection passing the given truth test.
154-
*
155-
* @param mixed $default
156-
*
157-
* @return mixed
158145
*/
159146
public function first(callable $callback = null, $default = null)
160147
{
@@ -181,27 +168,18 @@ public function first(callable $callback = null, $default = null)
181168
* Get the first item by the given key value pair.
182169
*
183170
* @param string $key
184-
* @param mixed $operator
185-
* @param mixed $value
186-
*
187-
* @return mixed
188171
*/
189172
public function firstWhere($key, $operator = null, $value = null)
190173
{
191174
return $this->first($this->operatorForWhere(...func_get_args()));
192175
}
193176

194-
/**
195-
* @param mixed $offset
196-
*/
197177
public function offsetExists($offset): bool
198178
{
199179
return isset($this->items[$offset]);
200180
}
201181

202182
/**
203-
* @param mixed $offset
204-
*
205183
* @return mixed
206184
*/
207185
#[\ReturnTypeWillChange]
@@ -210,10 +188,6 @@ public function offsetGet($offset)
210188
return $this->items[$offset];
211189
}
212190

213-
/**
214-
* @param mixed $offset
215-
* @param mixed $value
216-
*/
217191
public function offsetSet($offset, $value): void
218192
{
219193
if (is_null($offset)) {
@@ -223,9 +197,6 @@ public function offsetSet($offset, $value): void
223197
}
224198
}
225199

226-
/**
227-
* @param mixed $offset
228-
*/
229200
public function offsetUnset($offset): void
230201
{
231202
unset($this->items[$offset]);
@@ -241,9 +212,6 @@ public function getIterator(): \ArrayIterator
241212
return new \ArrayIterator($this->items);
242213
}
243214

244-
/**
245-
* @param mixed $items
246-
*/
247215
private function getArrayableItems($items): array
248216
{
249217
if (is_array($items)) {
@@ -269,9 +237,6 @@ private function getArrayableItems($items): array
269237
return (array) $items;
270238
}
271239

272-
/**
273-
* @param mixed $value
274-
*/
275240
private function useAsCallable($value): bool
276241
{
277242
return !is_string($value) && is_callable($value);
@@ -292,11 +257,7 @@ private function valueRetriever($value)
292257
}
293258

294259
/**
295-
* @param mixed $target
296260
* @param string|array|int|null $key
297-
* @param mixed $default
298-
*
299-
* @return mixed
300261
*/
301262
private static function getDeepData($target, $key, $default = null)
302263
{
@@ -358,9 +319,6 @@ public static function arrayCollapse(iterable $array): array
358319
return array_merge([], ...$results);
359320
}
360321

361-
/**
362-
* @param mixed $value
363-
*/
364322
public static function accessible($value): bool
365323
{
366324
return is_array($value) || $value instanceof \ArrayAccess;
@@ -381,10 +339,7 @@ private static function existsInArray($array, $key): bool
381339
return array_key_exists($key, $array);
382340
}
383341

384-
/**
385-
* @param mixed $value
386-
*/
387-
private function operatorForWhere(string $key, ?string $operator = null, $value = null): \Closure
342+
private function operatorForWhere(string $key, string $operator = null, $value = null): \Closure
388343
{
389344
if (1 === func_num_args()) {
390345
$value = true;

src/Command/MeilisearchCreateCommand.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Meilisearch\Bundle\Exception\TaskException;
1010
use Meilisearch\Bundle\Model\Aggregator;
1111
use Meilisearch\Bundle\SearchService;
12+
use Meilisearch\Bundle\SettingsProvider;
1213
use Meilisearch\Client;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Input\InputOption;
@@ -42,7 +43,7 @@ protected function configure(): void
4243
->addOption('indices', 'i', InputOption::VALUE_OPTIONAL, 'Comma-separated list of index names');
4344
}
4445

45-
private function entitiesToIndex($indexes)
46+
private function entitiesToIndex($indexes): array
4647
{
4748
foreach ($indexes as $key => $index) {
4849
$entityClassName = $index['class'];
@@ -85,16 +86,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8586
foreach ($index['settings'] as $variable => $value) {
8687
$method = sprintf('update%s', ucfirst($variable));
8788

88-
if (false === method_exists($indexInstance, $method)) {
89+
if (!method_exists($indexInstance, $method)) {
8990
throw new InvalidSettingName(sprintf('Invalid setting name: "%s"', $variable));
9091
}
9192

93+
if (isset($value['_service']) && $value['_service'] instanceof SettingsProvider) {
94+
$value = $value['_service']();
95+
}
96+
97+
// Update
9298
$task = $indexInstance->{$method}($value);
99+
100+
// Get task information using uid
101+
$indexInstance->waitForTask($task['taskUid']);
93102
$task = $indexInstance->getTask($task['taskUid']);
94103

95104
if ('failed' === $task['status']) {
96105
throw new TaskException($task['error']);
97106
}
107+
108+
$output->writeln('<info>Settings updated of "'.$index['name'].'".</info>');
98109
}
99110
}
100111
}

src/Command/MeilisearchImportCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Meilisearch\Bundle\Exception\TaskException;
1111
use Meilisearch\Bundle\Model\Aggregator;
1212
use Meilisearch\Bundle\SearchService;
13+
use Meilisearch\Bundle\SettingsProvider;
1314
use Meilisearch\Client;
15+
use Meilisearch\Exceptions\TimeOutException;
1416
use Symfony\Component\Console\Input\InputInterface;
1517
use Symfony\Component\Console\Input\InputOption;
1618
use Symfony\Component\Console\Output\OutputInterface;
@@ -155,10 +157,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
155157
$indexInstance = $this->searchClient->index($index['name']);
156158
foreach ($index['settings'] as $variable => $value) {
157159
$method = sprintf('update%s', ucfirst($variable));
158-
if (false === method_exists($indexInstance, $method)) {
160+
161+
if (!method_exists($indexInstance, $method)) {
159162
throw new InvalidSettingName(sprintf('Invalid setting name: "%s"', $variable));
160163
}
161164

165+
if (isset($value['_service']) && $value['_service'] instanceof SettingsProvider) {
166+
$value = $value['_service']();
167+
}
168+
162169
// Update
163170
$task = $indexInstance->{$method}($value);
164171

@@ -168,9 +175,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
168175

169176
if ('failed' === $task['status']) {
170177
throw new TaskException($task['error']);
171-
} else {
172-
$output->writeln('<info>Settings updated.</info>');
173178
}
179+
180+
$output->writeln('<info>Settings updated of "'.$index['name'].'".</info>');
174181
}
175182
}
176183

@@ -185,7 +192,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
185192
return 0;
186193
}
187194

188-
/*
195+
/**
189196
* @throws TimeOutException
190197
*/
191198
private function formatIndexingResponse(array $batch, int $responseTimeout): array

src/DependencyInjection/MeilisearchExtension.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
final class MeilisearchExtension extends Extension
2121
{
22-
/**
23-
* {@inheritdoc}
24-
*/
2522
public function load(array $configs, ContainerBuilder $container): void
2623
{
2724
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
@@ -34,12 +31,21 @@ public function load(array $configs, ContainerBuilder $container): void
3431
$config['prefix'] = $container->getParameter('kernel.environment').'_';
3532
}
3633

34+
foreach ($config['indices'] as $index => $indice) {
35+
$config['indices'][$index]['settings'] = $this->findReferences($config['indices'][$index]['settings']);
36+
}
37+
3738
$container->setParameter('meili_url', $config['url'] ?? null);
3839
$container->setParameter('meili_api_key', $config['api_key'] ?? null);
3940
$container->setParameter('meili_symfony_version', MeilisearchBundle::qualifiedVersion());
4041

4142
if (\count($doctrineEvents = $config['doctrineSubscribedEvents']) > 0) {
42-
$container->getDefinition('search.search_indexer_subscriber')->setArgument(1, $doctrineEvents);
43+
$subscriber = $container->getDefinition('search.search_indexer_subscriber');
44+
45+
foreach ($doctrineEvents as $event) {
46+
$subscriber->addTag('doctrine.event_listener', ['event' => $event]);
47+
$subscriber->addTag('doctrine_mongodb.odm.event_listener', ['event' => $event]);
48+
}
4349
} else {
4450
$container->removeDefinition('search.search_indexer_subscriber');
4551
}
@@ -53,4 +59,22 @@ public function load(array $configs, ContainerBuilder $container): void
5359

5460
$container->setDefinition('search.service', $searchDefinition->setPublic(true));
5561
}
62+
63+
/**
64+
* @param array<mixed, mixed> $settings
65+
*
66+
* @return array<mixed, mixed>
67+
*/
68+
private function findReferences(array $settings): array
69+
{
70+
foreach ($settings as $key => $value) {
71+
if (is_array($value)) {
72+
$settings[$key] = $this->findReferences($value);
73+
} elseif ('_service' === substr((string) $key, -8) || str_starts_with((string) $value, '@') || 'service' === $key) {
74+
$settings[$key] = new Reference(ltrim($value, '@'));
75+
}
76+
}
77+
78+
return $settings;
79+
}
5680
}

src/EventListener/DoctrineEventSubscriber.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,16 @@
44

55
namespace Meilisearch\Bundle\EventListener;
66

7-
use Doctrine\Common\EventSubscriber;
87
use Doctrine\Persistence\Event\LifecycleEventArgs;
98
use Meilisearch\Bundle\SearchService;
109

11-
final class DoctrineEventSubscriber implements EventSubscriber
10+
final class DoctrineEventSubscriber
1211
{
1312
private SearchService $searchService;
14-
private array $subscribedEvents;
1513

16-
public function __construct(SearchService $searchService, array $subscribedEvents)
14+
public function __construct(SearchService $searchService)
1715
{
1816
$this->searchService = $searchService;
19-
$this->subscribedEvents = $subscribedEvents;
20-
}
21-
22-
public function getSubscribedEvents(): array
23-
{
24-
return $this->subscribedEvents;
2517
}
2618

2719
public function postUpdate(LifecycleEventArgs $args): void

src/MeilisearchBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
final class MeilisearchBundle extends Bundle
1313
{
14-
public const VERSION = '0.12.0';
14+
public const VERSION = '0.13.0';
1515

1616
public static function qualifiedVersion()
1717
{

src/Model/Aggregator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public static function getEntityClassFromObjectID(string $objectId): string
7878
throw new EntityNotFoundInObjectID("Entity class from ObjectID $objectId not found.");
7979
}
8080

81-
/**
82-
* {@inheritdoc}
83-
*/
84-
public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = []): array
81+
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []): array
8582
{
8683
return array_merge(['objectID' => $this->objectID], $normalizer->normalize($this->entity, $format, $context));
8784
}

0 commit comments

Comments
 (0)