jamesmills /
laravel-timezone
| 1 | <?php |
||
| 2 | |||
| 3 | namespace JamesMills\LaravelTimezone; |
||
| 4 | |||
| 5 | use Illuminate\Foundation\AliasLoader; |
||
| 6 | use Illuminate\Support\Facades\Blade; |
||
| 7 | use Illuminate\Support\Facades\Event; |
||
| 8 | use Illuminate\Support\ServiceProvider; |
||
| 9 | use JamesMills\LaravelTimezone\Listeners\Auth\UpdateUsersTimezone; |
||
| 10 | |||
| 11 | class LaravelTimezoneServiceProvider extends ServiceProvider |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Indicates if loading of the provider is deferred. |
||
| 15 | * |
||
| 16 | * @var bool |
||
| 17 | */ |
||
| 18 | protected $defer = false; |
||
| 19 | |||
| 20 | |||
| 21 | /** |
||
| 22 | * Perform post-registration booting of services. |
||
| 23 | * |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public function boot() |
||
| 27 | { |
||
| 28 | // Allow migrations publish |
||
| 29 | if (! class_exists('AddTimezoneColumnToUsersTable')) { |
||
| 30 | $this->publishes([ |
||
| 31 | __DIR__ . '/database/migrations/add_timezone_column_to_users_table.php.stub' => database_path('/migrations/' . date('Y_m_d_His') . '_add_timezone_column_to_users_table.php'), |
||
| 32 | ], 'migrations'); |
||
| 33 | } |
||
| 34 | |||
| 35 | // Register the Timezone alias |
||
| 36 | AliasLoader::getInstance()->alias('Timezone', \JamesMills\LaravelTimezone\Facades\Timezone::class); |
||
| 37 | |||
| 38 | // Register an event listener |
||
| 39 | $this->registerEventListener(); |
||
| 40 | |||
| 41 | // Allow config publish |
||
| 42 | $this->publishes([ |
||
| 43 | __DIR__ . '/config/timezone.php' => config_path('timezone.php'), |
||
| 44 | ], 'config'); |
||
| 45 | |||
| 46 | // Register a blade directive to show user date/time in their timezone |
||
| 47 | Blade::directive( |
||
| 48 | 'displayDate', |
||
| 49 | function ($expression) { |
||
| 50 | $options = explode(',', $expression); |
||
| 51 | |||
| 52 | if (count($options) == 1) { |
||
| 53 | return "<?php echo e(Timezone::convertToLocal($options[0])); ?>"; |
||
| 54 | } elseif (count($options) == 2) { |
||
| 55 | return "<?php echo e(Timezone::convertToLocal($options[0], $options[1])); ?>"; |
||
| 56 | } elseif (count($options) == 3) { |
||
| 57 | return "<?php echo e(Timezone::convertToLocal($options[0], $options[1], $options[2])); ?>"; |
||
| 58 | } elseif (count($options) == 4) { |
||
| 59 | return "<?php echo e(Timezone::convertToLocal($options[0], $options[1], $options[2], $options[3])); ?>"; |
||
| 60 | } else { |
||
| 61 | return 'error'; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Register the service provider. |
||
| 69 | * |
||
| 70 | * @return void |
||
| 71 | */ |
||
| 72 | public function register() |
||
| 73 | { |
||
| 74 | $this->app->bind('timezone', Timezone::class); |
||
| 75 | |||
| 76 | $this->mergeConfigFrom( |
||
| 77 | __DIR__ . '/config/timezone.php', |
||
| 78 | 'timezone' |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * |
||
| 84 | */ |
||
| 85 | private function registerEventListener(): void |
||
| 86 | { |
||
| 87 | $events = [ |
||
| 88 | \Illuminate\Auth\Events\Login::class, |
||
| 89 | \Laravel\Passport\Events\AccessTokenCreated::class, |
||
|
0 ignored issues
–
show
|
|||
| 90 | ]; |
||
| 91 | |||
| 92 | Event::listen($events, UpdateUsersTimezone::class); |
||
| 93 | } |
||
| 94 | } |
||
| 95 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths