|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Copper package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Richard Browne <[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 Copper\Laravel; |
|
13
|
|
|
|
|
14
|
|
|
use Copper\Copper; |
|
15
|
|
|
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; |
|
16
|
|
|
use Illuminate\Events\Dispatcher; |
|
17
|
|
|
use Illuminate\Events\EventDispatcher; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* A simple API extension for NumberFormatter. |
|
21
|
|
|
*/ |
|
22
|
|
|
class ServiceProvider extends \Illuminate\Support\ServiceProvider |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Service provider boot loader. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function boot() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->updateLocale(); |
|
32
|
|
|
|
|
33
|
|
|
if (false === $this->app->bound('events')) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$service = $this; |
|
38
|
|
|
$events = $this->app['events']; |
|
39
|
|
|
|
|
40
|
|
|
if (true === $this->isEventDispatcher($events)) { |
|
41
|
|
|
$events->listen( |
|
42
|
|
|
(true === class_exists('Illuminate\Foundation\Events\LocaleUpdated')) ? 'Illuminate\Foundation\Events\LocaleUpdated' : 'locale.changed', |
|
43
|
|
|
function () use ($service) { |
|
44
|
|
|
$service->updateLocale(); |
|
45
|
|
|
} |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Function to update the locale used by Copper. |
|
52
|
|
|
* |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
public function updateLocale() |
|
56
|
|
|
{ |
|
57
|
|
|
$app = $this->app; |
|
58
|
|
|
$locale = $app->getLocale(); |
|
59
|
|
|
Copper::setLocale($locale); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Registration function for Laravel <5.3. |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function register() |
|
68
|
|
|
{ |
|
69
|
|
|
// Needed for Laravel < 5.3 compatibility |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Check function for Event Dispatcher. |
|
74
|
|
|
* |
|
75
|
|
|
* @param Illuminate\Contracts\Events\Dispatcher|Illuminate\Events\Dispatcher|Illuminate\Events\EventDispatcher $instance Event dispatcher |
|
76
|
|
|
* |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function isEventDispatcher($instance) |
|
80
|
|
|
{ |
|
81
|
|
|
return $instance instanceof EventDispatcher |
|
|
|
|
|
|
82
|
|
|
|| $instance instanceof Dispatcher |
|
83
|
|
|
|| $instance instanceof DispatcherContract; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto 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
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.