-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
FilesystemServiceProvider.php
63 lines (55 loc) · 2.1 KB
/
FilesystemServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Filesystem;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Flarum\Http\UrlGenerator;
use Illuminate\Contracts\Container\Container;
use Illuminate\Filesystem\Filesystem;
use League\Flysystem\Visibility;
class FilesystemServiceProvider extends AbstractServiceProvider
{
public function register(): void
{
$this->container->singleton('files', function () {
return new Filesystem();
});
$this->container->singleton('flarum.filesystem.disks', function () {
return [
'flarum-assets' => function (Paths $paths, UrlGenerator $url) {
return [
'root' => "$paths->public/assets",
'url' => $url->to('forum')->path('assets'),
'visibility' => Visibility::PUBLIC
];
},
'flarum-avatars' => function (Paths $paths, UrlGenerator $url) {
return [
'root' => "$paths->public/assets/avatars",
'url' => $url->to('forum')->path('assets/avatars')
];
},
];
});
$this->container->singleton('flarum.filesystem.drivers', function () {
return [];
});
$this->container->singleton('flarum.filesystem.resolved_drivers', function (Container $container) {
return array_map(function ($driverClass) use ($container) {
return $container->make($driverClass);
}, $container->make('flarum.filesystem.drivers'));
});
$this->container->singleton('filesystem', function (Container $container) {
return new FilesystemManager(
$container,
$container->make('flarum.filesystem.disks'),
$container->make('flarum.filesystem.resolved_drivers')
);
});
}
}