|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\Fractal; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
|
|
|
|
|
|
9
|
|
|
use Spatie\Fractal\Console\Commands\TransformerMakeCommand; |
|
10
|
|
|
|
|
11
|
|
|
class FractalServiceProvider extends ServiceProvider |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Bootstrap the application services. |
|
15
|
|
|
*/ |
|
16
|
228 |
|
public function boot() |
|
17
|
|
|
{ |
|
18
|
228 |
|
$this->setupConfig(); |
|
19
|
|
|
|
|
20
|
228 |
|
if ($this->app->runningInConsole()) { |
|
21
|
228 |
|
$this->commands([ |
|
22
|
228 |
|
TransformerMakeCommand::class, |
|
23
|
|
|
]); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
228 |
|
$this->setupMacro(); |
|
27
|
228 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Register the application services. |
|
31
|
|
|
*/ |
|
32
|
190 |
|
public function register() |
|
33
|
|
|
{ |
|
34
|
38 |
|
$this->app->singleton('fractal', function ($app, $arguments) { |
|
35
|
48 |
|
return fractal(...$arguments); |
|
|
|
|
|
|
36
|
228 |
|
}); |
|
37
|
|
|
|
|
38
|
228 |
|
$this->app->alias('fractal', Fractal::class); |
|
39
|
228 |
|
} |
|
40
|
|
|
|
|
41
|
228 |
|
protected function setupConfig() |
|
42
|
|
|
{ |
|
43
|
228 |
|
$source = realpath(__DIR__.'/../config/fractal.php'); |
|
44
|
|
|
|
|
45
|
228 |
|
if ($this->app instanceof LaravelApplication) { |
|
46
|
228 |
|
$this->publishes([$source => config_path('fractal.php')]); |
|
47
|
|
|
} elseif ($this->app instanceof LumenApplication) { |
|
48
|
|
|
$this->app->configure('fractal'); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
228 |
|
$this->mergeConfigFrom($source, 'fractal'); |
|
52
|
228 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Add a 'transformWith' macro to Laravel's collection. |
|
56
|
|
|
*/ |
|
57
|
38 |
|
protected function setupMacro() |
|
58
|
|
|
{ |
|
59
|
190 |
|
Collection::macro('transformWith', function ($transformer) { |
|
60
|
6 |
|
return fractal($this, $transformer); |
|
61
|
228 |
|
}); |
|
62
|
228 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths