1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Telegram\Bot\Laravel; |
4
|
|
|
|
5
|
|
|
use Telegram\Bot\Api; |
6
|
|
|
use Telegram\Bot\BotsManager; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Illuminate\Contracts\Container\Container as Application; |
9
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
10
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class TelegramServiceProvider. |
14
|
|
|
*/ |
15
|
|
|
class TelegramServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Indicates if loading of the provider is deferred. |
19
|
|
|
* |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $defer = true; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Boot the service provider. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function boot() |
30
|
|
|
{ |
31
|
|
|
$this->setupConfig($this->app); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Setup the config. |
36
|
|
|
* |
37
|
|
|
* @param \Illuminate\Contracts\Container\Container $app |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
protected function setupConfig(Application $app) |
42
|
|
|
{ |
43
|
|
|
$source = __DIR__.'/config/telegram.php'; |
44
|
|
|
|
45
|
|
|
if ($app instanceof LaravelApplication && $app->runningInConsole()) { |
|
|
|
|
46
|
|
|
$this->publishes([$source => config_path('telegram.php')], 'config'); |
47
|
|
|
} elseif ($app instanceof LumenApplication) { |
|
|
|
|
48
|
|
|
$app->configure('telegram'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->mergeConfigFrom($source, 'telegram'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Register the service provider. |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function register() |
60
|
|
|
{ |
61
|
|
|
$this->registerManager($this->app); |
62
|
|
|
$this->registerBindings($this->app); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Register the manager class. |
67
|
|
|
* |
68
|
|
|
* @param \Illuminate\Contracts\Container\Container $app |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
protected function registerManager(Application $app) |
73
|
|
|
{ |
74
|
|
|
$app->singleton('telegram', function ($app) { |
75
|
|
|
$config = (array)$app['config']['telegram']; |
76
|
|
|
|
77
|
|
|
return (new BotsManager($config))->setContainer($app); |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
$app->alias('telegram', BotsManager::class); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Register the bindings. |
85
|
|
|
* |
86
|
|
|
* @param \Illuminate\Contracts\Container\Container $app |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
protected function registerBindings(Application $app) |
91
|
|
|
{ |
92
|
|
|
$app->bind('telegram.bot', function ($app) { |
93
|
|
|
$manager = $app['telegram']; |
94
|
|
|
|
95
|
|
|
return $manager->bot(); |
96
|
|
|
}); |
97
|
|
|
|
98
|
|
|
$app->alias('telegram.bot', Api::class); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the services provided by the provider. |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
public function provides() |
107
|
|
|
{ |
108
|
|
|
return ['telegram', 'telegram.bot', BotsManager::class, Api::class]; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.