Issues (29)

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/Services/Modular.php (1 issue)

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 Mnabialek\LaravelModular\Services;
4
5
use Illuminate\Database\Seeder;
6
use Illuminate\Support\Collection;
7
use Illuminate\Contracts\Routing\Registrar;
8
use Mnabialek\LaravelModular\Models\Module;
9
use Mnabialek\LaravelModular\Traits\Replacer;
10
use Mnabialek\LaravelModular\Traits\Normalizer;
11
use Illuminate\Contracts\Foundation\Application;
12
13
class Modular
14
{
15
    use Replacer;
16
    use Normalizer;
17
18
    /**
19
     * @var Application
20
     */
21
    protected $app;
22
23
    /**
24
     * @var Collection|null
25
     */
26
    protected $modules = null;
27
28
    /**
29
     * @var Config
30
     */
31
    protected $config;
32
33
    /**
34
     * Modular constructor.
35
     *
36
     * @param Application $app
37
     * @param Config $config
38
     */
39
    public function __construct(Application $app, Config $config)
40
    {
41
        $this->app = $app;
42
        $this->config = $config;
43
    }
44
45
    /**
46
     * Runs main seeders for all active modules
47
     *
48
     * @param Seeder $seeder
49
     */
50
    public function seed(Seeder $seeder)
51
    {
52
        $this->withSeeders()->each(function ($module) use ($seeder) {
53
            /* @var Module $module */
54
            $seeder->call($module->seederClass());
55
        });
56
    }
57
58
    /**
59
     * Load routes for active modules
60
     *
61
     * @param Registrar $router
62
     * @param string|null $type
63
     */
64
    public function loadRoutes(Registrar $router, $type = null)
65
    {
66
        $this->withRoutes($type)->each(function ($module) use ($router, $type) {
67
            /* @var Module $module */
68
            $router->group(['namespace' => $module->routingControllerNamespace()],
69
                function ($router) use ($module, $type) {
0 ignored issues
show
The parameter $router is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
                    $this->app['files']->getRequire($this->app->basePath() .
71
                        DIRECTORY_SEPARATOR .
72
                        $module->routesFilePath($module->routePrefix(compact('type'))));
73
                });
74
        });
75
    }
76
77
    /**
78
     * Load factories for active modules
79
     *
80
     * @param $factory
81
     */
82
    public function loadFactories($factory)
83
    {
84
        $this->withFactories()->each(function ($module) use ($factory) {
85
            /* @var Module $module */
86
            $this->loadFactoryFile($this->app->basePath() . DIRECTORY_SEPARATOR .
87
                $module->factoryFilePath(), $factory);
88
        });
89
    }
90
91
    /**
92
     * Load file
93
     *
94
     * @param string $file
95
     * @param $factory
96
     *
97
     * @codeCoverageIgnore
98
     */
99
    protected function loadFactoryFile($file, $factory)
100
    {
101
        require $file;
102
    }
103
104
    /**
105
     * Load service providers for active modules
106
     */
107
    public function loadServiceProviders()
108
    {
109
        $this->withServiceProviders()->each(function ($module) {
110
            /* @var Module $module */
111
            $this->app->register($module->serviceProviderClass());
112
        });
113
    }
114
115
    /**
116
     * Get all routable modules (active and having routes file)
117
     *
118
     * @param string $type
119
     *
120
     * @return array
121
     */
122
    public function withRoutes($type)
123
    {
124
        return $this->filterActiveByMethod('hasRoutes', compact('type'));
125
    }
126
127
    /**
128
     * Get all routable modules (active and having routes file)
129
     *
130
     * @return array
131
     */
132
    public function withFactories()
133
    {
134
        return $this->filterActiveByMethod('hasFactory');
135
    }
136
137
    /**
138
     * Get all modules that have service providers (active and having service
139
     * provider file)
140
     *
141
     * @return array
142
     */
143
    public function withServiceProviders()
144
    {
145
        return $this->filterActiveByMethod('hasServiceProvider');
146
    }
147
148
    /**
149
     * Get all modules that have seeders (active and having seeder file)
150
     *
151
     * @return array
152
     */
153
    public function withSeeders()
154
    {
155
        return $this->filterActiveByMethod('hasSeeder');
156
    }
157
158
    /**
159
     * Get active modules that also pass given requirement
160
     *
161
     * @param string $requirement
162
     *
163
     * @param array $data
164
     *
165
     * @return Collection
166
     */
167
    protected function filterActiveByMethod($requirement, array $data = [])
168
    {
169
        return $this->modules()
170
            ->filter(function ($module) use ($requirement, $data) {
171
                return $module->active() && $module->$requirement($data);
172
            })->values();
173
    }
174
175
    /**
176
     * Get all modules
177
     *
178
     * @return Collection
179
     */
180
    public function all()
181
    {
182
        return $this->modules();
183
    }
184
185
    /**
186
     * Get active modules
187
     *
188
     * @return Collection
189
     */
190
    public function active()
191
    {
192
        return $this->modules()->filter(function ($module) {
193
            return $module->active();
194
        })->values();
195
    }
196
197
    /**
198
     * Load modules (if not loaded) and get modules
199
     *
200
     * @return Collection
201
     */
202
    protected function modules()
203
    {
204
        if ($this->modules === null) {
205
            $this->loadModules();
206
        }
207
208
        return $this->modules;
209
    }
210
211
    /**
212
     * Load modules from config
213
     */
214
    protected function loadModules()
215
    {
216
        $this->modules = collect();
217
218
        collect($this->config->modules())->each(function ($options, $name) {
219
            $this->modules->push(new Module($name, $this->app, $options));
220
        });
221
    }
222
223
    /**
224
     * Find given module by name
225
     *
226
     * @param string $name
227
     *
228
     * @return Module
229
     */
230
    public function find($name)
231
    {
232
        return $this->modules()->first(function ($module) use ($name) {
233
            /* @var Module $module */
234
            return $module->name() == $name;
235
        });
236
    }
237
238
    /**
239
     * Verify whether module with given name already exists
240
     *
241
     * @param $name
242
     *
243
     * @return bool
244
     */
245
    public function exists($name)
246
    {
247
        return $this->find($name) !== null;
248
    }
249
}
250