Skip to content

Commit

Permalink
No deprecation message for classes that implement old and new Transla…
Browse files Browse the repository at this point in the history
…torInterface
  • Loading branch information
jorrit authored and jordisala1991 committed Apr 15, 2021
1 parent 001964a commit 21c4ebf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 64 deletions.
39 changes: 23 additions & 16 deletions src/Security/ForbiddenDownloadStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ class ForbiddenDownloadStrategy implements DownloadStrategyInterface

public function __construct(object $translator)
{
if ($translator instanceof LegacyTranslatorInterface) {
@trigger_error(sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
), \E_USER_DEPRECATED);
} elseif (!$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
));
if (!$translator instanceof TranslatorInterface) {
if (!$translator instanceof LegacyTranslatorInterface) {
throw new \TypeError(
sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
)
);
}

@trigger_error(
sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
),
\E_USER_DEPRECATED
);
}

$this->translator = $translator;
Expand Down
39 changes: 23 additions & 16 deletions src/Security/PublicDownloadStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ class PublicDownloadStrategy implements DownloadStrategyInterface

public function __construct(object $translator)
{
if ($translator instanceof LegacyTranslatorInterface) {
@trigger_error(sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
), \E_USER_DEPRECATED);
} elseif (!$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
));
if (!$translator instanceof TranslatorInterface) {
if (!$translator instanceof LegacyTranslatorInterface) {
throw new \TypeError(
sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
)
);
}

@trigger_error(
sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
),
\E_USER_DEPRECATED
);
}

$this->translator = $translator;
Expand Down
39 changes: 23 additions & 16 deletions src/Security/RolesDownloadStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,29 @@ class RolesDownloadStrategy implements DownloadStrategyInterface
*/
public function __construct(object $translator, AuthorizationCheckerInterface $security, array $roles = [])
{
if ($translator instanceof LegacyTranslatorInterface) {
@trigger_error(sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
), \E_USER_DEPRECATED);
} elseif (!$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
));
if (!$translator instanceof TranslatorInterface) {
if (!$translator instanceof LegacyTranslatorInterface) {
throw new \TypeError(
sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
)
);
}

@trigger_error(
sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
),
\E_USER_DEPRECATED
);
}

$this->roles = $roles;
Expand Down
39 changes: 23 additions & 16 deletions src/Security/SessionDownloadStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,29 @@ class SessionDownloadStrategy implements DownloadStrategyInterface
*/
public function __construct(object $translator, object $sessionOrContainer, $times)
{
if ($translator instanceof LegacyTranslatorInterface) {
@trigger_error(sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
), \E_USER_DEPRECATED);
} elseif (!$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
));
if (!$translator instanceof TranslatorInterface) {
if (!$translator instanceof LegacyTranslatorInterface) {
throw new \TypeError(
sprintf(
'Argument 1 passed to "%s()" MUST be an instance of "%s" or "%s", "%s" given.',
__METHOD__,
LegacyTranslatorInterface::class,
TranslatorInterface::class,
\get_class($translator)
)
);
}

@trigger_error(
sprintf(
'Passing other type than "%s" as argument 1 to "%s()" is deprecated since sonata-project/media-bundle 3.31'
.' and will throw a "%s" error in 4.0.',
TranslatorInterface::class,
__METHOD__,
\TypeError::class
),
\E_USER_DEPRECATED
);
}

// NEXT_MAJOR: Remove these checks and declare `SessionInterface` for argument 2.
Expand Down

0 comments on commit 21c4ebf

Please sign in to comment.