1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Caspeco. |
5
|
|
|
* |
6
|
|
|
(c) HOY Multimedia AB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Hoy\Caspeco; |
13
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Container\Container; |
15
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
16
|
|
|
use Illuminate\Support\ServiceProvider; |
17
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This is the Caspeco service provider class. |
21
|
|
|
* |
22
|
|
|
* @author Vincent Klaiber <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class CaspecoServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Boot the service provider. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function boot() |
32
|
|
|
{ |
33
|
|
|
$this->setupConfig(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Setup the config. |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
protected function setupConfig() |
42
|
|
|
{ |
43
|
|
|
$source = realpath(__DIR__.'/../config/caspeco.php'); |
44
|
|
|
|
45
|
|
|
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { |
46
|
|
|
$this->publishes([$source => config_path('caspeco.php')]); |
47
|
|
|
} elseif ($this->app instanceof LumenApplication) { |
|
|
|
|
48
|
|
|
$this->app->configure('caspeco'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->mergeConfigFrom($source, 'caspeco'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Register the service provider. |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function register() |
60
|
|
|
{ |
61
|
|
|
$this->registerFactory(); |
62
|
|
|
$this->registerManager(); |
63
|
|
|
$this->registerBindings(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Register the factory class. |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
protected function registerFactory() |
72
|
|
|
{ |
73
|
|
|
$this->app->singleton('caspeco.factory', function () { |
74
|
|
|
return new CaspecoFactory(); |
75
|
|
|
}); |
76
|
|
|
|
77
|
|
|
$this->app->alias('caspeco.factory', CaspecoFactory::class); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Register the manager class. |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
protected function registerManager() |
86
|
|
|
{ |
87
|
|
|
$this->app->singleton('caspeco', function (Container $app) { |
88
|
|
|
$config = $app['config']; |
89
|
|
|
$factory = $app['caspeco.factory']; |
90
|
|
|
|
91
|
|
|
return new CaspecoManager($config, $factory); |
92
|
|
|
}); |
93
|
|
|
|
94
|
|
|
$this->app->alias('caspeco', CaspecoManager::class); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Register the bindings. |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
protected function registerBindings() |
103
|
|
|
{ |
104
|
|
|
$this->app->bind('caspeco.connection', function (Container $app) { |
105
|
|
|
$manager = $app['caspeco']; |
106
|
|
|
|
107
|
|
|
return $manager->connection(); |
108
|
|
|
}); |
109
|
|
|
|
110
|
|
|
$this->app->alias('caspeco.connection', Caspeco::class); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get the services provided by the provider. |
115
|
|
|
* |
116
|
|
|
* @return string[] |
117
|
|
|
*/ |
118
|
|
|
public function provides() |
119
|
|
|
{ |
120
|
|
|
return [ |
121
|
|
|
'caspeco', |
122
|
|
|
'caspeco.factory', |
123
|
|
|
'caspeco.connection', |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
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.