Skip to content

Commit 7efe6de

Browse files
authored
Merge pull request #193 from meilisearch/add-analytics
Feature/Add analytics
2 parents 788dbfb + 40baf55 commit 7efe6de

File tree

6 files changed

+112
-70
lines changed

6 files changed

+112
-70
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m
146146

147147
Make a PR modifying the file [`src/MeiliSearchBundle.php`](/src/MeiliSearchBundle.php) with the right version.
148148

149-
```ruby
149+
```php
150150
VERSION = 'X.X.X'
151151
```
152152

composer.json

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
11
{
2-
"name": "meilisearch/search-bundle",
3-
"description": "Seamless integration of Meilisearch into your Symfony project.",
4-
"keywords": [
5-
"meilisearch",
6-
"instant",
7-
"search",
8-
"api",
9-
"symfony",
10-
"bundle"
11-
],
12-
"type": "symfony-bundle",
13-
"license": "MIT",
14-
"authors": [
15-
{
16-
"name": "David Sanchez",
17-
"email": "[email protected]"
18-
}
19-
],
20-
"require": {
21-
"php": "^7.4|^8.0",
22-
"ext-json": "*",
23-
"doctrine/doctrine-bundle": "^2.4",
24-
"illuminate/collections": "^8.47",
25-
"meilisearch/meilisearch-php": "^0.24.0",
26-
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
27-
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
28-
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
29-
},
30-
"require-dev": {
31-
"doctrine/orm": "^2.9",
32-
"friendsofphp/php-cs-fixer": "^3.0",
33-
"nyholm/psr7": "^1.3",
34-
"phpstan/extension-installer": "^1.1",
35-
"phpstan/phpstan": "^0.12.90",
36-
"phpstan/phpstan-doctrine": "^0.12.39",
37-
"phpstan/phpstan-phpunit": "^0.12.20",
38-
"phpstan/phpstan-symfony": "^0.12.37",
39-
"phpunit/php-code-coverage": "^9.2",
40-
"phpunit/phpunit": "^9.5",
41-
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
42-
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
43-
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
44-
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
45-
},
46-
"autoload": {
47-
"psr-4": {
48-
"MeiliSearch\\Bundle\\": "src/"
49-
}
50-
},
51-
"autoload-dev": {
52-
"psr-4": {
53-
"MeiliSearch\\Bundle\\Test\\": "tests/"
54-
}
55-
},
56-
"config": {
57-
"sort-packages": true,
58-
"allow-plugins": {
59-
"phpstan/extension-installer": true
60-
}
61-
},
62-
"scripts": {
63-
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
64-
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
65-
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
66-
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
67-
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
2+
"name": "meilisearch/search-bundle",
3+
"description": "Seamless integration of Meilisearch into your Symfony project.",
4+
"keywords": [
5+
"meilisearch",
6+
"instant",
7+
"search",
8+
"api",
9+
"symfony",
10+
"bundle"
11+
],
12+
"type": "symfony-bundle",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "David Sanchez",
17+
"email": "[email protected]"
6818
}
19+
],
20+
"require": {
21+
"php": "^7.4|^8.0",
22+
"ext-json": "*",
23+
"doctrine/doctrine-bundle": "^2.4",
24+
"illuminate/collections": "^8.47",
25+
"meilisearch/meilisearch-php": "^0.24.2",
26+
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
27+
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
28+
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
29+
},
30+
"require-dev": {
31+
"doctrine/orm": "^2.9",
32+
"friendsofphp/php-cs-fixer": "^3.0",
33+
"nyholm/psr7": "^1.3",
34+
"phpstan/extension-installer": "^1.1",
35+
"phpstan/phpstan": "^0.12.90",
36+
"phpstan/phpstan-doctrine": "^0.12.39",
37+
"phpstan/phpstan-phpunit": "^0.12.20",
38+
"phpstan/phpstan-symfony": "^0.12.37",
39+
"phpunit/php-code-coverage": "^9.2",
40+
"phpunit/phpunit": "^9.5",
41+
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
42+
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
43+
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
44+
"symfony/yaml": "^4.4 || ^5.0 || ^6.0",
45+
"matthiasnoback/symfony-dependency-injection-test": "^4.3"
46+
},
47+
"autoload": {
48+
"psr-4": {
49+
"MeiliSearch\\Bundle\\": "src/"
50+
}
51+
},
52+
"autoload-dev": {
53+
"psr-4": {
54+
"MeiliSearch\\Bundle\\Test\\": "tests/"
55+
}
56+
},
57+
"config": {
58+
"sort-packages": true,
59+
"allow-plugins": {
60+
"phpstan/extension-installer": true
61+
}
62+
},
63+
"scripts": {
64+
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
65+
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
66+
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
67+
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
68+
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
69+
}
6970
}

src/DependencyInjection/MeiliSearchExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace MeiliSearch\Bundle\DependencyInjection;
66

77
use MeiliSearch\Bundle\Engine;
8+
use MeiliSearch\Bundle\MeiliSearchBundle;
89
use MeiliSearch\Bundle\Services\MeiliSearchService;
910
use Symfony\Component\Config\FileLocator;
1011
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -29,12 +30,13 @@ public function load(array $configs, ContainerBuilder $container): void
2930
$configuration = new Configuration();
3031
$config = $this->processConfiguration($configuration, $configs);
3132

32-
if (null === $config['prefix']) {
33+
if (null === $config['prefix'] && $container->hasParameter('kernel.environment')) {
3334
$config['prefix'] = $container->getParameter('kernel.environment').'_';
3435
}
3536

36-
$container->setParameter('meili_url', $config['url']);
37-
$container->setParameter('meili_api_key', $config['api_key']);
37+
$container->setParameter('meili_url', $config['url'] ?? null);
38+
$container->setParameter('meili_api_key', $config['api_key'] ?? null);
39+
$container->setParameter('meili_symfony_version', MeiliSearchBundle::qualifiedVersion());
3840

3941
if (\count($doctrineSubscribedEvents = $config['doctrineSubscribedEvents']) > 0) {
4042
$container->getDefinition('search.search_indexer_subscriber')->setArgument(1, $doctrineSubscribedEvents);

src/MeiliSearchBundle.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212
final class MeiliSearchBundle extends Bundle
1313
{
1414
public const VERSION = '0.8.0';
15+
16+
public static function qualifiedVersion()
17+
{
18+
return sprintf('Meilisearch Symfony (v%s)', MeiliSearchBundle::VERSION);
19+
}
1520
}

src/Resources/config/services.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<argument key="$url">%meili_url%</argument>
2222
<argument key="$apiKey">%meili_api_key%</argument>
2323
<argument key="$httpClient" type="service" id="psr18.http_client" on-invalid="ignore" />
24+
<argument key="$clientAgents" type="collection">
25+
<argument>%meili_symfony_version%</argument>
26+
</argument>
2427
</service>
2528

2629
<service id="MeiliSearch\Client" alias="search.client"/>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
6+
use MeiliSearch\Bundle\DependencyInjection\MeiliSearchExtension;
7+
use MeiliSearch\Bundle\MeiliSearchBundle;
8+
9+
class MeiliSearchExtensionTest extends AbstractExtensionTestCase
10+
{
11+
protected function getContainerExtensions(): array
12+
{
13+
return [
14+
new MeiliSearchExtension(),
15+
];
16+
}
17+
18+
public function testHasMeilisearchVersionDefinitionAfterLoad(): void
19+
{
20+
$this->load();
21+
22+
$this->assertContainerBuilderHasServiceDefinitionWithArgument('search.client', '$clientAgents', ['%meili_symfony_version%']);
23+
}
24+
25+
public function testHasMeilisearchVersionFromConstantAfterLoad(): void
26+
{
27+
$this->load();
28+
29+
$this->assertContainerBuilderHasParameter('meili_symfony_version', MeiliSearchBundle::qualifiedVersion());
30+
}
31+
}

0 commit comments

Comments
 (0)