Passed
Push — master ( faedb3...dd9457 )
by Fran
02:57
created

Router::getExternalModules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PSFS\base;
3
4
use PSFS\base\config\Config;
5
use PSFS\base\dto\JsonResponse;
6
use PSFS\base\exception\AccessDeniedException;
7
use PSFS\base\exception\AdminCredentialsException;
8
use PSFS\base\exception\ConfigException;
9
use PSFS\base\exception\RouterException;
10
use PSFS\base\types\helpers\AdminHelper;
11
use PSFS\base\types\helpers\GeneratorHelper;
12
use PSFS\base\types\helpers\I18nHelper;
13
use PSFS\base\types\helpers\RouterHelper;
14
use PSFS\base\types\helpers\SecurityHelper;
15
use PSFS\base\types\traits\SingletonTrait;
16
use PSFS\controller\base\Admin;
17
use PSFS\services\AdminServices;
18
use Symfony\Component\Finder\Finder;
19
use Symfony\Component\Finder\SplFileInfo;
20
21
/**
22
 * Class Router
23
 * @package PSFS
24
 */
25
class Router
26
{
27
    use SingletonTrait;
28
29
    /**
30
     * @var array
31
     */
32
    protected $routing = [];
33
    /**
34
     * @var array
35
     */
36
    protected $slugs = [];
37
    /**
38
     * @var array
39
     */
40
    private $domains = [];
41
    /**
42
     * @var Finder $finder
43
     */
44
    private $finder;
45
    /**
46
     * @var \PSFS\base\Cache $cache
47
     */
48
    private $cache;
49
    /**
50
     * @var bool headersSent
51
     */
52
    protected $headersSent = false;
53
    /**
54
     * @var int
55
     */
56
    protected $cacheType = Cache::JSON;
57
58
    /**
59
     * Router constructor.
60
     * @throws exception\GeneratorException
61
     * @throws ConfigException
62
     * @throws \InvalidArgumentException
63
     */
64 1
    public function __construct()
65
    {
66 1
        $this->finder = new Finder();
67 1
        $this->cache = Cache::getInstance();
68 1
        $this->init();
69 1
    }
70
71
    /**
72
     * @throws exception\GeneratorException
73
     * @throws ConfigException
74
     * @throws \InvalidArgumentException
75
     */
76 1
    public function init()
77
    {
78 1
        list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE);
79 1
        if (empty($this->routing) || Config::getInstance()->getDebugMode()) {
80 1
            $this->debugLoad();
81
        } else {
82
            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE);
83
        }
84 1
        $this->checkExternalModules(false);
85 1
        $this->setLoaded();
86 1
    }
87
88
    /**
89
     * @throws exception\GeneratorException
90
     * @throws ConfigException
91
     * @throws \InvalidArgumentException
92
     */
93 1
    private function debugLoad() {
94 1
        Logger::log('Begin routes load');
95 1
        $this->hydrateRouting();
96 1
        $this->simpatize();
97 1
        Logger::log('End routes load');
98 1
    }
99
100
    /**
101
     * @param \Exception|NULL $exception
102
     * @param bool $isJson
103
     * @return string
104
     * @throws RouterException
105
     */
106
    public function httpNotFound(\Exception $exception = NULL, $isJson = false)
107
    {
108
        Logger::log('Throw not found exception');
109
        if (NULL === $exception) {
110
            Logger::log('Not found page thrown without previous exception', LOG_WARNING);
111
            $exception = new \Exception(_('Page not found'), 404);
112
        }
113
        $template = Template::getInstance()->setStatus($exception->getCode());
114
        if ($isJson || false !== stripos(Request::getInstance()->getServer('CONTENT_TYPE'), 'json')) {
115
            $response = new JsonResponse(null, false, 0, 0, $exception->getMessage());
116
            return $template->output(json_encode($response), 'application/json');
117
        }
118
119
        $notFoundRoute = Config::getParam('route.404');
120
        if(null !== $notFoundRoute) {
121
            Request::getInstance()->redirect($this->getRoute($notFoundRoute, true));
122
        } else {
123
            return $template->render('error.html.twig', array(
124
                'exception' => $exception,
125
                'trace' => $exception->getTraceAsString(),
126
                'error_page' => TRUE,
127
            ));
128
        }
129
    }
130
131
    /**
132
     * @return array
133
     */
134 1
    public function getSlugs()
135
    {
136 1
        return $this->slugs;
137
    }
138
139
    /**
140
     * @return array
141
     */
142 2
    public function getRoutes() {
143 2
        return $this->routing;
144
    }
145
146
    /**
147
     * Method that extract all routes in the platform
148
     * @return array
149
     */
150 1
    public function getAllRoutes()
151
    {
152 1
        $routes = [];
153 1
        foreach ($this->getRoutes() as $path => $route) {
154 1
            if (array_key_exists('slug', $route)) {
155 1
                $routes[$route['slug']] = $path;
156
            }
157
        }
158 1
        return $routes;
159
    }
160
161
    /**
162
     * @param string|null $route
163
     *
164
     * @throws \Exception
165
     * @return string HTML
166
     */
167 2
    public function execute($route)
168
    {
169 2
        Logger::log('Executing the request');
170
        try {
171
            //Search action and execute
172 2
            return $this->searchAction($route);
173 1
        } catch (AccessDeniedException $e) {
174
            Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']);
175
            return Admin::staticAdminLogon($route);
176 1
        } catch (RouterException $r) {
177 1
            Logger::log($r->getMessage(), LOG_WARNING);
178
        } catch (\Exception $e) {
179
            Logger::log($e->getMessage(), LOG_ERR);
180
            throw $e;
181
        }
182
183 1
        throw new RouterException(_('Página no encontrada'), 404);
184
    }
185
186
    /**
187
     * @param string $route
188
     * @return mixed
189
     * @throws AccessDeniedException
190
     * @throws AdminCredentialsException
191
     * @throws RouterException
192
     * @throws \Exception
193
     */
194 2
    protected function searchAction($route)
195
    {
196 2
        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
197
        //Revisamos si tenemos la ruta registrada
198 2
        $parts = parse_url($route);
199 2
        $path = array_key_exists('path', $parts) ? $parts['path'] : $route;
200 2
        $httpRequest = Request::getInstance()->getMethod();
201 2
        foreach ($this->routing as $pattern => $action) {
202 2
            list($httpMethod, $routePattern) = RouterHelper::extractHttpRoute($pattern);
203 2
            $matched = RouterHelper::matchRoutePattern($routePattern, $path);
204 2
            if ($matched && ($httpMethod === 'ALL' || $httpRequest === $httpMethod) && RouterHelper::compareSlashes($routePattern, $path)) {
205
                // Checks restricted access
206 1
                SecurityHelper::checkRestrictedAccess($route);
207 1
                $get = RouterHelper::extractComponents($route, $routePattern);
208
                /** @var $class \PSFS\base\types\Controller */
209 1
                $class = RouterHelper::getClassToCall($action);
210
                try {
211 1
                    if($this->checkRequirements($action, $get)) {
212 1
                        return $this->executeCachedRoute($route, $action, $class, $get);
0 ignored issues
show
Bug introduced by
$class of type PSFS\base\types\Controller is incompatible with the type string expected by parameter $class of PSFS\base\Router::executeCachedRoute(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

212
                        return $this->executeCachedRoute($route, $action, /** @scrutinizer ignore-type */ $class, $get);
Loading history...
213
                    } else {
214
                        throw new RouterException(_('La ruta no es válida'), 400);
215
                    }
216
                } catch (\Exception $e) {
217
                    Logger::log($e->getMessage(), LOG_ERR);
218 2
                    throw $e;
219
                }
220
            }
221
        }
222 1
        throw new RouterException(_('Ruta no encontrada'));
223
    }
224
225
    /**
226
     * @param array $action
227
     * @param array $params
228
     * @return bool
229
     */
230 1
    private function checkRequirements(array $action, $params = []) {
231 1
        if(!empty($params) && !empty($action['requirements'])) {
232
            $checked = 0;
233
            foreach(array_keys($params) as $key) {
234
                if(in_array($key, $action['requirements'], true)) {
235
                    $checked++;
236
                }
237
            }
238
            $valid = count($action['requirements']) === $checked;
239
        } else {
240 1
            $valid = true;
241
        }
242 1
        return $valid;
243
    }
244
245
    /**
246
     * @return string HTML
247
     */
248
    protected function sentAuthHeader()
249
    {
250
        return AdminServices::getInstance()->setAdminHeaders();
251
    }
252
253
    /**
254
     * @return string|null
255
     */
256 1
    private function getExternalModules() {
257 1
        $externalModules = Config::getParam('modules.extend', '');
258 1
        $externalModules .= ',psfs/auth';
259 1
        return $externalModules;
260
    }
261
262
    /**
263
     * @param boolean $hydrateRoute
264
     */
265 1
    private function checkExternalModules($hydrateRoute = true)
266
    {
267 1
        $externalModules = $this->getExternalModules();
268 1
        if ('' !== $externalModules) {
269 1
            $externalModules = explode(',', $externalModules);
270 1
            foreach ($externalModules as &$module) {
271 1
                $module = $this->loadExternalModule($hydrateRoute, $module);
272
            }
273
        }
274 1
    }
275
276
    /**
277
     * @throws exception\GeneratorException
278
     * @throws ConfigException
279
     * @throws \InvalidArgumentException
280
     */
281 1
    private function generateRouting()
282
    {
283 1
        $base = SOURCE_DIR;
284 1
        $modulesPath = realpath(CORE_DIR);
285 1
        $this->routing = $this->inspectDir($base, 'PSFS', array());
286 1
        $this->checkExternalModules();
287 1
        if (file_exists($modulesPath)) {
288
            $modules = $this->finder->directories()->in($modulesPath)->depth(0);
289
            if($modules->hasResults()) {
290
                foreach ($modules->getIterator() as $modulePath) {
291
                    $module = $modulePath->getBasename();
292
                    $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
293
                }
294
            }
295
        }
296 1
        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE);
297 1
    }
298
299
    /**
300
     * @throws exception\GeneratorException
301
     * @throws ConfigException
302
     * @throws \InvalidArgumentException
303
     */
304 1
    public function hydrateRouting()
305
    {
306 1
        $this->generateRouting();
307 1
        $home = Config::getParam('home.action');
308 1
        if (NULL !== $home || $home !== '') {
309 1
            $home_params = NULL;
310 1
            foreach ($this->routing as $pattern => $params) {
311 1
                list($method, $route) = RouterHelper::extractHttpRoute($pattern);
312 1
                if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) {
313
                    $home_params = $params;
314
                }
315 1
                unset($method);
316
            }
317 1
            if (NULL !== $home_params) {
318
                $this->routing['/'] = $home_params;
319
            }
320
        }
321 1
    }
322
323
    /**
324
     * @param string $origen
325
     * @param string $namespace
326
     * @param array $routing
327
     * @return array
328
     * @throws ConfigException
329
     * @throws \InvalidArgumentException
330
     */
331 1
    private function inspectDir($origen, $namespace = 'PSFS', $routing = [])
332
    {
333 1
        $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php');
334 1
        if($files->hasResults()) {
335 1
            foreach ($files->getIterator() as $file) {
336 1
                if($namespace !== 'PSFS' && method_exists($file, 'getRelativePathname')) {
337
                    $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname()));
338
                } else {
339 1
                    $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname()));
340
                }
341 1
                $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
342
            }
343
        }
344 1
        $this->finder = new Finder();
345
346 1
        return $routing;
347
    }
348
349
    /**
350
     * @param string $namespace
351
     * @return bool
352
     */
353 3
    public static function exists($namespace)
354
    {
355 3
        return (class_exists($namespace) || interface_exists($namespace) || trait_exists($namespace));
356
    }
357
358
    /**
359
     *
360
     * @param string $namespace
361
     * @param array $routing
362
     * @param string $module
363
     *
364
     * @return array
365
     * @throws ConfigException
366
     */
367 1
    private function addRouting($namespace, &$routing, $module = 'PSFS')
368
    {
369 1
        if (self::exists($namespace)) {
370 1
            if(I18nHelper::checkI18Class($namespace)) {
371
                return $routing;
372
            }
373 1
            $reflection = new \ReflectionClass($namespace);
374 1
            if (false === $reflection->isAbstract() && FALSE === $reflection->isInterface()) {
375 1
                $this->extractDomain($reflection);
376 1
                $classComments = $reflection->getDocComment();
377 1
                preg_match('/@api\ (.*)\n/im', $classComments, $apiPath);
378 1
                $api = '';
379 1
                if (count($apiPath)) {
380
                    $api = array_key_exists(1, $apiPath) ? $apiPath[1] : $api;
381
                }
382 1
                foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
383 1
                    if (preg_match('/@route\ /i', $method->getDocComment())) {
384 1
                        list($route, $info) = RouterHelper::extractRouteInfo($method, str_replace('\\', '', $api), str_replace('\\', '', $module));
385
386 1
                        if (null !== $route && null !== $info) {
387 1
                            $info['class'] = $namespace;
388 1
                            $routing[$route] = $info;
389
                        }
390
                    }
391
                }
392
            }
393
        }
394
395 1
        return $routing;
396
    }
397
398
    /**
399
     *
400
     * @param \ReflectionClass $class
401
     *
402
     * @return Router
403
     * @throws ConfigException
404
     */
405 1
    protected function extractDomain(\ReflectionClass $class)
406
    {
407
        //Calculamos los dominios para las plantillas
408 1
        if ($class->hasConstant('DOMAIN') && !$class->isAbstract()) {
409 1
            if (!$this->domains) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->domains of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
410 1
                $this->domains = [];
411
            }
412 1
            $domain = '@' . $class->getConstant('DOMAIN') . '/';
413 1
            if (!array_key_exists($domain, $this->domains)) {
414 1
                $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
415
            }
416
        }
417
418 1
        return $this;
419
    }
420
421
    /**
422
     * @return $this
423
     * @throws exception\GeneratorException
424
     * @throws ConfigException
425
     */
426 1
    public function simpatize()
427
    {
428 1
        $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php';
429 1
        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
430 1
        $this->generateSlugs($absoluteTranslationFileName);
431 1
        GeneratorHelper::createDir(CONFIG_DIR);
432 1
        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE);
433
434 1
        return $this;
435
    }
436
437
    /**
438
     * @param string $slug
439
     * @param boolean $absolute
440
     * @param array $params
441
     *
442
     * @return string|null
443
     * @throws RouterException
444
     */
445 3
    public function getRoute($slug = '', $absolute = FALSE, array $params = [])
446
    {
447 3
        if ('' === $slug) {
448 1
            return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/';
449
        }
450 3
        if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) {
0 ignored issues
show
introduced by
The condition is_array($this->slugs) is always true.
Loading history...
451 1
            throw new RouterException(_('No existe la ruta especificada'));
452
        }
453 3
        $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
454 3
        if (!empty($params)) {
455
            foreach ($params as $key => $value) {
456
                $url = str_replace('{' . $key . '}', $value, $url);
457
            }
458 3
        } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) {
459 3
            $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default'];
460
        }
461
462 3
        return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
463
    }
464
465
    /**
466
     * @return array
467
     */
468 2
    public function getDomains()
469
    {
470 2
        return $this->domains ?: [];
471
    }
472
473
    /**
474
     * @param string $class
475
     * @param string $method
476
     */
477 1
    private function checkPreActions($class, $method) {
478 1
        $preAction = 'pre' . ucfirst($method);
479 1
        if(method_exists($class, $preAction)) {
480
            Logger::log(_('Pre action invoked'));
481
            try {
482
                if(false === call_user_func_array([$class, $preAction])) {
0 ignored issues
show
Bug introduced by
The call to call_user_func_array() has too few arguments starting with param_arr. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

482
                if(false === /** @scrutinizer ignore-call */ call_user_func_array([$class, $preAction])) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
483
                    Logger::log(_('Pre action failed'), LOG_ERR, [error_get_last()]);
484
                    error_clear_last();
485
                }
486
            } catch (\Exception $e) {
487
                Logger::log($e->getMessage(), LOG_ERR, [$class, $method]);
488
            }
489
        }
490 1
    }
491
492
    /**
493
     * @param string $route
494
     * @param array $action
495
     * @param string $class
496
     * @param array $params
497
     * @return mixed
498
     * @throws exception\GeneratorException
499
     * @throws ConfigException
500
     */
501 1
    protected function executeCachedRoute($route, $action, $class, $params = NULL)
502
    {
503 1
        Logger::log('Executing route ' . $route, LOG_INFO);
504 1
        $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams());
505 1
        Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action);
506 1
        $cache = Cache::needCache();
507 1
        $execute = TRUE;
508 1
        $return = null;
509 1
        if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) {
510
            list($path, $cacheDataName) = $this->cache->getRequestCacheHash();
511
            $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, $cache);
0 ignored issues
show
Bug introduced by
It seems like $cache can also be of type true; however, parameter $expires of PSFS\base\Cache::readFromCache() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

511
            $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, /** @scrutinizer ignore-type */ $cache);
Loading history...
512
            if (NULL !== $cachedData) {
513
                $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', $cache, null, Cache::JSON);
514
                Template::getInstance()->renderCache($cachedData, $headers);
515
                $execute = FALSE;
516
            }
517
        }
518 1
        if ($execute) {
519 1
            Logger::log(_('Start executing action'));
520 1
            $this->checkPreActions($class, $action['method']);
521 1
            $return = call_user_func_array([$class, $action['method']], $params);
0 ignored issues
show
Bug introduced by
It seems like $params can also be of type null; however, parameter $param_arr of call_user_func_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

521
            $return = call_user_func_array([$class, $action['method']], /** @scrutinizer ignore-type */ $params);
Loading history...
522 1
            if (false === $return) {
523
                Logger::log(_('An error occurred trying to execute the action'), LOG_ERR, [error_get_last()]);
524
            }
525
        }
526 1
        return $return;
527
    }
528
529
    /**
530
     * Parse slugs to create translations
531
     *
532
     * @param string $absoluteTranslationFileName
533
     */
534 1
    private function generateSlugs($absoluteTranslationFileName)
535
    {
536 1
        $translations = I18nHelper::generateTranslationsFile($absoluteTranslationFileName);
537 1
        foreach ($this->routing as $key => &$info) {
538 1
            $keyParts = explode('#|#', $key);
539 1
            $keyParts = array_key_exists(1, $keyParts) ? $keyParts[1] : $keyParts[0];
540 1
            $slug = RouterHelper::slugify($keyParts);
541 1
            if (NULL !== $slug && !array_key_exists($slug, $translations)) {
542 1
                $translations[$slug] = $info['label'];
543 1
                file_put_contents($absoluteTranslationFileName, "\$translations[\"{$slug}\"] = _(\"{$info['label']}\");\n", FILE_APPEND);
544
            }
545 1
            $this->slugs[$slug] = $key;
546 1
            $info['slug'] = $slug;
547
        }
548 1
    }
549
550
    /**
551
     * @param bool $hydrateRoute
552
     * @param $modulePath
553
     * @param $externalModulePath
554
     */
555
    private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath)
556
    {
557
        $extModule = $modulePath->getBasename();
558
        $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
559
        if(file_exists($moduleAutoloader)) {
560
            include_once $moduleAutoloader;
561
            if ($hydrateRoute) {
562
                $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
563
            }
564
        }
565
    }
566
567
    /**
568
     * @param $hydrateRoute
569
     * @param $module
570
     * @return mixed
571
     */
572 1
    private function loadExternalModule($hydrateRoute, $module)
573
    {
574
        try {
575 1
            $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
576 1
            $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
577 1
            if(file_exists($externalModulePath)) {
578
                $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
579
                if($externalModule->hasResults()) {
580
                    foreach ($externalModule->getIterator() as $modulePath) {
581 1
                        $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath);
582
                    }
583
                }
584
            }
585
        } catch (\Exception $e) {
586
            Logger::log($e->getMessage(), LOG_WARNING);
587
            $module = null;
588
        }
589 1
        return $module;
590
    }
591
592
}
593