1 | <?php |
||||
2 | |||||
3 | namespace Lionix\SeoManager; |
||||
4 | |||||
5 | use Illuminate\Support\Facades\Blade; |
||||
6 | use Illuminate\Support\ServiceProvider; |
||||
7 | use Lionix\SeoManager\Commands\GenerateSeoManagerData; |
||||
8 | |||||
9 | class SeoManagerServiceProvider extends ServiceProvider |
||||
10 | { |
||||
11 | /** |
||||
12 | * Bootstrap services. |
||||
13 | * |
||||
14 | * @return void |
||||
15 | */ |
||||
16 | public function boot() |
||||
17 | { |
||||
18 | $this->loadRoutesFrom(__DIR__ . '/routes/seo-manager.php'); |
||||
19 | $this->loadMigrationsFrom(__DIR__ . '/migrations'); |
||||
20 | $this->loadViewsFrom(__DIR__ . '/views', 'seo-manager'); |
||||
21 | |||||
22 | $this->publishes([ |
||||
23 | __DIR__ . '/config/seo-manager.php' => config_path('seo-manager.php'), |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
24 | ], 'config'); |
||||
25 | |||||
26 | $this->publishes([ |
||||
27 | __DIR__ . '/assets' => public_path('vendor/lionix'), |
||||
0 ignored issues
–
show
The function
public_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
![]() |
|||||
28 | ], 'assets'); |
||||
29 | |||||
30 | $this->commands([ |
||||
31 | GenerateSeoManagerData::class |
||||
32 | ]); |
||||
33 | |||||
34 | $this->registerHelpers(); |
||||
35 | $router = $this->app['router']; |
||||
36 | $router->pushMiddlewareToGroup('web', \Lionix\SeoManager\Middleware\ClearViewCache::class); |
||||
37 | |||||
38 | if (config('seo-manager.shared_meta_data')) { |
||||
0 ignored issues
–
show
The function
config 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
![]() |
|||||
39 | $router->pushMiddlewareToGroup('web', \Lionix\SeoManager\Middleware\SeoManager::class); |
||||
40 | } |
||||
41 | |||||
42 | // Blade Directives |
||||
43 | $this->registerBladeDirectives(); |
||||
44 | } |
||||
45 | |||||
46 | /** |
||||
47 | * Register services. |
||||
48 | * |
||||
49 | * @return void |
||||
50 | */ |
||||
51 | public function register() |
||||
52 | { |
||||
53 | $this->mergeConfigFrom( |
||||
54 | __DIR__ . '/config/seo-manager.php', 'seo-manager' |
||||
55 | ); |
||||
56 | $this->app->bind('seomanager', function () { |
||||
57 | return new SeoManager(); |
||||
58 | }); |
||||
59 | $this->app->alias('seomanager', SeoManager::class); |
||||
60 | } |
||||
61 | |||||
62 | /** |
||||
63 | * Register helpers file |
||||
64 | */ |
||||
65 | public function registerHelpers() |
||||
66 | { |
||||
67 | // Load the helpers |
||||
68 | if (file_exists($file = __DIR__ . '/helpers/helpers.php')) { |
||||
69 | require $file; |
||||
70 | } |
||||
71 | } |
||||
72 | |||||
73 | /** |
||||
74 | * Register Blade Directives |
||||
75 | */ |
||||
76 | public function registerBladeDirectives() |
||||
77 | { |
||||
78 | $names = [ |
||||
79 | 'keywords', |
||||
80 | 'url', |
||||
81 | 'author', |
||||
82 | 'description', |
||||
83 | 'title', |
||||
84 | ]; |
||||
85 | |||||
86 | Blade::directive('meta', function ($expression) use ($names) { |
||||
87 | $meta = ''; |
||||
88 | $expression = trim($expression, '\"\''); |
||||
89 | $metaData = metaData($expression); |
||||
90 | $type = in_array($expression, $names) ? "name" : "property"; |
||||
91 | |||||
92 | if (is_array($metaData)) { |
||||
93 | foreach ($metaData as $key => $og) { |
||||
94 | $type = in_array($key, $names) ? "name" : "property"; |
||||
95 | |||||
96 | $meta .= "<meta {$type}='{$key}' content='{$og}'/>\n"; |
||||
97 | } |
||||
98 | } else { |
||||
99 | $meta .= "<meta {$type}='{$expression}' content='{$metaData}'/>\n"; |
||||
100 | } |
||||
101 | return $meta; |
||||
102 | }); |
||||
103 | Blade::directive('keywords', function () { |
||||
104 | return "<meta name='keywords' content='" . metaKeywords() . "'/>\n"; |
||||
105 | }); |
||||
106 | Blade::directive('url', function () { |
||||
107 | return "<meta name='url' content='" . metaUrl() . "'/>\n"; |
||||
108 | }); |
||||
109 | Blade::directive('author', function () { |
||||
110 | return "<meta name='author' content='" . metaAuthor() . "'/>\n"; |
||||
111 | }); |
||||
112 | Blade::directive('description', function () { |
||||
113 | return "<meta name='description' content='" . metaDescription() . "'/>\n"; |
||||
114 | }); |
||||
115 | Blade::directive('title', function () { |
||||
116 | return "<meta name='title' content='" . metaTitle() . "'/>\n"; |
||||
117 | }); |
||||
118 | Blade::directive('openGraph', function ($expression) { |
||||
119 | $expression = trim($expression, '\"\''); |
||||
120 | $meta = ''; |
||||
121 | $metaOpenGraph = metaOpenGraph($expression); |
||||
122 | if (is_array($metaOpenGraph)) { |
||||
123 | foreach ($metaOpenGraph as $key => $og) { |
||||
124 | $meta .= "<meta property='{$key}' content='{$og}'/>\n"; |
||||
125 | } |
||||
126 | } else { |
||||
127 | $meta .= "<meta property='{$expression}' content='{$metaOpenGraph}'/>\n"; |
||||
128 | } |
||||
129 | return $meta; |
||||
130 | }); |
||||
131 | Blade::directive('titleDynamic', function () { |
||||
132 | return metaTitleDynamic(); |
||||
133 | }); |
||||
134 | } |
||||
135 | |||||
136 | } |
||||
137 |