Skip to content

Commit

Permalink
Merge pull request #193 from meilisearch/add-analytics
Browse files Browse the repository at this point in the history
Feature/Add analytics
  • Loading branch information
brunoocasali authored Aug 16, 2022
2 parents 788dbfb + 40baf55 commit 7efe6de
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 70 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m

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

```ruby
```php
VERSION = 'X.X.X'
```

Expand Down
133 changes: 67 additions & 66 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
{
"name": "meilisearch/search-bundle",
"description": "Seamless integration of Meilisearch into your Symfony project.",
"keywords": [
"meilisearch",
"instant",
"search",
"api",
"symfony",
"bundle"
],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "David Sanchez",
"email": "david38sanchez@gmail.com"
}
],
"require": {
"php": "^7.4|^8.0",
"ext-json": "*",
"doctrine/doctrine-bundle": "^2.4",
"illuminate/collections": "^8.47",
"meilisearch/meilisearch-php": "^0.24.0",
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"doctrine/orm": "^2.9",
"friendsofphp/php-cs-fixer": "^3.0",
"nyholm/psr7": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan-doctrine": "^0.12.39",
"phpstan/phpstan-phpunit": "^0.12.20",
"phpstan/phpstan-symfony": "^0.12.37",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
},
"autoload": {
"psr-4": {
"MeiliSearch\\Bundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MeiliSearch\\Bundle\\Test\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
"name": "meilisearch/search-bundle",
"description": "Seamless integration of Meilisearch into your Symfony project.",
"keywords": [
"meilisearch",
"instant",
"search",
"api",
"symfony",
"bundle"
],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "David Sanchez",
"email": "david38sanchez@gmail.com"
}
],
"require": {
"php": "^7.4|^8.0",
"ext-json": "*",
"doctrine/doctrine-bundle": "^2.4",
"illuminate/collections": "^8.47",
"meilisearch/meilisearch-php": "^0.24.2",
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"doctrine/orm": "^2.9",
"friendsofphp/php-cs-fixer": "^3.0",
"nyholm/psr7": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan-doctrine": "^0.12.39",
"phpstan/phpstan-phpunit": "^0.12.20",
"phpstan/phpstan-symfony": "^0.12.37",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.3"
},
"autoload": {
"psr-4": {
"MeiliSearch\\Bundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MeiliSearch\\Bundle\\Test\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
}
}
8 changes: 5 additions & 3 deletions src/DependencyInjection/MeiliSearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MeiliSearch\Bundle\DependencyInjection;

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

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

$container->setParameter('meili_url', $config['url']);
$container->setParameter('meili_api_key', $config['api_key']);
$container->setParameter('meili_url', $config['url'] ?? null);
$container->setParameter('meili_api_key', $config['api_key'] ?? null);
$container->setParameter('meili_symfony_version', MeiliSearchBundle::qualifiedVersion());

if (\count($doctrineSubscribedEvents = $config['doctrineSubscribedEvents']) > 0) {
$container->getDefinition('search.search_indexer_subscriber')->setArgument(1, $doctrineSubscribedEvents);
Expand Down
5 changes: 5 additions & 0 deletions src/MeiliSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
final class MeiliSearchBundle extends Bundle
{
public const VERSION = '0.8.0';

public static function qualifiedVersion()
{
return sprintf('Meilisearch Symfony (v%s)', MeiliSearchBundle::VERSION);
}
}
3 changes: 3 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<argument key="$url">%meili_url%</argument>
<argument key="$apiKey">%meili_api_key%</argument>
<argument key="$httpClient" type="service" id="psr18.http_client" on-invalid="ignore" />
<argument key="$clientAgents" type="collection">
<argument>%meili_symfony_version%</argument>
</argument>
</service>

<service id="MeiliSearch\Client" alias="search.client"/>
Expand Down
31 changes: 31 additions & 0 deletions tests/Integration/DependencyInjectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use MeiliSearch\Bundle\DependencyInjection\MeiliSearchExtension;
use MeiliSearch\Bundle\MeiliSearchBundle;

class MeiliSearchExtensionTest extends AbstractExtensionTestCase
{
protected function getContainerExtensions(): array
{
return [
new MeiliSearchExtension(),
];
}

public function testHasMeilisearchVersionDefinitionAfterLoad(): void
{
$this->load();

$this->assertContainerBuilderHasServiceDefinitionWithArgument('search.client', '$clientAgents', ['%meili_symfony_version%']);
}

public function testHasMeilisearchVersionFromConstantAfterLoad(): void
{
$this->load();

$this->assertContainerBuilderHasParameter('meili_symfony_version', MeiliSearchBundle::qualifiedVersion());
}
}

0 comments on commit 7efe6de

Please sign in to comment.