public
function
getModules()
{
if
(
$this
->modules->isEmpty()) {
if
(
$this
->files->isDirectory(
$this
->getModulePath())) {
collect(
$this
->files->directories(
$this
->getModulePath()))->each(
function
(
$directory
) {
if
(
$this
->files->exists(
$file
=
$directory
. DIRECTORY_SEPARATOR .
'composer.json'
)) {
$package
=
new
Collection(json_decode(
$this
->files->get(
$file
), true));
$identification
= Arr::get(
$package
,
'name'
);
$type
= Arr::get(
$package
,
'type'
);
if
(
$type
==
'notadd-module'
&&
$identification
) {
$provider
=
''
;
if
(
$entries
= data_get(
$package
,
'autoload.psr-4'
)) {
foreach
(
$entries
as
$namespace
=>
$entry
) {
$provider
=
$namespace
.
'ModuleServiceProvider'
;
}
}
if
(
$this
->files->exists(
$autoload
=
$directory
. DIRECTORY_SEPARATOR .
'vendor'
. DIRECTORY_SEPARATOR .
'autoload.php'
)) {
$this
->files->requireOnce(
$autoload
);
}
$authors
= Arr::get(
$package
,
'authors'
);
$description
= Arr::get(
$package
,
'description'
);
if
(
class_exists
(
$provider
)) {
$module
=
new
Module(
$identification
);
$module
->setAuthor(
$authors
);
$module
->setDescription(
$description
);
$module
->setDirectory(
$directory
);
$module
->setEnabled(
$this
->container->isInstalled() ?
$this
->container->make(
'setting'
)->get(
'module.'
.
$identification
.
'.enabled'
, false) : false);
$module
->setInstalled(
$this
->container->isInstalled() ?
$this
->container->make(
'setting'
)->get(
'module.'
.
$identification
.
'.installed'
, false) : false);
$module
->setEntry(
$provider
);
if
(method_exists(
$provider
,
'alias'
)) {
$module
->setAlias(call_user_func([
$provider
,
'alias'
]));
}
else
{
$module
->setAlias([
$identification
]);
}
method_exists(
$provider
,
'description'
) &&
$module
->setDescription(call_user_func([
$provider
,
'description'
]));
method_exists(
$provider
,
'name'
) &&
$module
->setName(call_user_func([
$provider
,
'name'
]));
method_exists(
$provider
,
'script'
) &&
$module
->setScript(call_user_func([
$provider
,
'script'
]));
method_exists(
$provider
,
'stylesheet'
) &&
$module
->setStylesheet(call_user_func([
$provider
,
'stylesheet'
]));
method_exists(
$provider
,
'version'
) &&
$module
->setVersion(call_user_func([
$provider
,
'version'
]));
$this
->modules->put(
$identification
,
$module
);
}
else
{
$this
->unloaded->put(
$identification
, [
'authors'
=>
$authors
,
'description'
=>
$description
,
'directory'
=>
$directory
,
'identification'
=>
$identification
,
'provider'
=>
$provider
,
]);
}
}
}
});
}
}
return
$this
->modules;
}