-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add support for symfony contracts translator interface #6342
Changes from all commits
41ade71
007c5e1
5eb6cab
a7a88e1
96ae31c
b9c0db5
ad2ed34
b1facc4
296a8fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,10 @@ | |
use Symfony\Component\Routing\Generator\UrlGeneratorInterface as RoutingUrlGeneratorInterface; | ||
use Symfony\Component\Security\Acl\Model\DomainObjectInterface; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; | ||
use Symfony\Component\Validator\Mapping\GenericMetadata; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
|
@@ -309,7 +310,7 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A | |
* | ||
* NEXT_MAJOR: remove this property | ||
* | ||
* @var \Symfony\Component\Translation\TranslatorInterface | ||
* @var TranslatorInterface|LegacyTranslatorInterface | ||
* | ||
* @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 | ||
*/ | ||
|
@@ -2443,7 +2444,11 @@ public function transChoice($id, $count, array $parameters = [], $domain = null, | |
|
||
$domain = $domain ?: $this->getTranslationDomain(); | ||
|
||
return $this->translator->transChoice($id, $count, $parameters, $domain, $locale); | ||
if ($this->translator instanceof LegacyTranslatorInterface) { | ||
return $this->translator->transChoice($id, $count, $parameters, $domain, $locale); | ||
} | ||
|
||
return $this->translator->trans($id, ['%count%' => $count] + $parameters, $domain, $locale); | ||
dmaicher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public function setTranslationDomain($translationDomain) | ||
|
@@ -2461,9 +2466,11 @@ public function getTranslationDomain() | |
* | ||
* NEXT_MAJOR: remove this method | ||
* | ||
* @param LegacyTranslatorInterface|TranslatorInterface $translator | ||
* | ||
* @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 | ||
*/ | ||
public function setTranslator(TranslatorInterface $translator) | ||
public function setTranslator(object $translator) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would not be this BC-break for someone extending the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://sandbox.onlinephpfunctions.com/code/33e12ee18a6acc787333047f632e5dd6a0367aef It is possible to change type hint to more restricted, anyway you will get warnings. Technicly this change will be BC-break but will work correct in production. I think upgrade note will be enought. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonata-project/contributors WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
that is not necessarily correct. On some of my projects even warnings will throw exceptions on production. Depends how you configure it. So I think indeed this is a BC break 😢 good catch @franmomu How can we avoid it? 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some idea: What if we rely on A quick prototype public function __call($name, $arguments)
{
if ($name !== 'setTranslator') {
throw new \BadMethodCallException('...');
}
@trigger_error(
'The AbstractAdmin::setTranslator method is deprecated since version 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
if (!is_array($arguments)
|| count($arguments) === 0
|| (!($translator = $arguments[0]) instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface)
) {
throw new \TypeError('...');
}
$this->translator = $translator;
} This means we could remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, there are more and more BC-breaks, we should not be afraid to move those to the next major for any reason. If we are afraid, it means we don't release majors often enough, and that's the issue we should fix, maybe by releasing one major per year at a given date. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. namespace Symfony\Component\Translation;
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
/**
* @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. Use \Symfony\Contracts\Translation\TranslatorInterface instead.
*/
class_alias('Symfony\Contracts\Translation\TranslatorInterface', 'Symfony\Component\Translation\TranslatorInterface');
} WDYT about this solution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO Add support for Symfony5 in Sonata3 will be awesome. Anyway force user to upgrade Sonata to v4 if they want use Symfony5 is also good thing. One important question: How much work with BC-break must be done in Sonata3 to support Symfony5? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree about focusing on 4.0, but TBH I have no idea how far we are from having a stable, battle-tested release of 4.0 and some of the changes to be compatible with Symfony 5 have to be done anyway, so IMO I'd support for Symfony 5 in In this particular case, apparently (#6213 (comment)) we have the same problem in 4.x (since the method hasn't been removed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We will never know if we don't start working actively on it. We started with @jordisala1991, and the sonata 4 just need
And since sonata-project/SonataDoctrineORMAdminBundle#1073 we can start to make real test with master branch.
But this introduce BC-break. Or will add a lot of complexity to our code which lead to difficulty to maintain/update. |
||
{ | ||
$args = \func_get_args(); | ||
if (isset($args[1]) && $args[1]) { | ||
|
@@ -2473,6 +2480,16 @@ public function setTranslator(TranslatorInterface $translator) | |
), E_USER_DEPRECATED); | ||
} | ||
|
||
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) { | ||
throw new \TypeError(sprintf( | ||
'Argument 1 passed to "%s()" must be an instance of "%s" or "%s", instance of "%s" given.', | ||
__METHOD__, | ||
LegacyTranslatorInterface::class, | ||
TranslatorInterface::class, | ||
\get_class($translator) | ||
)); | ||
} | ||
|
||
$this->translator = $translator; | ||
} | ||
|
||
|
@@ -2482,6 +2499,8 @@ public function setTranslator(TranslatorInterface $translator) | |
* NEXT_MAJOR: remove this method | ||
* | ||
* @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 | ||
* | ||
* @return LegacyTranslatorInterface|TranslatorInterface | ||
*/ | ||
public function getTranslator() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,9 @@ | |
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
|
@@ -64,6 +65,7 @@ | |
* @method void reorderFormGroup(string $group, array $keys) | ||
* @method void defineFormBuilder(FormBuilderInterface $formBuilder) | ||
* @method string getPagerType() | ||
* @method void setTranslator(object $translator); | ||
*/ | ||
interface AdminInterface extends AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface | ||
{ | ||
|
@@ -90,10 +92,8 @@ public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder); | |
*/ | ||
public function getDatagridBuilder(); | ||
|
||
public function setTranslator(TranslatorInterface $translator); | ||
|
||
/** | ||
* @return TranslatorInterface | ||
* @return TranslatorInterface|LegacyTranslatorInterface | ||
*/ | ||
public function getTranslator(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnt this available on sf4.4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in master the compat code can be droped safely right? if thats the case we should add next major cments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed. On master it can be typehinted with
Symfony\Contracts\Translation\TranslatorInterface
and we can drop all usages of the old legacy interfaceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But actually on master most usages should be fully removed anyway 😊
See https://github.com/sonata-project/SonataAdminBundle/pull/6342/files#diff-61e6d1f8fafe87b868adbe28ce0ba8f6R311
https://github.com/sonata-project/SonataAdminBundle/pull/6342/files#diff-61e6d1f8fafe87b868adbe28ce0ba8f6R2467
https://github.com/sonata-project/SonataAdminBundle/pull/6342/files#diff-30aa995d1ac562ec3c1e60958ab6032fR49
etc