Skip to content

Commit 19e888b

Browse files
committed
Replace closure with class name in config file
1 parent 13690f9 commit 19e888b

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/Handlers/ConfigHandler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Handlers;
4+
5+
class ConfigHandler
6+
{
7+
public function userField()
8+
{
9+
return auth()->user()->id;
10+
}
11+
}

src/LaravelFilemanagerServiceProvider.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use Illuminate\Support\ServiceProvider;
44
use Illuminate\Support\Facades\Config;
55

6-
76
/**
87
* Class LaravelFilemanagerServiceProvider
98
* @package Unisharp\Laravelfilemanager
@@ -17,8 +16,9 @@ class LaravelFilemanagerServiceProvider extends ServiceProvider {
1716
*/
1817
public function boot()
1918
{
20-
if (Config::get('lfm.use_package_routes'))
19+
if (Config::get('lfm.use_package_routes')) {
2120
include __DIR__ . '/routes.php';
21+
}
2222

2323
$this->loadTranslationsFrom(__DIR__.'/lang', 'laravel-filemanager');
2424

@@ -28,13 +28,17 @@ public function boot()
2828
__DIR__ . '/config/lfm.php' => base_path('config/lfm.php'),
2929
], 'lfm_config');
3030

31-
$this->publishes([
32-
__DIR__.'/../public' => public_path('vendor/laravel-filemanager'),
31+
$this->publishes([
32+
__DIR__.'/../public' => public_path('vendor/laravel-filemanager'),
3333
], 'lfm_public');
3434

3535
$this->publishes([
3636
__DIR__.'/views' => base_path('resources/views/vendor/laravel-filemanager'),
3737
], 'lfm_view');
38+
39+
$this->publishes([
40+
__DIR__.'/Handlers' => base_path('app/Handlers')
41+
], 'lfm_handler');
3842
}
3943

4044
/**
@@ -44,10 +48,8 @@ public function boot()
4448
*/
4549
public function register()
4650
{
47-
$this->app->singleton('laravel-filemanager', function ()
48-
{
51+
$this->app->singleton('laravel-filemanager', function () {
4952
return true;
5053
});
5154
}
52-
5355
}

src/config/lfm.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
'allow_share_folder' => true,
3434

3535
// Flexibla way to customize client folders accessibility
36+
// You can extend ConfigHandler class and rewrite userField function in class
3637
// Ex: The private folder of user will be named as the user id.
37-
// You cant use a closure when using the optimized config file (in Laravel 5.2 anyway)
38-
'user_field' => function() {
39-
return auth()->user()->id;
40-
},
38+
'user_field' => App\Handlers\ConfigHandler::class,
4139

4240
/*
4341
|--------------------------------------------------------------------------
@@ -164,7 +162,7 @@
164162
| These values override your php.ini settings before uploading files
165163
| Set these to false to ingnore and apply your php.ini settings
166164
|
167-
| Please note that the 'upload_max_filesize' & 'post_max_size'
165+
| Please note that the 'upload_max_filesize' & 'post_max_size'
168166
| directives are not supported.
169167
*/
170168
'php_ini_overrides' => [

src/traits/LfmHelpers.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,10 @@ public function sortFilesAndDirectories($arr_items, $sort_type)
588588
*/
589589
public function getUserSlug()
590590
{
591-
if (is_callable(config('lfm.user_field'))) {
591+
if (class_exists(config('lfm.user_field'))) {
592+
$config_handler = config('lfm.user_field');
593+
$slug_of_user = app()->make($config_handler)->userField();
594+
} elseif (is_callable(config('lfm.user_field'))) {
592595
$slug_of_user = call_user_func(config('lfm.user_field'));
593596
} else {
594597
$old_slug_of_user = config('lfm.user_field');

0 commit comments

Comments
 (0)