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.
Completed
Pull Request — master (#688)
by
unknown
18:52
created

AdminServiceProvider   B

Complexity

Total Complexity 25

Size/Duplication

Total Lines 262
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 18

Test Coverage

Coverage 84.72%

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 18
dl 0
loc 262
ccs 122
cts 144
cp 0.8472
rs 7.3333
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 28 1
B registerTemplate() 0 26 3
A getConfig() 0 4 1
A getBootstrapPath() 0 8 2
A boot() 0 5 1
A registerMessages() 0 16 2
B initializeNavigation() 0 31 1
A registerWysiwyg() 0 6 1
A registerBootstrap() 0 22 3
A registerAliases() 0 4 1
A registerCustomRoutes() 0 8 2
A registerDefaultRoutes() 0 12 2
A registerSupportRoutes() 0 17 1
A registerRoutes() 0 9 1
A registerNavigationFile() 0 10 3
1
<?php
2
3
namespace SleepingOwl\Admin\Providers;
4
5
use Illuminate\Routing\Router;
6
use SleepingOwl\Admin\Navigation;
7
use SleepingOwl\Admin\AliasBinder;
8
use Symfony\Component\Finder\Finder;
9
use SleepingOwl\Admin\Templates\Meta;
10
use Illuminate\Foundation\AliasLoader;
11
use Illuminate\Foundation\Application;
12
use SleepingOwl\Admin\Wysiwyg\Manager;
13
use Illuminate\Support\ServiceProvider;
14
use SleepingOwl\Admin\Templates\Assets;
15
use Symfony\Component\Finder\SplFileInfo;
16
use SleepingOwl\Admin\Routing\ModelRouter;
17
use SleepingOwl\Admin\Widgets\WidgetsRegistry;
18
use SleepingOwl\Admin\Exceptions\TemplateException;
19
use SleepingOwl\Admin\Widgets\Messages\InfoMessages;
20
use SleepingOwl\Admin\Widgets\Messages\MessageStack;
21
use Illuminate\Contracts\View\Factory as ViewFactory;
22
use SleepingOwl\Admin\Widgets\Messages\ErrorMessages;
23
use SleepingOwl\Admin\Model\ModelConfigurationManager;
24
use SleepingOwl\Admin\Widgets\Messages\SuccessMessages;
25
use SleepingOwl\Admin\Widgets\Messages\WarningMessages;
26
use SleepingOwl\Admin\Contracts\Form\FormButtonsInterface;
27
use SleepingOwl\Admin\Contracts\Repositories\RepositoryInterface;
28
use SleepingOwl\Admin\Contracts\Widgets\WidgetsRegistryInterface;
29
use SleepingOwl\Admin\Contracts\Display\TableHeaderColumnInterface;
30
31
class AdminServiceProvider extends ServiceProvider
32
{
33
    /**
34
     * @var string
35
     */
36
    protected $directory;
37
38 285
    public function register()
39
    {
40 285
        $this->registerWysiwyg();
41 285
        $this->registerTemplate();
42 285
        $this->initializeNavigation();
43 285
        $this->registerAliases();
44
45
        $this->app->singleton('sleeping_owl.widgets', function () {
46 285
            return new WidgetsRegistry($this->app);
47 285
        });
48
49
        $this->app->booted(function () {
50 285
            $this->app['sleeping_owl.widgets']->placeWidgets(
51 285
                $this->app[ViewFactory::class]
52 285
            );
53 285
        });
54
55
        $this->app->booted(function () {
56 285
            $this->registerCustomRoutes();
57 285
            $this->registerDefaultRoutes();
58 285
            $this->registerSupportRoutes();
59 285
            $this->registerNavigationFile();
60
61 285
            $this->app['sleeping_owl']->initialize();
62 285
        });
63
64 285
        ModelConfigurationManager::setEventDispatcher($this->app['events']);
65 285
    }
66
67 285
    protected function registerTemplate()
68
    {
69
        $this->app->singleton('assets.packages', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70 285
            return new \KodiCMS\Assets\PackageManager();
71 285
        });
72
73
        $this->app->singleton('sleeping_owl.meta', function ($app) {
74 285
            return new Meta(
75 285
                new Assets(
76 285
                    $app['assets.packages']
77 285
                )
78 285
            );
79 285
        });
80
81
        $this->app->singleton('sleeping_owl.template', function (Application $app) {
82 285
            if (! class_exists($class = $this->getConfig('template'))) {
83
                throw new TemplateException("Template class [{$class}] not found");
84
            }
85
86 285
            return $app->make($class);
87 285
        });
88
89 285
        if (file_exists($assetsFile = __DIR__.'/../../resources/assets.php')) {
90 285
            include $assetsFile;
91 285
        }
92 285
    }
93
94
    /**
95
     * @param string $key
96
     *
97
     * @return mixed
98
     */
99 285
    protected function getConfig($key)
100
    {
101 285
        return $this->app['config']->get('sleeping_owl.'.$key);
102
    }
103
104
    /**
105
     * @param string $path
106
     *
107
     * @return string
108
     */
109 285
    protected function getBootstrapPath($path = null)
110
    {
111 285
        if (! is_null($path)) {
112 285
            $path = DIRECTORY_SEPARATOR.$path;
113 285
        }
114
115 285
        return $this->getConfig('bootstrapDirectory').$path;
116
    }
117
118 285
    public function boot()
119
    {
120 285
        $this->registerMessages();
121 285
        $this->registerBootstrap();
122 285
    }
123
124
    /**
125
     * Global register messages of adminpanel.
126
     */
127 285
    protected function registerMessages()
128
    {
129
        $messageTypes = [
130 285
            'error'   => ErrorMessages::class,
131 285
            'info'    => InfoMessages::class,
132 285
            'success' => SuccessMessages::class,
133 285
            'warning' => WarningMessages::class,
134 285
        ];
135 285
        foreach ($messageTypes as $messageType) {
136 285
            $this->app[WidgetsRegistryInterface::class]->registerWidget($messageType);
137 285
        }
138
139
        $this->app->singleton('sleeping_owl.message', function () use ($messageTypes) {
140
            return new MessageStack($messageTypes);
141 285
        });
142 285
    }
143
144 285
    protected function initializeNavigation()
145
    {
146 285
        $this->app->bind(
147 285
            TableHeaderColumnInterface::class,
148
            \SleepingOwl\Admin\Display\TableHeaderColumn::class
149 285
        );
150
151 285
        $this->app->bind(
152 285
            RepositoryInterface::class,
153
            \SleepingOwl\Admin\Repositories\BaseRepository::class
154 285
        );
155
156 285
        $this->app->bind(
157 285
            FormButtonsInterface::class,
158
            \SleepingOwl\Admin\Form\FormButtons::class
159 285
        );
160
161 285
        $this->app->bind(
162 285
            \KodiComponents\Navigation\Contracts\PageInterface::class,
163
            \SleepingOwl\Admin\Navigation\Page::class
164 285
        );
165
166 285
        $this->app->bind(
167 285
            \KodiComponents\Navigation\Contracts\BadgeInterface::class,
168
            \SleepingOwl\Admin\Navigation\Badge::class
169 285
        );
170
171
        $this->app->singleton('sleeping_owl.navigation', function () {
172 285
            return new Navigation();
173 285
        });
174 285
    }
175
176 285
    protected function registerWysiwyg()
177
    {
178
        $this->app->singleton('sleeping_owl.wysiwyg', function () {
179 285
            return new Manager($this->app);
180 285
        });
181 285
    }
182
183
    /**
184
     * @return array
185
     */
186 285
    protected function registerBootstrap()
187
    {
188 285
        $directory = $this->getBootstrapPath();
189
190 285
        if (! is_dir($directory)) {
191 285
            return;
192
        }
193
194
        $files = Finder::create()
195
            ->files()
196
            ->name('/^.+\.php$/')
197
            ->notName('routes.php')
198
            ->notName('navigation.php')
199
            ->in($directory)
200
            ->sort(function (SplFileInfo $a) {
201
                return $a->getFilename() != 'bootstrap.php';
202
            });
203
204
        foreach ($files as $file) {
205
            require $file;
206
        }
207
    }
208
209
    /**
210
     * Register Alias from App.
211
     */
212 285
    protected function registerAliases()
213
    {
214 285
        AliasLoader::getInstance(config('sleeping_owl.aliases', []));
215 285
    }
216
217
    /**
218
     * Register Custom Routes From Users.
219
     */
220 285
    protected function registerCustomRoutes()
221
    {
222 285
        if (file_exists($file = $this->getBootstrapPath('routes.php'))) {
223
            $this->registerRoutes(function (Router $route) use ($file) {
224
                require $file;
225
            });
226
        }
227 285
    }
228
229
    /**
230
     * Register Default Admin Routes.
231
     */
232 285
    protected function registerDefaultRoutes()
233
    {
234
        $this->registerRoutes(function (Router $router) {
235 285
            (new ModelRouter($this->app, $router))->register($this->app['sleeping_owl']->getModels());
236
237 285
            if (file_exists($routesFile = __DIR__.'/../Http/routes.php')) {
238 285
                require $routesFile;
239 285
            }
240
241 285
            AliasBinder::registerRoutes($router);
242 285
        });
243 285
    }
244
245
    /**
246
     * Register CKEditor Upload and D&D plugins.
247
     */
248 285
    protected function registerSupportRoutes()
249
    {
250 285
        $this->app['router']->group([
251 285
            'prefix' => $this->getConfig('url_prefix'),
252
253
        ], function (Router $route) {
254 285
            $route->get('ckeditor/upload/image', [
255 285
                'as'   => 'admin.ckeditor.upload',
256 285
                'uses' => 'SleepingOwl\Admin\Http\Controllers\UploadController@ckEditorStore',
257 285
            ]);
258
259 285
            $route->post('ckeditor/upload/image', [
260 285
                'as'   => 'admin.ckeditor.upload',
261 285
                'uses' => 'SleepingOwl\Admin\Http\Controllers\UploadController@ckEditorStore',
262 285
            ]);
263 285
        });
264 285
    }
265
266
    /**
267
     * @param \Closure $callback
268
     */
269 285
    protected function registerRoutes(\Closure $callback)
270
    {
271 285
        $this->app['router']->group([
272 285
            'prefix'     => $this->getConfig('url_prefix'),
273 285
            'middleware' => $this->getConfig('middleware'),
274 285
        ], function (Router $route) use ($callback) {
275 285
            call_user_func($callback, $route);
276 285
        });
277 285
    }
278
279
    /**
280
     * Register navigation file.
281
     */
282 285
    protected function registerNavigationFile()
283
    {
284 285
        if (file_exists($navigation = $this->getBootstrapPath('navigation.php'))) {
285
            $items = include $navigation;
286
287
            if (is_array($items)) {
288
                $this->app['sleeping_owl.navigation']->setFromArray($items);
289
            }
290
        }
291 285
    }
292
}
293