1 | <?php |
||||||
2 | |||||||
3 | namespace Cion\LaravelCloudflare; |
||||||
4 | |||||||
5 | use Illuminate\Support\Collection; |
||||||
6 | use GuzzleHttp\Client as GuzzleClient; |
||||||
7 | use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
||||||
8 | |||||||
9 | class ServiceProvider extends BaseServiceProvider |
||||||
10 | { |
||||||
11 | /** |
||||||
12 | * Indicates if loading of the provider is deferred. |
||||||
13 | * |
||||||
14 | * @var bool |
||||||
15 | */ |
||||||
16 | protected $defer = true; |
||||||
17 | |||||||
18 | /** |
||||||
19 | * Bootstrap the application services. |
||||||
20 | */ |
||||||
21 | public function boot() |
||||||
22 | { |
||||||
23 | $this->publishes([ |
||||||
24 | __DIR__.'/../config/config.php' => config_path('cloudflare.php'), |
||||||
25 | ], 'config'); |
||||||
26 | } |
||||||
27 | |||||||
28 | public function register() |
||||||
29 | { |
||||||
30 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'cloudflare'); |
||||||
31 | |||||||
32 | $this->registerClient(); |
||||||
33 | $this->registerCommands(); |
||||||
34 | $this->registerMacros(); |
||||||
35 | } |
||||||
36 | |||||||
37 | protected function registerClient() |
||||||
38 | { |
||||||
39 | $this->app->bind(Client::class, function () { |
||||||
40 | return new Client( |
||||||
41 | $this->bootGuzzleClient(), |
||||||
42 | $this->app['log'] |
||||||
43 | ); |
||||||
44 | }); |
||||||
45 | } |
||||||
46 | |||||||
47 | protected function bootGuzzleClient() |
||||||
48 | { |
||||||
49 | $config = $this->app['config']['cloudflare']; |
||||||
50 | |||||||
51 | return new GuzzleClient([ |
||||||
52 | 'base_uri' => Client::BASE_URI, |
||||||
53 | \GuzzleHttp\RequestOptions::HEADERS => [ |
||||||
54 | 'X-Auth-Key' => $config['key'], |
||||||
55 | 'X-Auth-Email' => $config['email'], |
||||||
56 | ], |
||||||
57 | ]); |
||||||
58 | } |
||||||
59 | |||||||
60 | protected function registerCommands() |
||||||
61 | { |
||||||
62 | $this->app->bind(Commands\Cache\Purge::class, function () { |
||||||
63 | return new Commands\Cache\Purge( |
||||||
64 | $this->app[Client::class], |
||||||
65 | $this->app['config']['cloudflare.zones'] |
||||||
66 | ); |
||||||
67 | }); |
||||||
68 | |||||||
69 | $this->commands([ |
||||||
70 | Commands\Cache\Purge::class, |
||||||
71 | ]); |
||||||
72 | } |
||||||
73 | |||||||
74 | protected function registerMacros() |
||||||
75 | { |
||||||
76 | /* |
||||||
77 | * Transpose with keys. |
||||||
78 | * |
||||||
79 | * Implementation for PHP < 5.6 and Laravel ~5.1. |
||||||
80 | * |
||||||
81 | * @return \Illuminate\Support\Collection |
||||||
82 | */ |
||||||
83 | Collection::macro('_transpose', function () { |
||||||
84 | $keys = $this->keys()->all(); |
||||||
0 ignored issues
–
show
|
|||||||
85 | |||||||
86 | $params = array_merge([function () use ($keys) { |
||||||
87 | return new static(array_combine($keys, func_get_args())); |
||||||
0 ignored issues
–
show
array_combine($keys, func_get_args()) of type array|false is incompatible with the type Illuminate\Contracts\Foundation\Application expected by parameter $app of Cion\LaravelCloudflare\S...Provider::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
88 | }], $this->toArray()); |
||||||
0 ignored issues
–
show
The method
toArray() does not exist on Cion\LaravelCloudflare\ServiceProvider .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
89 | |||||||
90 | return new static(call_user_func_array('array_map', $params)); |
||||||
91 | }); |
||||||
92 | |||||||
93 | /* |
||||||
94 | * Add a value between each item. |
||||||
95 | * |
||||||
96 | * @param mixed $value |
||||||
97 | * @return \Illuminate\Support\Collection |
||||||
98 | */ |
||||||
99 | Collection::macro('insertBetween', function ($value) { |
||||||
100 | return $this->values()->flatMap(function ($item, $index) use ($value) { |
||||||
0 ignored issues
–
show
The method
values() does not exist on Cion\LaravelCloudflare\ServiceProvider .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
101 | return [$index ? $value : null, $item]; |
||||||
102 | })->forget(0)->values(); |
||||||
103 | }); |
||||||
104 | |||||||
105 | /* |
||||||
106 | * Reorder the collection according to an array of keys |
||||||
107 | * |
||||||
108 | * @param mixed $keys |
||||||
109 | * @return \Illuminate\Support\Collection |
||||||
110 | */ |
||||||
111 | Collection::macro('reorder', function ($keys) { |
||||||
112 | $order = $this->getArrayableItems($keys); |
||||||
0 ignored issues
–
show
The method
getArrayableItems() does not exist on Cion\LaravelCloudflare\ServiceProvider .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
113 | |||||||
114 | return $this->sortBy(function ($item, $key) use ($order) { |
||||||
0 ignored issues
–
show
The method
sortBy() does not exist on Cion\LaravelCloudflare\ServiceProvider .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
115 | return array_search($key, $order); |
||||||
116 | }); |
||||||
117 | }); |
||||||
118 | } |
||||||
119 | |||||||
120 | /** |
||||||
121 | * Get the services provided by the provider. |
||||||
122 | * |
||||||
123 | * @return array |
||||||
124 | */ |
||||||
125 | public function provides() |
||||||
126 | { |
||||||
127 | return [ |
||||||
128 | Client::class, |
||||||
129 | Commands\Cache\Purge::class, |
||||||
130 | ]; |
||||||
131 | } |
||||||
132 | } |
||||||
133 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.