|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Laravel Lodash package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Longman\LaravelLodash; |
|
13
|
|
|
|
|
14
|
|
|
use Blade; |
|
15
|
|
|
use Illuminate\Support\ServiceProvider; |
|
16
|
|
|
|
|
17
|
|
|
class LodashServiceProvider extends ServiceProvider |
|
18
|
|
|
{ |
|
19
|
|
|
protected $commands = [ |
|
20
|
|
|
'command.lodash.clear-all' => \Longman\LaravelLodash\Commands\ClearAll::class, |
|
21
|
|
|
'command.lodash.db.clear' => \Longman\LaravelLodash\Commands\DbClear::class, |
|
22
|
|
|
'command.lodash.db.dump' => \Longman\LaravelLodash\Commands\DbDump::class, |
|
23
|
|
|
'command.lodash.db.restore' => \Longman\LaravelLodash\Commands\DbRestore::class, |
|
24
|
|
|
'command.lodash.log.clear' => \Longman\LaravelLodash\Commands\LogClear::class, |
|
25
|
|
|
'command.lodash.user.add' => \Longman\LaravelLodash\Commands\UserAdd::class, |
|
26
|
|
|
'command.lodash.user.password' => \Longman\LaravelLodash\Commands\UserPassword::class, |
|
27
|
|
|
|
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
3 |
|
public function boot() |
|
32
|
|
|
{ |
|
33
|
3 |
|
$this->publishes([ |
|
34
|
3 |
|
__DIR__ . '/../config/config.php' => config_path('lodash.php'), |
|
35
|
|
|
]); |
|
36
|
3 |
|
} |
|
37
|
|
|
|
|
38
|
3 |
|
public function register() |
|
39
|
|
|
{ |
|
40
|
3 |
|
$this->registerCommands(); |
|
41
|
|
|
|
|
42
|
3 |
|
$this->registerBladeDirectives(); |
|
43
|
3 |
|
} |
|
44
|
|
|
|
|
45
|
3 |
|
protected function registerCommands() |
|
46
|
|
|
{ |
|
47
|
3 |
|
foreach ($this->commands as $name => $class) { |
|
48
|
3 |
|
$this->app->singleton($name, $class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
$this->commands(array_keys($this->commands)); |
|
52
|
3 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function registerBladeDirectives() |
|
55
|
|
|
{ |
|
56
|
|
|
// Display relative time |
|
57
|
3 |
|
Blade::directive('datetime', function ($expression) { |
|
58
|
|
|
|
|
59
|
|
|
return "<?php echo '<time datetime=\'' . with({$expression})->toIso8601String() |
|
60
|
|
|
. '\' title=\'' . $expression . '\'>' |
|
61
|
|
|
. with({$expression})->diffForHumans() . '</time>' ?>"; |
|
62
|
3 |
|
}); |
|
63
|
|
|
|
|
64
|
|
|
// Pluralization helper |
|
65
|
3 |
|
Blade::directive('plural', function ($expression) { |
|
66
|
|
|
$expression = trim($expression, '()'); |
|
67
|
|
|
list($count, $str, $spacer) = array_pad(preg_split('/,\s*/', $expression), 3, "' '"); |
|
68
|
|
|
|
|
69
|
|
|
return "<?php echo $count . $spacer . str_plural($str, $count) ?>"; |
|
70
|
3 |
|
}); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|