Skip to content

Commit

Permalink
Add deprecation notices
Browse files Browse the repository at this point in the history
  • Loading branch information
tambait committed Dec 5, 2020
1 parent 29bbbb0 commit 5296b8f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ UPGRADE 3.x
UPGRADE FROM 3.xx to 3.xx
=========================

### Deprecated `AdminInterface::getValidator()` and `AdminInterface::setValidator()` methods, `AbstractAdmin::$validator` property.

Methods are deprecated without replacement.

### Sonata\AdminBundle\Admin\Pool

- Passing a `Symfony\Component\PropertyAccess\PropertyAccessorInterface` instance as 4 argument instantiating
Expand Down
19 changes: 19 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A
protected $securityHandler;

/**
* NEXT_MAJOR: Remove this property.
*
* @var ValidatorInterface
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
protected $validator;

Expand Down Expand Up @@ -2849,6 +2853,11 @@ public function id($model)
return $this->getNormalizedIdentifier($model);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function setValidator($validator)
{
// NEXT_MAJOR: Move ValidatorInterface check to method signature
Expand All @@ -2862,8 +2871,18 @@ public function setValidator($validator)
$this->validator = $validator;
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getValidator()
{
@trigger_error(sprintf(
'The %s method is deprecated since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

return $this->validator;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,22 @@ public function getNormalizedIdentifier($model);
public function id($model);

/**
* NEXT_MAJOR: remove this method.
*
* @param ValidatorInterface $validator
*
* @return void
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function setValidator($validator);

/**
* NEXT_MAJOR: remove this method.
*
* @return ValidatorInterface
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getValidator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function applyConfigurationFromAttribute(Definition $definition, array $a
'translator',
'configuration_pool',
'router',
'validator',
'validator', //NEXT_MAJOR: Remove this line
'security_handler',
'menu_factory',
'route_builder',
Expand Down Expand Up @@ -281,7 +281,7 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at
'translator' => 'translator',
'configuration_pool' => 'sonata.admin.pool',
'route_generator' => 'sonata.admin.route.default_generator',
'validator' => 'validator',
'validator' => 'validator', //NEXT_MAJOR: Remove this line
'security_handler' => 'sonata.admin.security.handler',
'menu_factory' => 'knp_menu.factory',
'route_builder' => 'sonata.admin.route.path_info'.
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public function getConfigTreeBuilder()
->scalarNode('translator')->defaultNull()->end()
->scalarNode('configuration_pool')->defaultNull()->end()
->scalarNode('route_generator')->defaultNull()->end()
// NEXT_MAJOR: remove validator option
->scalarNode('validator')->defaultNull()->end()
->scalarNode('security_handler')->defaultNull()->end()
->scalarNode('label')->defaultNull()->end()
Expand Down
9 changes: 9 additions & 0 deletions tests/Admin/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,11 @@ public function testGetFormTheme(): void
$this->assertSame(['FooTheme'], $admin->getFormTheme());
}

/**
* NEXT_MAJOR: remove this method.
*
* @group legacy
*/
public function testGetValidator(): void
{
$admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController');
Expand All @@ -963,6 +968,9 @@ public function testGetValidator(): void
$validator = $this->getMockForAbstractClass(ValidatorInterface::class);

$admin->setValidator($validator);

$this->expectDeprecation('The Sonata\AdminBundle\Admin\AbstractAdmin::getValidator method is deprecated since version 3.x and will be removed in 4.0.');

$this->assertSame($validator, $admin->getValidator());
}

Expand Down Expand Up @@ -2840,6 +2848,7 @@ public function testAdminAvoidInifiniteLoop(): void

$validator = $this->createMock(ValidatorInterface::class);
$validator->method('getMetadataFor')->willReturn($this->createStub(MemberMetadata::class));

$admin->setValidator($validator);

$routeGenerator = $this->createStub(RouteGeneratorInterface::class);
Expand Down

0 comments on commit 5296b8f

Please sign in to comment.