Skip to content

Commit

Permalink
Add deprecation and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed May 29, 2020
1 parent aeea05d commit 7f95e43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Timezone detectors
User timezone detector
^^^^^^^^^^^^^^^^^^^^^^

.. versionadded:: 2.x

If the model class for the authenticated user implements ``Sonata\IntlBundle\Timezone\TimezoneAwareInterface``,
it returns the timezone from its ``getTimezone()`` method.

**DEPRECATED**
Relying on ``Sonata\UserBundle\Model\User`` is deprecated since 2.x in favor of
explicit implementation of ``Sonata\IntlBundle\Timezone\TimezoneAwareInterface``.

If the SonataUserBundle_ is enabled, it returns the timezone from the
``Sonata\UserBundle\Model\User::getTimezone()`` method.

Expand Down
7 changes: 7 additions & 0 deletions src/Timezone/UserBasedTimezoneDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public function getTimezone()

// NEXT_MAJOR: Remove this check when `User` implement `TimezoneAwareInterface`
if ($user instanceof User) {
@trigger_error(sprintf(
'Timezone inference based on the %s class is deprecated since sonata-project/intl-bundle 2.7 and will be dropped in 3.0 version.'
.' Implement %s explicitely in your user class instead.',
User::class,
TimezoneAwareInterface::class
), E_USER_DEPRECATED);

return $user->getTimezone();
}

Expand Down

0 comments on commit 7f95e43

Please sign in to comment.