Skip to content

Commit

Permalink
Merge pull request #43 from Setono/rename-facet-form-builders
Browse files Browse the repository at this point in the history
Rename facet form builders to filter form builders because people use the word 'filters' more
  • Loading branch information
loevgaard authored Dec 7, 2024
2 parents 9499590 + 7ae6886 commit 55851db
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/Document/Attribute/Facetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Setono\SyliusMeilisearchPlugin\Document\Attribute;

use Attribute;
use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FacetValuesSorterInterface;
use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FilterValuesSorterInterface;
use Webmozart\Assert\Assert;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)]
Expand All @@ -14,14 +14,14 @@ final class Facetable extends Filterable
/**
* TODO: Should be a service id
*
* @param class-string<FacetValuesSorterInterface>|null $sorter
* @param class-string<FilterValuesSorterInterface>|null $sorter
*/
public function __construct(public readonly ?string $sorter = null)
{
if ($this->sorter === null) {
return;
}

Assert::true(is_a($sorter, FacetValuesSorterInterface::class, true));
Assert::true(is_a($sorter, FilterValuesSorterInterface::class, true));
}
}
4 changes: 2 additions & 2 deletions src/Document/Metadata/Facet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Setono\SyliusMeilisearchPlugin\Document\Metadata;

use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FacetValuesSorterInterface;
use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FilterValuesSorterInterface;

final class Facet
{
/** @param class-string<FacetValuesSorterInterface>|null $sorter */
/** @param class-string<FilterValuesSorterInterface>|null $sorter */
public function __construct(
public readonly string $name,
public readonly string $type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use function Symfony\Component\String\u;

final class CheckboxFacetFormBuilder implements FacetFormBuilderInterface
final class CheckboxFilterFormBuilder implements FilterFormBuilderInterface
{
public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace Setono\SyliusMeilisearchPlugin\Form\Builder;

use Setono\SyliusMeilisearchPlugin\Document\Metadata\Facet;
use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FacetValuesSorterInterface;
use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FilterValuesSorterInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use function Symfony\Component\String\u;

final class ChoiceFacetFormBuilder implements FacetFormBuilderInterface
final class ChoiceFilterFormBuilder implements FilterFormBuilderInterface
{
public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void
{
$keys = array_keys($values);
$choices = array_combine($keys, $keys);

/** @var class-string<FacetValuesSorterInterface> $sorter */
/** @var class-string<FilterValuesSorterInterface> $sorter */
$sorter = $facet->sorter;
if ($facet->sorter !== null) {
/** @var array $choices */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Symfony\Component\Form\FormBuilderInterface;

/**
* @extends CompositeService<FacetFormBuilderInterface>
* @extends CompositeService<FilterFormBuilderInterface>
*/
final class CompositeFacetFormBuilder extends CompositeService implements FacetFormBuilderInterface
final class CompositeFilterFormBuilder extends CompositeService implements FilterFormBuilderInterface
{
public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Setono\SyliusMeilisearchPlugin\Document\Metadata\Facet;
use Symfony\Component\Form\FormBuilderInterface;

interface FacetFormBuilderInterface
interface FilterFormBuilderInterface
{
/**
* @param array<string, int> $values The values of the facet. This could be ['red' => 10, 'blue' => 5] where the key is the facet value and the value is the number of matching documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use function Symfony\Component\String\u;

final class RangeFacetFormBuilder implements FacetFormBuilderInterface
final class RangeFilterFormBuilder implements FilterFormBuilderInterface
{
public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Builder/SearchFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class SearchFormBuilder implements SearchFormBuilderInterface
{
public function __construct(
private readonly FormFactoryInterface $formFactory,
private readonly FacetFormBuilderInterface $facetFormBuilder,
private readonly FilterFormBuilderInterface $filterFormBuilder,
private readonly SortingFormBuilderInterface $sortingFormBuilder,
private readonly MetadataFactoryInterface $metadataFactory,
private readonly Index $index,
Expand Down Expand Up @@ -113,8 +113,8 @@ public function build(SearchResult $searchResult): FormInterface
continue;
}

if ($this->facetFormBuilder->supports($facets[$name], $values, $facetStats[$name] ?? null)) {
$this->facetFormBuilder->build($facetsFormBuilder, $facets[$name], $values, $facetStats[$name] ?? null);
if ($this->filterFormBuilder->supports($facets[$name], $values, $facetStats[$name] ?? null)) {
$this->filterFormBuilder->build($facetsFormBuilder, $facets[$name], $values, $facetStats[$name] ?? null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter;

interface FacetValuesSorterInterface
interface FilterValuesSorterInterface
{
public function sort(array $values): array;
}
2 changes: 1 addition & 1 deletion src/Form/Builder/Sorter/SizeSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use DragonCode\SizeSorter\Sorter;

final class SizeSorter implements FacetValuesSorterInterface
final class SizeSorter implements FilterValuesSorterInterface
{
public function sort(array $values): array
{
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
</parameters>
<services>
<!-- Facet form builders -->
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\FacetFormBuilderInterface"
alias="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFacetFormBuilder"/>
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\FilterFormBuilderInterface"
alias="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFilterFormBuilder"/>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFacetFormBuilder"/>
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFilterFormBuilder"/>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CheckboxFacetFormBuilder">
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CheckboxFilterFormBuilder">
<tag name="setono_sylius_meilisearch.facet_form_builder" priority="100"/>
</service>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\ChoiceFacetFormBuilder">
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\ChoiceFilterFormBuilder">
<tag name="setono_sylius_meilisearch.facet_form_builder" priority="90"/>
</service>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\RangeFacetFormBuilder">
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\RangeFilterFormBuilder">
<tag name="setono_sylius_meilisearch.facet_form_builder" priority="80"/>
</service>

Expand All @@ -37,7 +37,7 @@

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\SearchFormBuilder">
<argument type="service" id="form.factory"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Form\Builder\FacetFormBuilderInterface"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Form\Builder\FilterFormBuilderInterface"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Form\Builder\SortingFormBuilderInterface"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Document\Metadata\MetadataFactoryInterface"/>
<argument type="service" id="setono_sylius_meilisearch.index.search"/>
Expand Down
4 changes: 2 additions & 2 deletions src/SetonoSyliusMeilisearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Setono\CompositeCompilerPass\CompositeCompilerPass;
use Setono\SyliusMeilisearchPlugin\DataMapper\CompositeDataMapper;
use Setono\SyliusMeilisearchPlugin\Filter\Entity\CompositeEntityFilter;
use Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFacetFormBuilder;
use Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFilterFormBuilder;
use Setono\SyliusMeilisearchPlugin\Meilisearch\Filter\CompositeFilterBuilder;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\CompositeIndexScopeProvider;
use Setono\SyliusMeilisearchPlugin\Provider\Settings\CompositeSettingsProvider;
Expand All @@ -33,7 +33,7 @@ public function build(ContainerBuilder $container): void

// Register services in composite services
$container->addCompilerPass(new CompositeCompilerPass(
CompositeFacetFormBuilder::class,
CompositeFilterFormBuilder::class,
'setono_sylius_meilisearch.facet_form_builder',
));

Expand Down

0 comments on commit 55851db

Please sign in to comment.