ServiceProvider.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace MailPoetVendor\Carbon\Laravel; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoetVendor\Carbon\Carbon; |
| 9 | use MailPoetVendor\Illuminate\Events\Dispatcher; |
| 10 | use MailPoetVendor\Illuminate\Events\EventDispatcher; |
| 11 | use MailPoetVendor\Illuminate\Translation\Translator as IlluminateTranslator; |
| 12 | use MailPoetVendor\Symfony\Component\Translation\Translator; |
| 13 | class ServiceProvider extends \MailPoetVendor\Illuminate\Support\ServiceProvider |
| 14 | { |
| 15 | public function boot() |
| 16 | { |
| 17 | $service = $this; |
| 18 | $events = $this->app['events']; |
| 19 | if ($events instanceof \MailPoetVendor\Illuminate\Events\EventDispatcher || $events instanceof \MailPoetVendor\Illuminate\Events\Dispatcher) { |
| 20 | $events->listen(\class_exists('MailPoetVendor\\Illuminate\\Foundation\\Events\\LocaleUpdated') ? 'Illuminate\\Foundation\\Events\\LocaleUpdated' : 'locale.changed', function () use($service) { |
| 21 | $service->updateLocale(); |
| 22 | }); |
| 23 | $service->updateLocale(); |
| 24 | } |
| 25 | } |
| 26 | public function updateLocale() |
| 27 | { |
| 28 | $translator = $this->app['translator']; |
| 29 | if ($translator instanceof \MailPoetVendor\Symfony\Component\Translation\Translator || $translator instanceof \MailPoetVendor\Illuminate\Translation\Translator) { |
| 30 | \MailPoetVendor\Carbon\Carbon::setLocale($translator->getLocale()); |
| 31 | } |
| 32 | } |
| 33 | public function register() |
| 34 | { |
| 35 | // Needed for Laravel < 5.3 compatibility |
| 36 | } |
| 37 | } |
| 38 |