Issues (24)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/ResponderServiceProvider.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Flugg\Responder;
4
5
use Flugg\Responder\Console\MakeTransformer;
6
use Flugg\Responder\Contracts\ErrorFactory as ErrorFactoryContract;
7
use Flugg\Responder\Contracts\ErrorMessageResolver as ErrorMessageResolverContract;
8
use Flugg\Responder\Contracts\ErrorSerializer as ErrorSerializerContract;
9
use Flugg\Responder\Contracts\Pagination\PaginatorFactory as PaginatorFactoryContract;
10
use Flugg\Responder\Contracts\Resources\ResourceFactory as ResourceFactoryContract;
11
use Flugg\Responder\Contracts\Resources\ResourceKeyResolver as ResourceKeyResolverContract;
12
use Flugg\Responder\Contracts\Responder as ResponderContract;
13
use Flugg\Responder\Contracts\ResponseFactory;
14
use Flugg\Responder\Contracts\ResponseFactory as ResponseFactoryContract;
15
use Flugg\Responder\Contracts\SimpleTransformer as SimpleTransformerContract;
16
use Flugg\Responder\Contracts\Transformers\TransformerResolver as TransformerResolverContract;
17
use Flugg\Responder\Contracts\TransformFactory as TransformFactoryContract;
18
use Flugg\Responder\Http\Responses\ErrorResponseBuilder;
19
use Flugg\Responder\Http\Responses\Factories\LaravelResponseFactory;
20
use Flugg\Responder\Http\Responses\Factories\LumenResponseFactory;
21
use Flugg\Responder\Pagination\PaginatorFactory;
22
use Flugg\Responder\Resources\ResourceFactory;
23
use Flugg\Responder\Resources\ResourceKeyResolver;
24
use Flugg\Responder\Transformers\Transformer as BaseTransformer;
25
use Flugg\Responder\Transformers\TransformerResolver;
26
use Illuminate\Contracts\Container\Container;
27
use Illuminate\Foundation\Application as Laravel;
28
use Illuminate\Http\Request;
29
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
30
use Illuminate\Translation\Translator;
31
use Laravel\Lumen\Application as Lumen;
32
use League\Fractal\Manager;
33
use League\Fractal\Serializer\SerializerAbstract;
34
35
/**
36
 * A service provider class responsible for bootstrapping the parts of the Laravel package.
37
 *
38
 * @package flugger/laravel-responder
39
 * @author  Alexander TømmerÃ¥s <[email protected]>
40
 * @license The MIT License
41
 */
42
class ResponderServiceProvider extends BaseServiceProvider
43
{
44
    /**
45
     * Indicates if loading of the provider is deferred.
46
     *
47
     * @var bool
48
     */
49
    protected $defer = false;
50
51
    /**
52
     * Register the service provider.
53
     *
54
     * @return void
55
     */
56 192
    public function register()
57
    {
58 192
        if ($this->app instanceof Laravel) {
59 192
            $this->registerLaravelBindings();
60
        } elseif ($this->app instanceof Lumen) {
0 ignored issues
show
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

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 the composer.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 or require-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 ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
61
            $this->registerLumenBindings();
62
        }
63
64 192
        $this->registerSerializerBindings();
65 192
        $this->registerErrorBindings();
66 192
        $this->registerFractalBindings();
67 192
        $this->registerTransformerBindings();
68 192
        $this->registerResourceBindings();
69 192
        $this->registerPaginationBindings();
70 192
        $this->registerTransformationBindings();
71 192
        $this->registerServiceBindings();
72 192
    }
73
74
    /**
75
     * Register Laravel bindings.
76
     *
77
     * @return void
78
     */
79 192
    protected function registerLaravelBindings()
80
    {
81
        $this->app->singleton(ResponseFactoryContract::class, function ($app) {
82 55
            return $this->decorateResponseFactory($app->make(LaravelResponseFactory::class));
83 192
        });
84 192
    }
85
86
    /**
87
     * Register Lumen bindings.
88
     *
89
     * @return void
90
     */
91
    protected function registerLumenBindings()
92
    {
93
        $this->app->singleton(ResponseFactoryContract::class, function ($app) {
94
            return $this->decorateResponseFactory($app->make(LumenResponseFactory::class));
95
        });
96
97
        $this->app->bind(Translator::class, function ($app) {
98
            return $app['translator'];
99
        });
100
    }
101
102
    /**
103
     * Decorate response factories.
104
     *
105
     * @param  \Flugg\Responder\Contracts\ResponseFactory $factory
106
     * @return \Flugg\Responder\Contracts\ResponseFactory
107
     */
108 55
    protected function decorateResponseFactory(ResponseFactoryContract $factory): ResponseFactory
109
    {
110 55
        foreach ($this->app->config['responder.decorators'] as $decorator) {
111 55
            $factory = new $decorator($factory);
112
        };
113
114 55
        return $factory;
115
    }
116
117
    /**
118
     * Register serializer bindings.
119
     *
120
     * @return void
121
     */
122 192
    protected function registerSerializerBindings()
123
    {
124
        $this->app->bind(ErrorSerializerContract::class, function ($app) {
125 55
            return $app->make($app->config['responder.serializers.error']);
126 192
        });
127
128
        $this->app->bind(SerializerAbstract::class, function ($app) {
129 55
            return $app->make($app->config['responder.serializers.success']);
130 192
        });
131 192
    }
132
133
    /**
134
     * Register error bindings.
135
     *
136
     * @return void
137
     */
138 192
    protected function registerErrorBindings()
139
    {
140
        $this->app->singleton(ErrorMessageResolverContract::class, function ($app) {
141 55
            return $app->make(ErrorMessageResolver::class);
142 192
        });
143
144
        $this->app->singleton(ErrorFactoryContract::class, function ($app) {
145 55
            return $app->make(ErrorFactory::class);
146 192
        });
147
148
        $this->app->bind(ErrorResponseBuilder::class, function ($app) {
149 55
            return (new ErrorResponseBuilder($app->make(ResponseFactoryContract::class), $app->make(ErrorFactoryContract::class)))->serializer($app->make(ErrorSerializerContract::class));
150 192
        });
151 192
    }
152
153
    /**
154
     * Register Fractal bindings.
155
     *
156
     * @return void
157
     */
158 192
    protected function registerFractalBindings()
159
    {
160
        $this->app->bind(Manager::class, function ($app) {
161 55
            return (new Manager)->setRecursionLimit($app->config['responder.recursion_limit']);
162 192
        });
163 192
    }
164
165
    /**
166
     * Register transformer bindings.
167
     *
168
     * @return void
169
     */
170 192
    protected function registerTransformerBindings()
171
    {
172
        $this->app->singleton(TransformerResolverContract::class, function ($app) {
173 57
            return new TransformerResolver($app, $app->config['responder.fallback_transformer']);
174 192
        });
175
176
        BaseTransformer::containerResolver(function () {
177 22
            return $this->app->make(Container::class);
178 192
        });
179 192
    }
180
181
    /**
182
     * Register pagination bindings.
183
     *
184
     * @return void
185
     */
186 192
    protected function registerResourceBindings()
187
    {
188
        $this->app->singleton(ResourceKeyResolverContract::class, function ($app) {
189 57
            return $app->make(ResourceKeyResolver::class);
190 192
        });
191
192
        $this->app->singleton(ResourceFactoryContract::class, function ($app) {
193 57
            return $app->make(ResourceFactory::class);
194 192
        });
195 192
    }
196
197
    /**
198
     * Register pagination bindings.
199
     *
200
     * @return void
201
     */
202 192
    protected function registerPaginationBindings()
203
    {
204
        $this->app->bind(PaginatorFactoryContract::class, function ($app) {
205 55
            return new PaginatorFactory($app->make(Request::class)->query());
206 192
        });
207 192
    }
208
209
    /**
210
     * Register transformation bindings.
211
     *
212
     * @return void
213
     */
214 192
    protected function registerTransformationBindings()
215
    {
216
        $this->app->bind(TransformFactoryContract::class, function ($app) {
217 55
            return $app->make(FractalTransformFactory::class);
218 192
        });
219
220
        $this->app->bind(TransformBuilder::class, function ($app) {
221 55
            $request = $this->app->make(Request::class);
222 55
            $relations = $request->input($this->app->config['responder.load_relations_parameter'], []);
223 55
            $fieldsets = $request->input($app->config['responder.filter_fields_parameter'], []);
224
225 55
            return (new TransformBuilder($app->make(ResourceFactoryContract::class), $app->make(TransformFactoryContract::class), $app->make(PaginatorFactoryContract::class)))->serializer($app->make(SerializerAbstract::class))
226 55
                ->with(is_string($relations) ? explode(',', $relations) : $relations)
227 55
                ->only($fieldsets);
228 192
        });
229 192
    }
230
231
    /**
232
     * Register service bindings.
233
     *
234
     * @return void
235
     */
236 192
    protected function registerServiceBindings()
237
    {
238
        $this->app->bind(ResponderContract::class, function ($app) {
239 54
            return $app->make(Responder::class);
240 192
        });
241 192
    }
242
243
    /**
244
     * Bootstrap the application events.
245
     *
246
     * @return void
247
     */
248 192
    public function boot()
249
    {
250 192
        if ($this->app instanceof Laravel) {
251 192
            $this->bootLaravelApplication();
252
        } elseif ($this->app instanceof Lumen) {
0 ignored issues
show
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

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 the composer.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 or require-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 ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
253
            $this->bootLumenApplication();
254
        }
255
256 192
        $this->mergeConfigFrom(__DIR__ . '/../config/responder.php', 'responder');
257 192
        $this->commands(MakeTransformer::class);
258 192
    }
259
260
    /**
261
     * Bootstrap the Laravel application.
262
     *
263
     * @return void
264
     */
265 192
    protected function bootLaravelApplication()
266
    {
267 192
        if ($this->app->runningInConsole()) {
268 192
            $this->publishes([
269 192
                __DIR__ . '/../config/responder.php' => config_path('responder.php'),
270 192
            ], 'config');
271 192
            $this->publishes([
272 192
                __DIR__ . '/../resources/lang/en/errors.php' => base_path('resources/lang/en/errors.php'),
273 192
            ], 'lang');
274
        }
275 192
    }
276
277
    /**
278
     * Bootstrap the Lumen application.
279
     *
280
     * @return void
281
     */
282
    protected function bootLumenApplication()
283
    {
284
        $this->app->configure('responder');
0 ignored issues
show
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean registerConfiguredProviders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
285
    }
286
}