Total Complexity | 4 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class ServiceProvider extends BaseServiceProvider |
||
9 | { |
||
10 | /** |
||
11 | * Bootstrap the application services. |
||
12 | */ |
||
13 | 12 | public function boot() |
|
14 | { |
||
15 | 12 | $this->publishes([__DIR__.'/../config/' => config_path()], 'config'); |
|
16 | |||
17 | 12 | $this->registerResponseMacro($this->getResponseMacroName()); |
|
18 | } |
||
19 | |||
20 | /** |
||
21 | * Register the application services. |
||
22 | */ |
||
23 | 12 | public function register() |
|
24 | { |
||
25 | 12 | $this->mergeConfigFrom(__DIR__.'/../config/javascript-data-response.php', 'javascript-data-response'); |
|
26 | |||
27 | 12 | $this->app->singleton(Builder::class); |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * Response macro for JavaScript data. |
||
32 | * |
||
33 | * @param string $name |
||
34 | */ |
||
35 | 12 | protected function registerResponseMacro(string $name) |
|
36 | { |
||
37 | 12 | Response::macro( |
|
38 | 12 | $name, |
|
39 | /** |
||
40 | * Return a new JavaScript data response from the application. |
||
41 | * |
||
42 | * @param string $name |
||
43 | * @param mixed $data |
||
44 | * @param int $status |
||
45 | * @param array $headers |
||
46 | * @param int $options |
||
47 | * |
||
48 | * @return \Illuminate\Http\Response |
||
49 | */ |
||
50 | 12 | function (string $name, $data = [], int $status = 200, array $headers = [], $options = 0) { |
|
51 | 4 | $builder = app(Builder::class); |
|
52 | 4 | $factory = new ResponseFactory(/* @scrutinizer ignore-type */ $this, $builder); |
|
53 | |||
54 | 4 | return $factory->make($name, $data, $status, $headers, $options); |
|
55 | 12 | } |
|
56 | 12 | ); |
|
57 | } |
||
58 | |||
59 | 12 | protected function getResponseMacroName(): string |
|
62 | } |
||
63 | } |
||
64 |