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
Push — master ( f91a4c...f91a4c )
by Dave
39:26 queued 34:22
created

AdminServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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
     * Register bootstrap file.
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_once $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
        $domain = config('sleeping_owl.domain', false);
251 285
252
        $middlewares = collect($this->getConfig('middleware'));
253
        $middlewares = $middlewares->filter(function ($item) {
254 285
            return $item != 'web';
255 285
        });
256 285
        $configGroup = collect([
257 285
            'prefix'     => $this->getConfig('url_prefix'),
258
            'middleware' => $middlewares,
259 285
        ]);
260 285
261 285
        if ($domain) {
262 285
            $configGroup->put('domain', $domain);
263 285
        }
264 285
265
        $this->app['router']->group($configGroup->toArray(), function (Router $route) {
266
            $route->get('ckeditor/upload/image', [
267
                'as'   => 'admin.ckeditor.upload',
268
                'uses' => 'SleepingOwl\Admin\Http\Controllers\UploadController@ckEditorStore',
269 285
            ]);
270
271 285
            $route->post('ckeditor/upload/image', [
272 285
                'as'   => 'admin.ckeditor.upload',
273 285
                'uses' => 'SleepingOwl\Admin\Http\Controllers\UploadController@ckEditorStore',
274 285
            ]);
275 285
        });
276 285
    }
277 285
278
    /**
279
     * @param \Closure $callback
280
     */
281
    protected function registerRoutes(\Closure $callback)
282 285
    {
283
        $domain = config('sleeping_owl.domain', false);
284 285
        $configGroup = collect([
285
            'prefix'     => $this->getConfig('url_prefix'),
286
            'middleware' => $this->getConfig('middleware'),
287
        ]);
288
289
        if ($domain) {
290
            $configGroup->put('domain', $domain);
291 285
        }
292
293
        $this->app['router']->group($configGroup->toArray(), function (Router $route) use ($callback) {
294
            call_user_func($callback, $route);
295
        });
296
    }
297
298
    /**
299
     * Register navigation file.
300
     */
301
    protected function registerNavigationFile()
302
    {
303
        if (file_exists($navigation = $this->getBootstrapPath('navigation.php'))) {
304
            $items = include $navigation;
305
306
            if (is_array($items)) {
307
                $this->app['sleeping_owl.navigation']->setFromArray($items);
308
            }
309
        }
310
    }
311
}
312