GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FileManagerServiceProvider::_publishConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace rdx\filemanager;
4
5
use Illuminate\Contracts\Config\Repository as Config;
6
use Illuminate\Contracts\Container\Container;
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
use rdx\filemanager\FileManager;
10
use rdx\filemanager\FileManagerDatabaseStorage;
11
12
class FileManagerServiceProvider extends ServiceProvider {
13
14
	/**
15
	 *
16
	 */
17
	public function register() {
18
		$this->_registerService();
19
		$this->_publishConfig();
20
	}
21
22
	/**
23
	 *
24
	 */
25
	public function boot() {
26
		$router = $this->app['router'];
27
		$config = $this->app['config'];
28
29
		$this->_loadMigrations();
30
		$this->_defineRouteParams($router);
31
32
		if ($config['filemanager']['publishers']['route']) {
33
			$this->_definePublishRoute($router, $config);
34
		}
35
	}
36
37
	/**
38
	 *
39
	 */
40
	protected function _registerService() {
41
		$this->app->singleton('filemanager', function(Container $app) {
42
			$connection = $app['db.connection'];
43
			$config = $app['config']['filemanager'];
44
45
			$storage = new FileManagerDatabaseStorage($connection, $config['storage']);
46
			$manager = new FileManager($storage, $config['manager']);
47
48
			if ($config['publishers']['original']) {
49
				$manager->addPublisher('original', function(FileManager $manager, ManagedFile $file) {
50
					$target = $manager->resolvePublicPath('original', $file->filepath);
51
					copy($file->fullpath, $target);
52
				});
53
			}
54
55
			return $manager;
56
		});
57
58
		$this->app->alias('filemanager', FileManager::class);
59
	}
60
61
	/**
62
	 *
63
	 */
64
	protected function _publishConfig() {
65
		$path = __DIR__ . '/../config/filemanager.php';
66
67
		$this->publishes([
68
			$path => config_path('filemanager.php'),
69
		]);
70
71
		$this->mergeConfigFrom($path, 'filemanager');
72
	}
73
74
	/**
75
	 *
76
	 */
77
	protected function _loadMigrations() {
78
		$this->loadMigrationsFrom(__DIR__ . '/../migrations/');
79
	}
80
81
	/**
82
	 *
83
	 */
84
	protected function _defineRouteParams(Router $router) {
85
		$router->pattern('managed_file', '[0-9]+');
86
		$router->bind('managed_file', function($id) {
87
			$manager = $this->app->make('filemanager');
88
			return $manager->findOrFail($id);
89
		});
90
91
		$router->pattern('filemanager_publisher', '[^/]+');
92
		$router->pattern('filemanager_file_path', '.+');
93
	}
94
95
	/**
96
	 *
97
	 */
98
	protected function _definePublishRoute(Router $router, Config $config) {
99
		$prefix = $config['filemanager']['manager']['public'];
100
		$uri = "$prefix/{filemanager_publisher}/{filemanager_file_path}";
101
102
		$router->get($uri, FileManagerController::class . '@getPublish')
103
			->name('filemanager.publish')
104
			->middleware('web');
105
	}
106
107
}
108