1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yoeunes\Notify; |
4
|
|
|
|
5
|
|
|
use Illuminate\Container\Container; |
6
|
|
|
use Illuminate\Support\Facades\Blade; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
9
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
10
|
|
|
|
11
|
|
|
class NotifyServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Bootstrap the application events. |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
public function boot() |
19
|
|
|
{ |
20
|
|
|
$source = realpath($raw = __DIR__.'/../config/notify.php') ?: $raw; |
21
|
|
|
|
22
|
|
|
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { |
23
|
|
|
$this->publishes([$source => config_path('notify.php')], 'config'); |
24
|
|
|
} elseif ($this->app instanceof LumenApplication) { |
|
|
|
|
25
|
|
|
$this->app->configure('notify'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->mergeConfigFrom($source, 'notify'); |
29
|
|
|
|
30
|
|
|
$this->registerBladeDirectives(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Register the service provider. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function register() |
39
|
|
|
{ |
40
|
|
|
if ($this->app instanceof LumenApplication) { |
|
|
|
|
41
|
|
|
$this->app->register(\Illuminate\Session\SessionServiceProvider::class); |
42
|
|
|
$this->app->configure('session'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->registerNotify(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function registerNotify() |
49
|
|
|
{ |
50
|
|
|
$this->app->singleton('notify', function (Container $app) { |
51
|
|
|
return new Notify(NotifierFactory::make($app['config']['notify']), $app['session'], $app['config']); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$this->app->alias('notify', Notify::class); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function registerBladeDirectives() |
58
|
|
|
{ |
59
|
|
|
Blade::directive('notify_render', function () { |
60
|
|
|
return "<?php echo app('notify')->render(); ?>"; |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
Blade::directive('notify_css', function () { |
64
|
|
|
return '<?php echo notify_css(); ?>'; |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
Blade::directive('notify_js', function () { |
68
|
|
|
return '<?php echo notify_js(); ?>'; |
69
|
|
|
}); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the services provided by the provider. |
74
|
|
|
* |
75
|
|
|
* @return string[] |
76
|
|
|
*/ |
77
|
|
|
public function provides(): array |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
'notify', |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.