1 | <?php |
||
22 | class LodashServiceProvider extends ServiceProvider |
||
23 | { |
||
24 | protected $commands = [ |
||
25 | 'command.lodash.clear-all' => ClearAll::class, |
||
26 | 'command.lodash.db.clear' => DbClear::class, |
||
27 | 'command.lodash.db.dump' => DbDump::class, |
||
28 | 'command.lodash.db.restore' => DbRestore::class, |
||
29 | 'command.lodash.log.clear' => LogClear::class, |
||
30 | 'command.lodash.user.add' => UserAdd::class, |
||
31 | 'command.lodash.user.password' => UserPassword::class, |
||
32 | ]; |
||
33 | |||
34 | 71 | public function boot(): void |
|
44 | |||
45 | 71 | public function register(): void |
|
51 | |||
52 | 71 | protected function registerCommands(): void |
|
60 | |||
61 | 71 | protected function registerBladeDirectives(): void |
|
62 | { |
||
63 | // Display relative time |
||
64 | 71 | app('blade.compiler')->directive('datetime', static function ($expression) { |
|
65 | |||
66 | return "<?php echo '<time datetime=\'' . with({$expression})->toIso8601String() |
||
67 | . '\' title=\'' . $expression . '\'>' |
||
68 | . with({$expression})->diffForHumans() . '</time>' ?>"; |
||
69 | 71 | }); |
|
70 | |||
71 | // Pluralization helper |
||
72 | 71 | app('blade.compiler')->directive('plural', static function ($expression) { |
|
73 | $expression = trim($expression, '()'); |
||
74 | [$count, $str, $spacer] = array_pad(preg_split('/,\s*/', $expression), 3, "' '"); |
||
75 | |||
76 | return "<?php echo $count . $spacer . str_plural($str, $count) ?>"; |
||
77 | 71 | }); |
|
78 | 71 | } |
|
79 | |||
80 | 71 | protected function registerRequestMacros(): void |
|
81 | { |
||
82 | 71 | Request::macro('getInt', function (string $name, int $default = 0): int { |
|
83 | |||
84 | return (int) $this->get($name, $default); |
||
85 | 71 | }); |
|
86 | |||
87 | 71 | Request::macro('getBool', function (string $name, bool $default = false): bool { |
|
88 | |||
89 | return (bool) $this->get($name, $default); |
||
90 | 71 | }); |
|
91 | |||
92 | 71 | Request::macro('getFloat', function (string $name, float $default = 0): float { |
|
93 | |||
94 | return (float) $this->get($name, $default); |
||
95 | 71 | }); |
|
96 | |||
97 | 71 | Request::macro('getString', function (string $name, string $default = ''): string { |
|
98 | |||
99 | return (string) $this->get($name, $default); |
||
100 | 71 | }); |
|
101 | 71 | } |
|
102 | |||
103 | 71 | protected function loadTranslations(): void |
|
111 | } |
||
112 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.