Skip to content

Commit

Permalink
Merge pull request #91 from PUGX/sf7
Browse files Browse the repository at this point in the history
allow Symfony 7
  • Loading branch information
garak authored Jul 30, 2024
2 parents e78d148 + 73b479d commit 6388237
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 83 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ on:

jobs:
tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
include:
- description: 'Symfony 4.4'
php: '7.3'
composer_option: '--prefer-lowest'
- description: 'Symfony 5.4'
php: '7.4'
symfony: 5.4.*
- description: 'Symfony 6.0'
php: '8.0'
symfony: 6.0.*
php: '8.1'
composer_option: '--prefer-lowest'
- description: 'Symfony 6.4'
php: '8.2'
symfony: 6.4.*
- description: 'Symfony 7.1'
php: '8.3'
symfony: 7.1.*
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: ${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }}
Expand Down
10 changes: 4 additions & 6 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
->in([__DIR__.'/src', __DIR__.'/tests'])
;

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
'@PHP81Migration' => true,
'@PHPUnit84Migration:risky' => true,
'declare_strict_types' => false,
'native_function_invocation' => true,
'native_function_invocation' => ['include' => ['@all']],
'php_unit_mock_short_will_return' => true,
])
->setFinder($finder)
Expand Down
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PUGXAutocompleterBundle
=======================
# PUGXAutocompleterBundle

This bundle has a simple, specific purpose: adding an "autocomplete" (also known as "type-ahead")
field.
Expand All @@ -9,29 +8,23 @@ classic select is not suitable. Here comes this bundle.

![Build Status](https://github.com/PUGX/PUGXAutoCompleterBundle/workflows/build/badge.svg)

Documentation
-------------
## Documentation

[Read the documentation](https://github.com/PUGX/PUGXAutoCompleterBundle/tree/master/docs/index.md)

Installation
------------
## Installation

All the installation instructions are located in [documentation](https://github.com/PUGX/PUGXAutoCompleterBundle/tree/master/docs/index.md).

License
-------
## License

This bundle is released under the LGPL license. See the [complete license text](https://github.com/PUGX/PUGXAutoCompleterBundle/tree/master/LICENSE).

About
-----
## About

PUGXAutocompleterBundle is a [PUGX](http://pugx.org/) initiative.


Reporting an issue or a feature request
---------------------------------------
## Reporting an issue or a feature request

Issues and feature requests are tracked in the [Github issue tracker](https://github.com/PUGX/PUGXAutocompleterBundle/issues).

Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"doctrine/persistence": "^3.0.1",
"symfony/config": "^4.4 || ^5.4 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.0",
"symfony/form": "^4.4 || ^5.4 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.0"
"php": "^8.1",
"doctrine/persistence": "^3.3",
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0",
"symfony/form": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"lexik/form-filter-bundle": "^6.0 || ^7.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.6",
"spiriitlabs/form-filter-bundle": "^11.0"
},
"suggest": {
"lexik/form-filter-bundle" : "To use autocomplete on a filter."
"spiriitlabs/form-filter-bundle" : "To use autocomplete on a filter."
},
"autoload": {
"psr-4": { "PUGX\\AutocompleterBundle\\": "src" }
Expand Down
3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PUGXAutocompleterBundle Documentation
=====================================
# PUGXAutocompleterBundle Documentation

## 1. Installation

Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/PUGXAutocompleterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
final class PUGXAutocompleterExtension extends ConfigurableExtension
{
/**
* @param array<string, mixed> $configs
* @param array<string, mixed> $mergedConfig
*
* @throws \Exception
*/
public function loadInternal(array $configs, ContainerBuilder $container): void
public function loadInternal(array $mergedConfig, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.xml');
Expand Down
32 changes: 10 additions & 22 deletions src/Form/Transformer/ObjectToIdTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,40 @@

class ObjectToIdTransformer implements DataTransformerInterface
{
/**
* @var ManagerRegistry
*/
private $registry;

/**
* @var string
*/
private $class;

public function __construct(ManagerRegistry $registry, string $class)
public function __construct(private ManagerRegistry $registry, private string $class)
{
$this->registry = $registry;
$this->class = $class;
}

/**
* Transforms an object (object) to a string (id).
*
* @param object|null $object
* @param object|null $value
*/
public function transform($object): string
public function transform($value): string
{
if (null === $object) {
if (null === $value) {
return '';
}

return $object->getId();
return $value->getId();
}

/**
* Transforms a string (id) to an object (object).
*
* @param string|int|null $id
* @param string|int|null $value
*
* @throws TransformationFailedException if object (object) is not found
*/
public function reverseTransform($id): ?object
public function reverseTransform($value): ?object
{
if (empty($id)) {
if (empty($value)) {
return null;
}
$object = $this->registry->getManagerForClass($this->class)->getRepository($this->class)->find($id);
$object = $this->registry->getManagerForClass($this->class)->getRepository($this->class)->find($value);
if (null === $object) {
$msg = 'Object from class %s with id "%s" not found';
throw new TransformationFailedException(\sprintf($msg, $this->class, $id));
throw new TransformationFailedException(\sprintf($msg, $this->class, $value));
}

return $object;
Expand Down
8 changes: 1 addition & 7 deletions src/Form/Type/AutocompleteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@

class AutocompleteType extends AbstractType
{
/**
* @var ManagerRegistry
*/
private $registry;

public function __construct(ManagerRegistry $registry)
public function __construct(private ManagerRegistry $registry)
{
$this->registry = $registry;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Listener/FilterSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace PUGX\AutocompleterBundle\Listener;

use Lexik\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
use Spiriit\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* See https://github.com/lexik/LexikFormFilterBundle for this custom filter.
* See https://github.com/SpiriitLabs/form-filter-bundle for this custom filter.
*/
final class FilterSubscriber implements EventSubscriberInterface
{
Expand All @@ -26,12 +26,12 @@ public static function getSubscribedEvents(): array
}

/**
* Apply a filter for a filter_autcomplete type.
* Apply a filter for a filter_autocomplete type.
* This method should work with both ORM and DBAL query builder.
*/
public function filterAutocomplete(GetFilterConditionEvent $event): void
{
/** @var \Lexik\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery|\Lexik\Bundle\FormFilterBundle\Filter\Doctrine\DBALQuery $query */
/** @var \Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery|\Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\DBALQuery $query */
$query = $event->getFilterQuery();
$expr = $query->getExpr();
$values = $event->getValues();
Expand Down
1 change: 0 additions & 1 deletion src/Resources

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Listener/FilterSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace PUGX\AutocompleterBundle\Tests\Listener;

use Doctrine\ORM\Query\Expr;
use Lexik\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
use Lexik\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery;
use PHPUnit\Framework\TestCase;
use PUGX\AutocompleterBundle\Listener\FilterSubscriber;
use Spiriit\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
use Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery;

final class FilterSubscriberTest extends TestCase
{
Expand Down

0 comments on commit 6388237

Please sign in to comment.