Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bf89b962ec | |||
| 7de30e78ac | |||
| 6d65df0b9c | |||
| 5d56d98325 | |||
| 2f6597a957 | |||
| 93bb85f69f | |||
| 218b174d4f | |||
| 2258fa0c96 | |||
| 34b0e7f146 | |||
| ab25540462 | |||
| da950685c0 | |||
| 954e6aa712 | |||
| 3f410b8f55 | |||
| 78f356f030 | |||
| c35da20deb | |||
| 066e3f0d4b | |||
| cf03ff8f89 | |||
| c46af9c4f7 | |||
| 7e3b74af08 | |||
| d4dc1b57c8 |
14
.editorconfig
Normal file
14
.editorconfig
Normal file
@@ -0,0 +1,14 @@
|
||||
# This is the top-most .editorconfig file; do not search in parent directories.
|
||||
root = true
|
||||
|
||||
# All files.
|
||||
[*]
|
||||
end_of_line = LF
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/vendor
|
||||
composer.lock
|
||||
.phpunit.result.cache
|
||||
|
||||
@@ -9,11 +9,21 @@
|
||||
"doctrine/orm": "^2.12",
|
||||
"symfony/framework-bundle": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"vimeo/psalm": "^4.24",
|
||||
"psalm/plugin-symfony": "^3.1",
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Pcm\\SearchBundle\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Pcm\\SearchBundle\\": "tests/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Matt Feeny",
|
||||
@@ -23,9 +33,5 @@
|
||||
"name": "Bradley Goode",
|
||||
"email": "bg@pcmsystems.co.uk"
|
||||
}
|
||||
],
|
||||
"require-dev": {
|
||||
"vimeo/psalm": "^4.24",
|
||||
"psalm/plugin-symfony": "^3.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
9
config/services.yaml
Normal file
9
config/services.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
pcm_search.searchable_subscriber:
|
||||
class: Pcm\SearchBundle\EventSubscriber\SearchableSubscriber
|
||||
tags:
|
||||
- { name: doctrine.event_subscriber }
|
||||
|
||||
pcm_search.search_service:
|
||||
class: Pcm\SearchBundle\Service\SearchService
|
||||
public: true
|
||||
13
phpunit.xml
Normal file
13
phpunit.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit colors="true" bootstrap="vendor/autoload.php">
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix="Test.php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
22
src/DependencyInjection/PcmSearchExtension.php
Normal file
22
src/DependencyInjection/PcmSearchExtension.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pcm\SearchBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
class PcmSearchExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader(
|
||||
$container,
|
||||
new FileLocator(__DIR__.'/../../config')
|
||||
);
|
||||
$loader->load('services.yaml');
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ namespace Pcm\SearchBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class SearchBundle extends Bundle
|
||||
class PcmSearchBundle extends Bundle
|
||||
{
|
||||
public function getPath(): string
|
||||
{
|
||||
|
||||
@@ -14,7 +14,14 @@ class SearchService
|
||||
{
|
||||
public function __construct(private EntityManagerInterface $em) {}
|
||||
|
||||
public function index($entity)
|
||||
/**
|
||||
* Given an $entity that implements SearchableInterface, this method
|
||||
* creates or updates a SearchIndex $entity
|
||||
*
|
||||
* @param SearchableInterface $entity
|
||||
* @return void
|
||||
*/
|
||||
public function index(SearchableInterface $entity)
|
||||
{
|
||||
$searchIndex = $this->createSearchResult($entity);
|
||||
|
||||
@@ -22,7 +29,14 @@ class SearchService
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
public function unIndex($entity)
|
||||
/**
|
||||
* Given an $entity that implements SearchableInterface, this method removes
|
||||
* the item from the search index
|
||||
*
|
||||
* @param SearchableInterface $entity
|
||||
* @return void
|
||||
*/
|
||||
public function unIndex(SearchableInterface $entity)
|
||||
{
|
||||
$class = get_class($entity);
|
||||
|
||||
@@ -37,6 +51,14 @@ class SearchService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an entity that implements SearchableInterface, this method first checks
|
||||
* if the relevant SearchIndex entity exists. If it doesn't, it's created. The
|
||||
* title and index data are set based on the methods in the $entity
|
||||
*
|
||||
* @param SearchableInterface $entity
|
||||
* @return SearchIndex
|
||||
*/
|
||||
public function createSearchResult(SearchableInterface $entity): SearchIndex
|
||||
{
|
||||
$values = [];
|
||||
@@ -76,7 +98,8 @@ class SearchService
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all searchable Doctrine entities.
|
||||
* Finds all searchable Doctrine entities the implement SearchableInterface
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchableClasses(): array
|
||||
{
|
||||
|
||||
0
tests/.gitkeep
Normal file
0
tests/.gitkeep
Normal file
Reference in New Issue
Block a user