Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ jobs:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
symfony: ['^7.0']
symfony: ['^7.0', '^8.0']
exclude:
- php: '8.2'
symfony: '^8.0'
- php: '8.3'
symfony: '^8.0'

name: PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}

Expand Down Expand Up @@ -55,5 +60,5 @@ jobs:
COMPOSER_PROCESS_TIMEOUT: 900
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
ALGOLIA_PREFIX: sf_phpunit_${{ matrix.php }}_
ALGOLIA_PREFIX: sf_phpunit_${{ matrix.php }}_${{ matrix.symfony }}_
run: composer test:unit
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</h4>

<p align="center">
<a href="https://circleci.com/gh/algolia/search-bundle"><img src="https://circleci.com/gh/algolia/search-bundle.svg?style=shield" alt="CircleCI" /></a>
<a href="https://github.com/algolia/search-bundle/actions/workflows/ci.yml"><img src="https://github.com/algolia/search-bundle/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
<a href="https://packagist.org/packages/algolia/search-bundle"><img src="https://poser.pugx.org/algolia/search-bundle/downloads" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/algolia/search-bundle"><img src="https://poser.pugx.org/algolia/search-bundle/v/stable" alt="Latest Version"></a>
<a href="https://packagist.org/packages/algolia/search-bundle"><img src="https://poser.pugx.org/algolia/search-bundle/license" alt="License"></a>
Expand All @@ -31,11 +31,11 @@
## ✨ Features

* **Simple**: You can get started with only 5 lines of YAML
* **Robust**: It benefits from all the new features of our PHP Client v2, like the [`wait()`](/doc/api-reference/api-methods/wait-task/) method
* **Robust**: It benefits from all the features of our PHP Client v3, like the [`wait()`](/doc/api-reference/api-methods/wait-task/) method
* **Flexible**: All methods take optional `$requestOptions` to let you handle your data as you wish
* **Dev-friendly**: Auto-completion and type-hinting thanks to an exhaustive documentation

Algolia SearchBundle supports PHP > 7.1
Algolia SearchBundle requires PHP >= 8.2 and supports Symfony 7 and 8.

## 💡 Getting Started

Expand Down Expand Up @@ -103,9 +103,7 @@ to get matching results and then will create a doctrine collection. The data are
pulled from the database (that's why you need to pass the Doctrine Manager).

```php
$em = $this->getDoctrine()->getManagerForClass(Post::class);

$posts = $this->searchService->search($em, Post::class, 'query');
$posts = $this->searchService->search($entityManager, Post::class, 'query');
```

For full documentation, visit the **[Algolia Symfony Search Bundle](https://www.algolia.com/doc/framework-integration/symfony/getting-started/)**.
Expand All @@ -120,4 +118,4 @@ If you want to contribute to this project without installing all its dependencie

## 📄 License

Algolia Symfony Search Bundle is an open-sourced software licensed under the [MIT license](LICENSE.md).
Algolia Symfony Search Bundle is an open-sourced software licensed under the [MIT license](LICENSE).
22 changes: 10 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "algolia/search-bundle",
"description": "Algolia Search integration for Symfony",
"type": "symfony-bundle",
"license": "MIT",
"authors": [
Expand All @@ -13,11 +14,10 @@
"php": ">= 8.2",
"algolia/algoliasearch-client-php": "^3.0",
"doctrine/event-manager": "^1.1 || ^2.0",
"doctrine/persistence": "^2.1 || ^3.0",
"symfony/filesystem": "^7.0",
"symfony/http-kernel": "^7.0",
"symfony/property-access": "^7.0",
"symfony/serializer": "^7.0"
"doctrine/persistence": "^2.1 || ^3.0 || ^4.0",
"symfony/filesystem": "^7.0 || ^8.0",
"symfony/property-access": "^7.0 || ^8.0",
"symfony/serializer": "^7.0 || ^8.0"
},
"autoload": {
"psr-4": {
Expand All @@ -34,17 +34,15 @@
},
"require-dev": {
"ext-json": "*",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^2.12 || ^3.0",
"doctrine/orm": "^2.5 || ^3.0",
"friendsofphp/php-cs-fixer": "^v3.54.0",
"jms/serializer-bundle": "^5.4.0",
"friendsofphp/proxy-manager-lts": "*",
"phpunit/phpunit": "^8.5 || ^9.0",
"roave/security-advisories": "dev-master",
"symfony/framework-bundle": "^7.0",
"symfony/phpunit-bridge": "^7.0",
"symfony/proxy-manager-bridge": "*",
"symfony/yaml": "^7.0"
"symfony/framework-bundle": "^7.0 || ^8.0",
"symfony/phpunit-bridge": "^7.0 || ^8.0",
"symfony/yaml": "^7.0 || ^8.0"
},
"extra": {
"branch-alias": {
Expand Down
5 changes: 1 addition & 4 deletions src/Command/SearchClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
#[AsCommand(name: 'search:clear')]
final class SearchClearCommand extends IndexCommand
{
/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Clear index (remove all data but keep index and settings)')
Expand Down
5 changes: 1 addition & 4 deletions src/Command/SearchImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public function __construct(
$this->searchClient = $searchClient;
}

/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Import given entity into search engine')
Expand Down
5 changes: 1 addition & 4 deletions src/Command/SearchSettingsBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
#[AsCommand(name: 'search:settings:backup')]
final class SearchSettingsBackupCommand extends SearchSettingsCommand
{
/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Backup search engine settings into your project')
Expand Down
5 changes: 1 addition & 4 deletions src/Command/SearchSettingsPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
#[AsCommand(name: 'search:settings:push')]
final class SearchSettingsPushCommand extends SearchSettingsCommand
{
/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Push settings from your project to the search engine')
Expand Down
10 changes: 4 additions & 6 deletions src/DependencyInjection/AlgoliaSearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

/**
Expand All @@ -23,14 +23,12 @@
final class AlgoliaSearchExtension extends Extension
{
/**
* @return void
*
* @throws \InvalidArgumentException|\Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand Down
48 changes: 0 additions & 48 deletions src/Resources/config/services.xml

This file was deleted.

47 changes: 47 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
services:
Algolia\SearchBundle\Command\:
resource: '../../Command'
autowire: true
autoconfigure: true

Algolia\SearchBundle\Command\SearchImportCommand:
autowire: true
autoconfigure: true
arguments:
$searchServiceForAtomicReindex: '@search.service_for_atomic_reindex'

search.search_indexer_subscriber:
class: Algolia\SearchBundle\EventListener\SearchIndexerSubscriber
public: true
arguments:
- '@search.service'
- [] # doctrine subscribed events
tags:
- { name: doctrine.event_listener, event: postPersist, connection: default }
- { name: doctrine.event_listener, event: postUpdate, connection: default }
- { name: doctrine.event_listener, event: preRemove, connection: default }
- { name: doctrine_mongodb.odm.event_subscriber }

search.client:
class: Algolia\AlgoliaSearch\SearchClient
public: true
lazy: true
factory: ['Algolia\AlgoliaSearch\SearchClient', 'create']
arguments:
$appId: '%env(ALGOLIA_APP_ID)%'
$apiKey: '%env(ALGOLIA_API_KEY)%'

Algolia\AlgoliaSearch\SearchClient:
alias: search.client

Algolia\SearchBundle\SearchService:
alias: search.service

Algolia\SearchBundle\Settings\SettingsManager:
alias: search.settings_manager

custom_normalizer:
class: Symfony\Component\Serializer\Normalizer\CustomNormalizer
public: false
tags:
- { name: serializer.normalizer, priority: -800 }
2 changes: 1 addition & 1 deletion tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/config/config.yml');

$loader->load(__DIR__ . '/../src/Resources/config/services.xml');
$loader->load(__DIR__ . '/../src/Resources/config/services.yaml');

$loader->load(__DIR__ . '/config/algolia_search.yml');

Expand Down
2 changes: 1 addition & 1 deletion tests/TestApp/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Attribute\Groups;

#[ORM\Entity]
#[ORM\Table('posts')]
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/AggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function testAggregatorProxyClass(): void
]);
$this->entityManager->persist($post);
$this->entityManager->flush();
$this->entityManager->clear();

$postMetadata = $this->entityManager->getClassMetadata(Post::class);
$this->entityManager->getProxyFactory()->generateProxyClasses([$postMetadata], null);
Expand Down
12 changes: 3 additions & 9 deletions tests/TestCase/ClientProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Algolia\SearchBundle\TestCase;

use Algolia\AlgoliaSearch\SearchClient;
use Algolia\SearchBundle\BaseTest;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
use Symfony\Component\VarExporter\LazyObjectInterface;

class ClientProxyTest extends BaseTest
{
Expand Down Expand Up @@ -39,17 +39,11 @@ public static function tearDownAfterClass(): void
$_SERVER = self::$values['_server'];
}

public function testClientIsProxied(): void
public function testClientIsResolvable(): void
{
$client = $this->get('search.client');

if (PHP_VERSION_ID >= 80400) {
$reflector = new \ReflectionClass($client);
self::assertTrue($reflector->isUninitializedLazyObject($client));
} else {
$interfaces = class_implements($client);
self::assertContains(LazyObjectInterface::class, $interfaces);
}
self::assertInstanceOf(SearchClient::class, $client);
}

public function testProxiedClientFailIfNoEnvVarsFound(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testSearchImportAggregator(): void
$searchPost = $this->searchService->rawSearch(ContentAggregator::class);
self::assertCount($expectedResult, $searchPost['hits']);
// clearup table
$this->connection->executeUpdate($this->platform->getTruncateTableSQL($this->indexName, true));
$this->connection->executeStatement($this->platform->getTruncateTableSQL($this->indexName, true));
$this->cleanUp();
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public function testSearchImport($isAtomic): void

self::assertCount($expectedResult, $searchPost['hits']);
// clearup table
$this->connection->executeUpdate($this->platform->getTruncateTableSQL($this->indexName, true));
$this->connection->executeStatement($this->platform->getTruncateTableSQL($this->indexName, true));
$this->cleanUp();
}

Expand Down
12 changes: 2 additions & 10 deletions tests/TestCase/EntityProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public function testEntityIsNotProxied(): void
self::assertEquals('Algolia\\SearchBundle\\TestApp\\Entity\\Comment', ClassInfo::getClass($comment));
}

public function testEntityIsProxiedWithOPM(): void
{
$factory = new \ProxyManager\Factory\NullObjectFactory();
$proxy = $factory->createProxy(Comment::class);

self::assertStringStartsWith('ProxyManagerGeneratedProxy\\__PM__\\Algolia\\SearchBundle\\TestApp\\Entity\\Comment', get_class($proxy));
self::assertEquals('Algolia\\SearchBundle\\TestApp\\Entity\\Comment', ClassInfo::getClass($proxy));
}

public function testEntityIsProxiedWithDP(): void
{
/** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
Expand All @@ -77,7 +68,8 @@ public function testEntityIsProxiedWithDP(): void

$proxy = $entityManager->getProxyFactory()->getProxy($metadata->getName(), ['id' => 1]);

self::assertStringStartsWith('Proxies\\__CG__\Algolia\\SearchBundle\\TestApp\\Entity\\Comment', get_class($proxy));
// ORM 3 uses lazy ghost objects instead of __CG__ proxies
// The proxy is the same class, but ClassInfo should still resolve correctly
self::assertEquals('Algolia\\SearchBundle\\TestApp\\Entity\\Comment', ClassInfo::getClass($proxy));
}
}
1 change: 0 additions & 1 deletion tests/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ doctrine:
url: sqlite:///%kernel.project_dir%/tests/cache/blog.sqlite
logging: false
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
Expand Down
Loading