-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f18c744
commit 74dea22
Showing
7 changed files
with
145 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules | |
vendor | ||
.env | ||
composer.lock | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace ReinVanOyen\Cmf\Factories; | ||
|
||
use ReinVanOyen\Cmf\Module; | ||
|
||
class ModuleFactory | ||
{ | ||
public static function make($module) | ||
{ | ||
if (is_string($module)) { | ||
return app($module); | ||
} | ||
if ($module instanceof Module) { | ||
return $module; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace ReinVanOyen\Cmf; | ||
|
||
use ReinVanOyen\Cmf\Factories\ModuleFactory; | ||
|
||
class ModuleRegistry | ||
{ | ||
/** | ||
* @var array $modules | ||
*/ | ||
private $modules; | ||
|
||
/** | ||
* @var array $modulesMap | ||
*/ | ||
private $modulesMap; | ||
|
||
/** | ||
* @param $module | ||
* @param bool $isRoot | ||
* @return \Illuminate\Contracts\Foundation\Application|mixed|null | ||
*/ | ||
public function add($module, $isRoot = true) | ||
{ | ||
$module = ModuleFactory::make($module); | ||
$this->modulesMap[$module->id()] = $module; | ||
|
||
if ($isRoot) { | ||
$this->modules[] = $module; | ||
} | ||
|
||
return $module; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return mixed|null | ||
*/ | ||
public function get(string $id): ?Module | ||
{ | ||
return ($this->modulesMap[$id] ?? null); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function root(): array | ||
{ | ||
return $this->modules; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function all(): array | ||
{ | ||
return array_keys($this->modulesMap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters