Skip to content

Commit

Permalink
Merge 026a7ac into 65b6ead
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 22, 2020
2 parents 65b6ead + 026a7ac commit b52680d
Show file tree
Hide file tree
Showing 36 changed files with 147 additions and 449 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -35,6 +35,8 @@ matrix:
env: SYMFONY=4.4.*
- php: '7.3'
env: SYMFONY='dev-master as 4.4.x-dev'
- php: '7.3'
env: SONATA_ADMIN=dev-master
- php: '7.3'
env: SYMFONY_DEPRECATIONS_HELPER=0
allow_failures:
Expand Down
14 changes: 13 additions & 1 deletion UPGRADE-4.0.md
@@ -1,2 +1,14 @@
UPGRADE FROM 3.X to 3.0
UPGRADE FROM 3.X to 4.0
=======================

## Deprecations

All the deprecated code introduced on 3.x is removed on 4.0.

Please read [3.x](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/tree/3.x) upgrade guides for more information.

See also the [diff code](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.x...4.0.0).

## Dropped

- Support for `sonata-project/block-bundle` 3.
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -23,11 +23,11 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.3",
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/orm": "^2.5",
"doctrine/persistence": "^1.3.4",
"sonata-project/admin-bundle": "^3.71",
"sonata-project/admin-bundle": "dev-master",
"sonata-project/exporter": "^1.11.0 || ^2.0",
"sonata-project/form-extensions": "^0.1 || ^1.4",
"symfony/config": "^4.4",
Expand All @@ -53,7 +53,7 @@
},
"require-dev": {
"simplethings/entity-audit-bundle": "^0.9 || ^1.0",
"sonata-project/block-bundle": "^3.17 || ^4.0",
"sonata-project/block-bundle": "^4.2",
"symfony/phpunit-bridge": "^5.0"
},
"suggest": {
Expand Down
16 changes: 4 additions & 12 deletions src/Admin/FieldDescription.php
Expand Up @@ -22,12 +22,8 @@ public function __construct()
$this->parentAssociationMappings = [];
}

public function setAssociationMapping($associationMapping): void
public function setAssociationMapping(array $associationMapping): void
{
if (!\is_array($associationMapping)) {
throw new \RuntimeException('The association mapping must be an array');
}

$this->associationMapping = $associationMapping;

$this->type = $this->type ?: $associationMapping['type'];
Expand All @@ -40,7 +36,7 @@ public function setAssociationMapping($associationMapping): void
*
* @deprecated since sonata-project/doctrine-orm-admin-bundle 3.20 and will be removed in version 4.0. Use FieldDescription::getTargetModel() instead.
*/
public function getTargetEntity()
public function getTargetEntity(): ?string
{
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.20 and will be removed in version 4.0.'
Expand All @@ -64,12 +60,8 @@ public function getTargetModel(): ?string
return null;
}

public function setFieldMapping($fieldMapping): void
public function setFieldMapping(array $fieldMapping): void
{
if (!\is_array($fieldMapping)) {
throw new \RuntimeException('The field mapping must be an array');
}

$this->fieldMapping = $fieldMapping;

$this->type = $this->type ?: $fieldMapping['type'];
Expand All @@ -88,7 +80,7 @@ public function setParentAssociationMappings(array $parentAssociationMappings):
$this->parentAssociationMappings = $parentAssociationMappings;
}

public function isIdentifier()
public function isIdentifier(): bool
{
return isset($this->fieldMapping['id']) ? $this->fieldMapping['id'] : false;
}
Expand Down
70 changes: 3 additions & 67 deletions src/Block/AuditBlockService.php
Expand Up @@ -14,11 +14,8 @@
namespace Sonata\DoctrineORMAdminBundle\Block;

use SimpleThings\EntityAudit\AuditReader;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;
Expand All @@ -35,63 +32,11 @@ class AuditBlockService extends AbstractBlockService
*/
protected $auditReader;

/**
* NEXT_MAJOR: Allow only Environment|EngineInterface for argument 1 and AuditReader for argument 2.
*
* @param Environment|EngineInterface|string $templatingOrDeprecatedName
* @param EngineInterface|AuditReader $templatingOrAuditReader
*/
public function __construct($templatingOrDeprecatedName, object $templatingOrAuditReader, ?AuditReader $auditReader = null)
public function __construct(Environment $twig, AuditReader $auditReader)
{
if ($templatingOrAuditReader instanceof EngineInterface) {
@trigger_error(sprintf(
'Passing %s as argument 2 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.21'
.' and will throw a \TypeError in version 4.0. You must pass an instance of %s instead.',
EngineInterface::class,
__METHOD__,
AuditReader::class
), E_USER_DEPRECATED);

if (null === $auditReader) {
throw new \TypeError(sprintf(
'Passing null as argument 3 to %s() is not allowed when %s is passed as argument 2.'
.' You must pass an instance of %s instead.',
__METHOD__,
EngineInterface::class,
AuditReader::class
));
}

parent::__construct($templatingOrDeprecatedName, $templatingOrAuditReader);
parent::__construct($twig);

$this->auditReader = $auditReader;
} elseif ($templatingOrAuditReader instanceof AuditReader) {
if (!$templatingOrDeprecatedName instanceof Environment
&& !$templatingOrDeprecatedName instanceof EngineInterface
) {
throw new \TypeError(sprintf(
'Argument 1 passed to %s() must be either an instance of %s or preferably %s, %s given.',
__METHOD__,
EngineInterface::class,
Environment::class,
\is_object($templatingOrDeprecatedName)
? 'instance of '.\get_class($templatingOrDeprecatedName)
: \gettype($templatingOrDeprecatedName)
));
}

parent::__construct($templatingOrDeprecatedName);

$this->auditReader = $templatingOrAuditReader;
} else {
throw new \TypeError(sprintf(
'Argument 2 passed to %s() must be either an instance of %s or preferably %s, instance of %s given.',
__METHOD__,
EngineInterface::class,
AuditReader::class,
\get_class($templatingOrAuditReader)
));
}
$this->auditReader = $auditReader;
}

public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
Expand All @@ -112,15 +57,6 @@ public function execute(BlockContextInterface $blockContext, ?Response $response
], $response);
}

public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void
{
}

public function getName()
{
return 'Audit List';
}

public function configureSettings(OptionsResolver $resolver): void
{
$resolver->setDefaults([
Expand Down
15 changes: 4 additions & 11 deletions src/Builder/DatagridBuilder.php
Expand Up @@ -50,14 +50,11 @@ class DatagridBuilder implements DatagridBuilderInterface
*/
protected $csrfTokenEnabled;

/**
* @param bool $csrfTokenEnabled
*/
public function __construct(
FormFactoryInterface $formFactory,
FilterFactoryInterface $filterFactory,
TypeGuesserInterface $guesser,
$csrfTokenEnabled = true
bool $csrfTokenEnabled = true
) {
$this->formFactory = $formFactory;
$this->filterFactory = $filterFactory;
Expand Down Expand Up @@ -129,7 +126,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
}
}

public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
public function addFilter(DatagridInterface $datagrid, ?string $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
{
if (null === $type) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
Expand Down Expand Up @@ -174,7 +171,7 @@ public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionIn
$datagrid->addFilter($filter);
}

public function getBaseDatagrid(AdminInterface $admin, array $values = [])
public function getBaseDatagrid(AdminInterface $admin, array $values = []): DatagridInterface
{
$pager = $this->getPager($admin->getPagerType());

Expand All @@ -193,13 +190,9 @@ public function getBaseDatagrid(AdminInterface $admin, array $values = [])
/**
* Get pager by pagerType.
*
* @param string $pagerType
*
* @throws \RuntimeException If invalid pager type is set
*
* @return PagerInterface
*/
protected function getPager($pagerType)
protected function getPager(string $pagerType): PagerInterface
{
switch ($pagerType) {
case Pager::TYPE_DEFAULT:
Expand Down
10 changes: 4 additions & 6 deletions src/Builder/FormContractor.php
Expand Up @@ -25,6 +25,7 @@
use Sonata\AdminBundle\Form\Type\ModelTypeList;
use Sonata\Form\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormFactoryInterface;

class FormContractor implements FormContractorInterface
Expand Down Expand Up @@ -80,20 +81,17 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
}
}

/**
* @return FormFactoryInterface
*/
public function getFormFactory()
public function getFormFactory(): FormFactoryInterface
{
return $this->formFactory;
}

public function getFormBuilder($name, array $options = [])
public function getFormBuilder(string $name, array $options = []): FormBuilderInterface
{
return $this->getFormFactory()->createNamedBuilder($name, FormType::class, null, $options);
}

public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
public function getDefaultOptions(?string $type, FieldDescriptionInterface $fieldDescription): array
{
$options = [];
$options['sonata_field_description'] = $fieldDescription;
Expand Down
11 changes: 4 additions & 7 deletions src/Builder/ListBuilder.php
Expand Up @@ -42,12 +42,12 @@ public function __construct(TypeGuesserInterface $guesser, array $templates = []
$this->templates = $templates;
}

public function getBaseList(array $options = [])
public function getBaseList(array $options = []): FieldDescriptionCollection
{
return new FieldDescriptionCollection();
}

public function buildField($type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
public function buildField(?string $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
{
if (null === $type) {
$guessType = $this->guesser->guessType(
Expand All @@ -63,7 +63,7 @@ public function buildField($type, FieldDescriptionInterface $fieldDescription, A
$this->fixFieldDescription($admin, $fieldDescription);
}

public function addField(FieldDescriptionCollection $list, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
public function addField(FieldDescriptionCollection $list, ?string $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
{
$this->buildField($type, $fieldDescription, $admin);
$admin->addListFieldDescription($fieldDescription->getName(), $fieldDescription);
Expand Down Expand Up @@ -155,10 +155,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
}
}

/**
* @return FieldDescriptionInterface
*/
public function buildActionFieldDescription(FieldDescriptionInterface $fieldDescription)
public function buildActionFieldDescription(FieldDescriptionInterface $fieldDescription): FieldDescriptionInterface
{
if (null === $fieldDescription->getTemplate()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/list__action.html.twig');
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/ShowBuilder.php
Expand Up @@ -42,12 +42,12 @@ public function __construct(TypeGuesserInterface $guesser, array $templates)
$this->templates = $templates;
}

public function getBaseList(array $options = [])
public function getBaseList(array $options = []): FieldDescriptionCollection
{
return new FieldDescriptionCollection();
}

public function addField(FieldDescriptionCollection $list, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
public function addField(FieldDescriptionCollection $list, ?string $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin): void
{
if (null === $type) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
Expand Down
9 changes: 2 additions & 7 deletions src/Datagrid/Pager.php
Expand Up @@ -36,7 +36,7 @@ class Pager extends BasePager
*/
protected $queryBuilder = null;

public function computeNbResult()
public function computeNbResult(): int
{
$countQuery = clone $this->getQuery();

Expand All @@ -56,16 +56,11 @@ public function computeNbResult()
));
}

public function getResults($hydrationMode = Query::HYDRATE_OBJECT)
public function getResults($hydrationMode = Query::HYDRATE_OBJECT): array
{
return $this->getQuery()->execute([], $hydrationMode);
}

public function getQuery()
{
return $this->query;
}

public function init(): void
{
$this->resetIterator();
Expand Down

0 comments on commit b52680d

Please sign in to comment.