kernel update
This commit is contained in:
21
kernel/services/ConsoleService.php
Normal file
21
kernel/services/ConsoleService.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
class ConsoleService
|
||||
{
|
||||
public function runComposerRequire(string $package): void
|
||||
{
|
||||
exec("composer require $package");
|
||||
}
|
||||
|
||||
public function runComposerRemove(string $package): void
|
||||
{
|
||||
exec("composer remove $package");
|
||||
}
|
||||
|
||||
public function runCommand(string $command): void
|
||||
{
|
||||
exec($command);
|
||||
}
|
||||
}
|
@ -36,4 +36,25 @@ class MigrationService
|
||||
}
|
||||
}
|
||||
|
||||
public function rollbackAtPath(string $path): void
|
||||
{
|
||||
$path = getConst($path);
|
||||
try {
|
||||
$filesystem = new Filesystem();
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), $filesystem);
|
||||
|
||||
$migrationFiles = $m->getMigrationFiles($path);
|
||||
foreach ($migrationFiles as $name => $migrationFile){
|
||||
$migrationInstance = $filesystem->getRequire($migrationFile);
|
||||
$migrationInstance->migration = $name;
|
||||
$migrationInstance->down();
|
||||
$dmr->delete($migrationInstance);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Не удалось откатить миграции');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -444,7 +444,7 @@ class ModuleService
|
||||
|
||||
public function isLastVersion(string $slug): bool
|
||||
{
|
||||
if ($this->isServerAvailable()){
|
||||
if ($this->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
@ -473,16 +473,20 @@ class ModuleService
|
||||
|
||||
public function isShopModule(string $slug): bool
|
||||
{
|
||||
if ($this->isServerAvailable()){
|
||||
if ($this->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
if (!$this->issetModuleShopToken()){
|
||||
|
||||
if (!$this->issetModuleShopToken()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
$mod_info = $this->getModuleInfoBySlug($slug);
|
||||
foreach ($modules_info as $mod) {
|
||||
if ($mod['slug'] === $mod_info['slug']) {
|
||||
return true;
|
||||
if (isset($modules_info)) {
|
||||
$mod_info = $this->getModuleInfoBySlug($slug);
|
||||
foreach ($modules_info as $mod) {
|
||||
if ($mod['slug'] === $mod_info['slug']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -503,7 +507,7 @@ class ModuleService
|
||||
|
||||
public function isServerAvailable(): bool
|
||||
{
|
||||
if (null !== $this->serverAvailable){
|
||||
if (null !== $this->serverAvailable) {
|
||||
return $this->serverAvailable;
|
||||
}
|
||||
|
||||
@ -520,10 +524,58 @@ class ModuleService
|
||||
|
||||
public function issetModuleShopToken(): bool
|
||||
{
|
||||
if (!empty($_ENV['MODULE_SHOP_TOKEN'])){
|
||||
if (!empty($_ENV['MODULE_SHOP_TOKEN'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createDirs(string $slug): void
|
||||
{
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/controllers");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/migrations");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/services");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models/forms");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/routs");
|
||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/views");
|
||||
|
||||
mkdir(APP_DIR . "/modules/$slug");
|
||||
mkdir(APP_DIR . "/modules/$slug/controllers");
|
||||
mkdir(APP_DIR . "/modules/$slug/routs");
|
||||
}
|
||||
|
||||
public function createModuleByParams(array $params): void
|
||||
{
|
||||
$slug = $params['slug'];
|
||||
$model = $params['model'];
|
||||
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/manifests/manifest_template', APP_DIR . "/modules/$slug/manifest.json", $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/controllers/kernel_controller_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/controllers/' . $model . 'Controller.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/controllers/app_controller_template', APP_DIR . '/modules/' . $slug . '/controllers/' . $model . 'Controller.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/routs/kernel_routs_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/routs/' . $slug . '.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/routs/app_routs_template', APP_DIR . '/modules/' . $slug . '/routs/' . $slug . '.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/module_files/kernel_module_file_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/' . $model . 'Module.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/module_files/app_module_file_template', APP_DIR . '/modules/' . $slug . '/' . $model . 'Module.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/models/model_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/models/' . $model . '.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/models/forms/create_form_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/models/forms/Create' . $model . 'Form.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/services/service_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/services/' . $model . 'Service.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/views/index_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/index.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/views/view_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/view.php', $params);
|
||||
$this->createModuleFileByTemplate(KERNEL_TEMPLATES_DIR . '/views/form_template', KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/form.php', $params);
|
||||
}
|
||||
|
||||
public function createModuleFileByTemplate(string $templatePath, string $filePath, array $params): void
|
||||
{
|
||||
$data = file_get_contents($templatePath);
|
||||
|
||||
foreach ($params as $key => $param){
|
||||
$data = str_replace("{" . $key . "}", $param, $data);
|
||||
}
|
||||
|
||||
file_put_contents($filePath, $data);
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,7 @@ class TokenService
|
||||
*/
|
||||
public static function md5(): string
|
||||
{
|
||||
return md5(microtime() . self::getSalt() . time());
|
||||
return md5(microtime() . self::getSalt(10) . time());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +40,7 @@ class TokenService
|
||||
*/
|
||||
public static function crypt(): string
|
||||
{
|
||||
return crypt(microtime(), self::getSalt());
|
||||
return crypt(microtime(), self::getSalt(20));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,15 +48,15 @@ class TokenService
|
||||
*/
|
||||
public static function hash(string $alg): string
|
||||
{
|
||||
return hash($alg, self::getSalt());
|
||||
return hash($alg, self::getSalt(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public static function getSalt(): string
|
||||
public static function getSalt(int $length): string
|
||||
{
|
||||
return bin2hex(random_bytes(10));
|
||||
return bin2hex(random_bytes($length));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user