Issues (51)

src/ServiceProvider.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Fomvasss\UrlAliases;
4
5
use Fomvasss\UrlAliases\Middleware\UrlAliasMiddleware;
6
use Illuminate\Contracts\Http\Kernel;
7
8
class ServiceProvider extends \Illuminate\Support\ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        $this->publishConfig();
18
19
        $this->publishMigrations();
20
21
//        $this->registerMiddleware(UrlAliasMiddleware::class);
22
    }
23
24
    /**
25
     * Register the application services.
26
     *
27
     * @return void
28
     */
29
    public function register()
30
    {
31
        $this->mergeConfigFrom(__DIR__.'/../config/url-aliases.php', 'url-aliases');
32
        $this->mergeConfigFrom(__DIR__.'/../config/url-aliases-laravellocalization.php', 'url-aliases-laravellocalization');
33
34
        $this->app->singleton(UrlAliasLocalization::class, function () {
35
            return new UrlAliasLocalization($this->app);
36
        });
37
38
        $this->app->singleton(UrlAlias::class, function () {
39
            return new UrlAlias($this->app);
40
        });
41
    }
42
43
    protected function publishConfig()
44
    {
45
        $this->publishes([
46
            __DIR__ . '/../config/url-aliases.php' => config_path('url-aliases.php'),
0 ignored issues
show
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            __DIR__ . '/../config/url-aliases.php' => /** @scrutinizer ignore-call */ config_path('url-aliases.php'),
Loading history...
47
            __DIR__ . '/../config/url-aliases-laravellocalization.php' => config_path('url-aliases-laravellocalization.php'),
48
        ], 'url-aliases-config');
49
    }
50
51
    protected function publishMigrations()
52
    {
53
        if (! class_exists('CreateUrlAliasesTable')) {
54
            $timestamp = date('Y_m_d_His', time());
55
56
            $migrationPath = __DIR__.'/../database/migrations/create_url_aliases_table.php';
57
                $this->publishes([$migrationPath => database_path('/migrations/' . $timestamp . '_create_url_aliases_table.php'),
0 ignored issues
show
The function database_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
                $this->publishes([$migrationPath => /** @scrutinizer ignore-call */ database_path('/migrations/' . $timestamp . '_create_url_aliases_table.php'),
Loading history...
58
            ], 'url-aliases-migrations');
59
        }
60
    }
61
62
    protected function registerMiddleware($middleware)
63
    {
64
        $kernel = $this->app[Kernel::class];
65
        $kernel->pushMiddleware($middleware);
66
    }
67
68
    protected function checkMakeDir(string $path)
69
    {
70
        if (!is_dir($path)) {
71
            mkdir($path, 0755, true);
72
        }
73
        return $path;
74
    }
75
}
76