Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 4 compatibility #3

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
483702e
tests gh action
prgTW Feb 14, 2024
30a7b86
no fail-fast
prgTW Feb 14, 2024
2292c80
compat
prgTW Feb 14, 2024
4cad413
phpunit
prgTW Feb 14, 2024
9e57156
less tests
prgTW Feb 14, 2024
950a54a
propel
prgTW Feb 14, 2024
db32acc
cs fixer removed
prgTW Feb 14, 2024
24728e7
phpunit compat
prgTW Feb 14, 2024
d003d09
refactor
prgTW Feb 15, 2024
6ec3af5
cannot do strict validation due to commit-ref
prgTW Feb 15, 2024
f35c37f
delete lock
prgTW Feb 15, 2024
99b4558
imitate php to 7.4
prgTW Feb 15, 2024
6147d01
if removed
prgTW Feb 15, 2024
93b92e6
PHPUnit
prgTW Feb 15, 2024
80997c5
CI status badge
prgTW Feb 15, 2024
7152af6
SYMFONY_DEPRECATIONS_HELPER
prgTW Feb 16, 2024
ae69992
phpunit colors
prgTW Feb 16, 2024
36cc176
method_exists() fix
prgTW Feb 16, 2024
f75cdf4
conflicts with doctrine/annotations:>1
prgTW Feb 16, 2024
54f3392
updated requirements
prgTW Feb 16, 2024
b035900
different matrix
prgTW Feb 16, 2024
2239da8
type guessing
prgTW Feb 16, 2024
8aa6743
allow sf4
prgTW Feb 16, 2024
e5557d0
sf 4.2 compat
prgTW Feb 16, 2024
4201830
common `var` dir
prgTW Feb 16, 2024
5baa178
sonata-project/[email protected]
prgTW Feb 16, 2024
c583b5c
don't boot kernel on disabled test
prgTW Feb 16, 2024
b428636
FQCNs
prgTW Feb 16, 2024
c648d52
Removed `at` matcher + fixes
prgTW Feb 17, 2024
f3a5d13
Symfony4-compatibility only
prgTW Feb 19, 2024
93bb70c
test matrix updated
prgTW Feb 19, 2024
61bfdf5
test matrix updated
prgTW Feb 19, 2024
9e2ef7d
test matrix updated
prgTW Feb 19, 2024
969c2d2
removing mangling with dependencies
prgTW Feb 19, 2024
16eb229
try not to fake platform
prgTW Feb 19, 2024
81f39c8
fixes
prgTW Feb 19, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches:
- master
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
tests:
strategy:
fail-fast: false
matrix:
include:
- php: 7.4
- php: 8.0
- php: 8.1
- php: 8.2
- php: 8.3
- php: 8.4

name: 'PHP ${{ matrix.php }}'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --ansi --prefer-dist --no-interaction --no-scripts

- name: PHPUnit
run: vendor/bin/phpunit --colors=always
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/build
/Resources/doc/_build
/vendor
.idea/
composer.phar
composer.lock
phpunit.xml
.php_cs.cache

.phpunit.result.cache
/var
!/var/cache/.gitignore
!/var/log/.gitignore
# propel-generated stuff
Tests/Fixtures/App/app/propel/sql/
Tests/Fixtures/App/src/Sonata/TestBundle/Model/map
Tests/Fixtures/App/src/Sonata/TestBundle/Model/om
Tests/Fixtures/App/src/Sonata/TestBundle/Model/Base
Tests/Fixtures/App/src/Sonata/TestBundle/Model/Map
19 changes: 0 additions & 19 deletions .php_cs

This file was deleted.

60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions Builder/DatagridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
use Sonata\PropelAdminBundle\Datagrid\Datagrid;
use Sonata\PropelAdminBundle\Datagrid\Pager;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormFactory;

/**
Expand Down Expand Up @@ -88,7 +89,7 @@ public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescri
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());

$type = $guessType->getType();
$type = (null === $guessType) ? null : $guessType->getType();

$fieldDescription->setType($type);

Expand Down Expand Up @@ -128,7 +129,7 @@ public function getBaseDatagrid(AdminInterface $admin, array $values = array())
$defaultOptions['csrf_protection'] = false;
}

$formBuilder = $this->formFactory->createNamedBuilder('filter', 'form', array(), $defaultOptions);
$formBuilder = $this->formFactory->createNamedBuilder('filter', FormType::class, array(), $defaultOptions);

return new Datagrid($admin->createQuery('list'), $admin->getList(), $pager, $formBuilder, $values);
}
Expand Down
15 changes: 10 additions & 5 deletions Builder/FormContractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\FormContractorInterface;
use Sonata\AdminBundle\Form\Type\AdminType;
use Sonata\AdminBundle\Form\Type\CollectionType;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\AdminBundle\Form\Type\ModelType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;

Expand Down Expand Up @@ -62,7 +67,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
*/
public function getFormBuilder($name, array $options = array())
{
return $this->formFactory->createNamedBuilder($name, 'form', null, $options);
return $this->formFactory->createNamedBuilder($name, FormType::class, null, $options);
}

/**
Expand All @@ -77,26 +82,26 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
'sonata_field_description' => $fieldDescription,
);

if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
if ($type == ModelType::class || $type == ModelListType::class) {
if ($fieldDescription->getOption('edit') == 'list') {
throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle');
}

$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
} elseif ($type == 'sonata_type_admin') {
} elseif ($type == AdminType::class) {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}

$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
} elseif ($type == 'sonata_type_collection') {
} elseif ($type == CollectionType::class) {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}

$options['type'] = 'sonata_type_admin';
$options['type'] = AdminType::class;
$options['modifiable'] = true;
$options['type_options'] = array(
'sonata_field_description' => $fieldDescription,
Expand Down
2 changes: 1 addition & 1 deletion Builder/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function buildField($type = null, FieldDescriptionInterface $fieldDescrip
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
$fieldDescription->setType((null === $guessType) ? null : $guessType->getType());
} else {
$fieldDescription->setType($type);
}
Expand Down
2 changes: 1 addition & 1 deletion Builder/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function addField(FieldDescriptionCollection $list, $type = null, FieldDe
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
$fieldDescription->setType((null === $guessType) ? null : $guessType->getType());
} else {
$fieldDescription->setType($type);
}
Expand Down
11 changes: 6 additions & 5 deletions Datagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

/**
* @author Toni Uebernickel <[email protected]>
Expand All @@ -36,20 +37,20 @@ public function buildPager()
}

foreach ($this->getFilters() as $name => $filter) {
list($type, $options) = $filter->getRenderSettings();
[$type, $options] = $filter->getRenderSettings();

$this->formBuilder->add($filter->getFormName(), $type, $options);
}

$this->formBuilder->add('_sort_by', 'hidden');
$this->formBuilder->add('_sort_by', HiddenType::class);
$this->formBuilder->get('_sort_by')->addViewTransformer(new CallbackTransformer(
function ($value) { return $value; },
function ($value) { return $value instanceof FieldDescriptionInterface ? $value->getName() : $value; }
));

$this->formBuilder->add('_sort_order', 'hidden');
$this->formBuilder->add('_page', 'hidden');
$this->formBuilder->add('_per_page', 'hidden');
$this->formBuilder->add('_sort_order', HiddenType::class);
$this->formBuilder->add('_page', HiddenType::class);
$this->formBuilder->add('_per_page', HiddenType::class);

$this->form = $this->formBuilder->getForm();
$this->form->submit($this->values);
Expand Down
2 changes: 1 addition & 1 deletion Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,6 @@ public function getQuery()

public function hasMethod($method)
{
return method_exists($this, $method) || method_exists($this->query, $method);
return method_exists($this, $method) || (null !== $this->query && method_exists($this->query, $method));
}
}
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sonata_propel_orm_admin', 'array');
$treeBuilder = new TreeBuilder('sonata_propel_orm_admin');
$rootNode = !method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->root('sonata_propel_orm_admin') : $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
33 changes: 33 additions & 0 deletions Exporter/Source/PropelCollectionSourceIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Sonata\PropelAdminBundle\Exporter\Source;

use Propel\Runtime\Collection\Collection;
use Sonata\Exporter\Source\AbstractPropertySourceIterator;

class PropelCollectionSourceIterator extends AbstractPropertySourceIterator
{
private Collection $collection;

/**
* @param array<string> $fields Fields to export
*/
public function __construct(Collection $collection, array $fields, string $dateTimeFormat = 'r')
{
$this->collection = clone $collection;

parent::__construct($fields, $dateTimeFormat);
}

public function rewind(): void
{
if (null === $this->iterator) {
$this->iterator = $this->collection->getIterator();
}

$this->iterator->rewind();
}
}

9 changes: 9 additions & 0 deletions Filter/AbstractDateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DateRangeType;
use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType;
use Sonata\AdminBundle\Form\Type\Filter\DateTimeType;
use Sonata\AdminBundle\Form\Type\Filter\DateType;

/**
Expand Down Expand Up @@ -138,6 +140,13 @@ public function getRenderSettings()
$name .= '_range';
}

$name = [
'sonata_type_filter_date' => DateType::class,
'sonata_type_filter_datetime' => DateTimeType::class,
'sonata_type_filter_date_range' => DateRangeType::class,
'sonata_type_filter_datetime_range' => DateTimeRangeType::class,
][$name];

return array($name, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
Expand Down
5 changes: 3 additions & 2 deletions Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\CoreBundle\Form\Type\BooleanType;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\Form\Type\BooleanType;

/**
* @author Kévin Gomez <[email protected]>
Expand Down Expand Up @@ -44,7 +45,7 @@ public function filter(ProxyQueryInterface $query, $alias, $field, $value)
*/
public function getRenderSettings()
{
return array('sonata_type_filter_default', array(
return array(DefaultType::class, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'label' => $this->getLabel(),
Expand Down
3 changes: 2 additions & 1 deletion Filter/CallbackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;

class CallbackFilter extends AbstractFilter
{
Expand Down Expand Up @@ -55,7 +56,7 @@ public function getDefaultOptions()
*/
public function getRenderSettings()
{
return array('sonata_type_filter_default', array(
return array(DefaultType::class, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'operator_type' => $this->getOption('operator_type'),
Expand Down
Loading