-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from Arno2005/master
Install default modules by command
- Loading branch information
Showing
73 changed files
with
4,672 additions
and
185 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
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,107 @@ | ||
<?php | ||
|
||
namespace Quantum\Libraries\Module; | ||
|
||
use Quantum\Di\Di; | ||
use Quantum\Libraries\Storage\FileSystem; | ||
|
||
class ModuleManager{ | ||
|
||
protected $fs; | ||
protected $optionEnabled; | ||
|
||
private $moduleName; | ||
private $template; | ||
private $demo; | ||
private $modulePath; | ||
private $templatePath; | ||
|
||
function __construct(string $moduleName, string $template, string $demo, $enabled){ | ||
$this->moduleName = $moduleName; | ||
|
||
$this->template = $template; | ||
|
||
$this->demo = $demo; | ||
|
||
$this->optionEnabled = $enabled; | ||
|
||
$type = $this->demo == "yes" ? "Demo" : "Default"; | ||
|
||
$this->templatePath = __DIR__ . DS . "Templates" . DS . $type . DS . ucfirst($this->template); | ||
|
||
$this->modulePath = modules_dir() . DS . $this->moduleName; | ||
|
||
$this->fs = Di::get(FileSystem::class); | ||
} | ||
|
||
public function writeContents() | ||
{ | ||
if (!$this->fs->isDirectory(modules_dir())) { | ||
$this->fs->makeDirectory(modules_dir()); | ||
} | ||
$this->copyDirectoryWithTemplates($this->templatePath, $this->modulePath); | ||
} | ||
|
||
public function addModuleConfig() | ||
{ | ||
$modulesConfigPath = base_dir() . DS . 'shared' . DS . 'config' . DS . 'modules.php'; | ||
$modules = require $modulesConfigPath; | ||
|
||
foreach ($modules['modules'] as $module => $options) { | ||
if ($module == $this->moduleName || $options['prefix'] == strtolower($this->moduleName)) { | ||
throw new \Exception("A module or prefix named '$this->moduleName' already exists"); | ||
} | ||
} | ||
|
||
$this->fs->put( | ||
$modulesConfigPath, | ||
str_replace( | ||
"'modules' => [", | ||
$this->writeModuleConfig($this->moduleName), | ||
$this->fs->get($modulesConfigPath) | ||
) | ||
); | ||
} | ||
|
||
private function copyDirectoryWithTemplates($src, $dst) { | ||
if (!$this->fs->isDirectory($src)) { | ||
throw new \Exception("Directory '$src' does not exist"); | ||
} | ||
|
||
if (!$this->fs->isDirectory($dst)) { | ||
$this->fs->makeDirectory($dst); | ||
} | ||
|
||
$dir = $this->fs->listDirectory($src); | ||
|
||
foreach ($dir as $file) { | ||
$srcPath = $file; | ||
$dstPath = str_replace($src, $dst, $file); | ||
|
||
if ($this->fs->isDirectory($srcPath)) { | ||
$this->copyDirectoryWithTemplates($srcPath, $dstPath); | ||
} else { | ||
$processedContent = require_once $srcPath; | ||
$this->fs->put($dstPath, $processedContent); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Add module to config | ||
* @param string $module | ||
* @return string | ||
*/ | ||
private function writeModuleConfig(string $module): string | ||
{ | ||
$enabled = $this->optionEnabled ? "true" : "false"; | ||
|
||
$prefix = $this->template == "web" && $this->demo == "yes" ? "" : strtolower($module); | ||
|
||
return "'modules' => [ | ||
'" . $module . "' => [ | ||
'prefix' => '" . $prefix . "', | ||
'enabled' => " . $enabled . ", | ||
],"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Libraries/Module/Templates/Default/Api/Config/cors.php
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,17 @@ | ||
<?php | ||
|
||
return '<?php | ||
return [ | ||
/** | ||
* --------------------------------------------------------- | ||
* Cross-Origin Resource Sharing (CORS) Configuration | ||
* --------------------------------------------------------- | ||
* Settings defined here determines the cross-origin resource sharing | ||
*/ | ||
\'Access-Control-Allow-Origin\' => \'*\', | ||
\'Access-Control-Allow-Headers\' => \'Origin, X-Requested-With, Content-Type, Accept, Authorization, refresh_token\', | ||
\'Access-Control-Allow-Methods\' => \'GET, POST, PUT, DELETE, OPTIONS\', | ||
\'Access-Control-Allow-Credentials\' => true, | ||
]; | ||
'; |
20 changes: 20 additions & 0 deletions
20
src/Libraries/Module/Templates/Default/Api/Config/routes.php
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,20 @@ | ||
<?php | ||
|
||
return '<?php | ||
use Quantum\Factory\ViewFactory; | ||
use Quantum\Http\Response; | ||
return function ($route) { | ||
$route->group("openapi", function ($route) { | ||
$route->get("docs", function (Quantum\Http\Response $response) { | ||
$response->html(partial("openApi/openApi")); | ||
}); | ||
$route->get("spec", function (Quantum\Http\Response $response) { | ||
$fs = Quantum\Di\Di::get(Quantum\Libraries\Storage\FileSystem::class); | ||
$response->json((array) json_decode($fs->get(modules_dir() . "\Api\Resources\openapi\spec.json"))); | ||
}); | ||
}); | ||
$route->get(\'/\', \'MainController\', \'index\'); | ||
};'; |
Oops, something went wrong.