Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"doctrine/annotations": "^2.0",
"voku/html-min": "^4.5",
"league/commonmark": "^1.6",
"ezyang/htmlpurifier": "^4.18"
"ezyang/htmlpurifier": "^4.18",
"symfony/process": "^5.4"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
Expand Down
111 changes: 87 additions & 24 deletions shared/Commands/DemoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
use Quantum\Libraries\Database\Database;
use Bluemmb\Faker\PicsumPhotosProvider;
use Quantum\Di\Exceptions\DiException;
use Symfony\Component\Process\Process;
use Quantum\Console\QtCommand;
use Ottaviano\Faker\Gravatar;
use ReflectionException;
use Shared\Enums\Role;
use Faker\Generator;
use ErrorException;
use Faker\Factory;
use Exception;

/**
* Class DemoCommand
Expand Down Expand Up @@ -146,6 +146,7 @@ public function exec()
foreach ($steps as $step) {
$this->updateProgress($progress, $step['message']);
$step['action']();
$progress->advance();
}

$progress->finish();
Expand Down Expand Up @@ -219,12 +220,10 @@ private function initProgressBar(int $steps): ProgressBar
* @param string $moduleName
* @param string $template
* @param bool $withAssets
* @return void
* @throws ExceptionInterface
*/
private function createModule(string $moduleName, string $template, bool $withAssets): void
{
$this->runExternalCommand(self::COMMANDS['module_generate'], [
$this->runCommandExternally(self::COMMANDS['module_generate'], [
'module' => $moduleName,
'--yes' => true,
'--template' => $template,
Expand All @@ -248,7 +247,7 @@ private function generateUsers(): array
$users = [];
for ($i = 0; $i < self::COUNTS['users']; $i++) {
$user = $this->generateUserData();
$this->runExternalCommand(self::COMMANDS['user_create'], $user);
$this->runCommandInternally(self::COMMANDS['user_create'], $user);
$users[] = $user;
}
return $users;
Expand All @@ -273,7 +272,7 @@ private function generatePosts(array $users): array
foreach ($users as $user) {
for ($i = 0; $i < self::COUNTS['posts_per_user']; $i++) {
$post = $this->generatePostData($user);
$this->runExternalCommand(self::COMMANDS['post_create'], $post);
$this->runCommandInternally(self::COMMANDS['post_create'], $post);
$posts[] = $post;
}
}
Expand All @@ -294,7 +293,7 @@ private function generateComments(array $users, array $posts): void
for ($i = 0; $i < self::COUNTS['comments_per_post']; $i++) {
$commentUser = $this->getRandomUserExcept($users, $post['user_uuid']);

$this->runExternalCommand(self::COMMANDS['comment_create'], [
$this->runCommandInternally(self::COMMANDS['comment_create'], [
'post_uuid' => $post['uuid'],
'user_uuid' => $commentUser['uuid'],
'content' => textCleanUp($this->faker->realText(rand(20, 100))),
Expand All @@ -316,7 +315,7 @@ private function generateComments(array $users, array $posts): void
private function generateUserData(): array
{
$userUuid = $this->faker->uuid();
$email = textCleanUp($this->faker->email());
$email = $this->faker->safeEmail();

create_user_directory($userUuid);

Expand All @@ -327,19 +326,19 @@ private function generateUserData(): array
);

return [
'uuid' => $userUuid,
'email' => $email,
'password' => self::DEFAULT_PASSWORD,
'firstname' => $this->faker->name(),
'lastname' => $this->faker->lastName(),
'uuid' => $userUuid,
'role' => Role::EDITOR,
'email' => $email,
'password' => self::DEFAULT_PASSWORD,
'image' => $imageName
];
}

/**
* Generates data for post
* @param $user
* @param array $user
* @return array
* @throws BaseException
* @throws ConfigException
Expand All @@ -348,7 +347,7 @@ private function generateUserData(): array
* @throws HttpClientException
* @throws ReflectionException
*/
private function generatePostData($user): array
private function generatePostData(array $user): array
{
$postUuid = $this->faker->uuid();
$title = textCleanUp($this->faker->realText(50));
Expand All @@ -360,11 +359,11 @@ private function generatePostData($user): array
);

return [
'uuid' => $postUuid,
'title' => $title,
'description' => textCleanUp($this->faker->realText(1000)),
'image' => $imageName,
'user_uuid' => $user['uuid'],
'uuid' => $postUuid,
'image' => $imageName,
];
}

Expand Down Expand Up @@ -393,25 +392,25 @@ private function updateProgress(ProgressBar $progress, string $message): void
{
$progress->setMessage($message, 'item');
$progress->display();
$progress->advance();
}

/**
* Rebuilds the database
* @return void
* @throws ExceptionInterface
*/
private function rebuildDatabase(): void
{
switch (Database::getInstance()->getConfigs()['driver']) {
case 'mysql':
$this->runExternalCommand(self::COMMANDS['migrate'], ['direction' => 'down']);
$this->runExternalCommand(self::COMMANDS['migrate'], ['direction' => 'up']);
$this->runCommandInternally(self::COMMANDS['migrate'], ['direction' => 'down']);
$this->runCommandInternally(self::COMMANDS['migrate'], ['direction' => 'up']);
break;

case 'sleekdb':
$this->runExternalCommand(self::COMMANDS['comment_delete'], ['--yes' => true]);
$this->runExternalCommand(self::COMMANDS['post_delete'], ['--yes' => true]);
$this->runExternalCommand(self::COMMANDS['user_delete'], ['--yes' => true]);
$this->runCommandInternally(self::COMMANDS['comment_delete'], ['--yes' => true]);
$this->runCommandInternally(self::COMMANDS['post_delete'], ['--yes' => true]);
$this->runCommandInternally(self::COMMANDS['user_delete'], ['--yes' => true]);
break;
}
}
Expand Down Expand Up @@ -452,13 +451,77 @@ private function resetDatabase(): void
}

/**
* Runs an external command
* @throws Exception
* @param string $commandName
* @param array $arguments
* @throws ExceptionInterface
*/
private function runExternalCommand(string $commandName, ?array $arguments = [])
private function runCommandInternally(string $commandName, array $arguments = [])
{
$command = $this->getApplication()->find($commandName);
$command->run(new ArrayInput($arguments), new NullOutput);
}

/**
* @param string $commandName
* @param array $arguments
*/
private function runCommandExternally(string $commandName, array $arguments = [])
{
$command = $this->buildCommand($commandName, $arguments);
$this->runExternalProcess($command);
}

/**
* Runs separate process
* @param array $command
* @return void
*/
private function runExternalProcess(array $command): void
{
$process = new Process($command, base_dir());
$process->setTimeout(null);

$process->mustRun();
}

/**
* Builds command string
* @param string $commandName
* @param array $arguments
* @return string[]
*/
private function buildCommand(string $commandName, array $arguments): array
{
$command = ['php', 'qt', $commandName];

foreach ($arguments as $key => $value) {
if (!is_int($key) && substr($key, 0, 2) !== '--') {
$command[] = (string)$value;
continue;
}

if (is_bool($value)) {
if ($value) $command[] = $key;
continue;
}

if (is_array($value)) {
foreach ($value as $item) {
$command[] = $key;
$command[] = (string)$item;
}
continue;
}

$command[] = $key;

if ($value === null) {
continue;
}

$command[] = (string)$value;
}

return $command;
}
}
3 changes: 2 additions & 1 deletion shared/resources/lang/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

// ───── About framework ───────────────────────────────────
'description' => 'Very fast and extremely simple, next generation PHP MVC framework with modular structure.',
'about_framework' => 'Quantum is a free, open-source PHP web framework under MIT license...',
'about_framework' => 'Quantum is a free, open-source PHP web framework under MIT license, specially designed to develop very fast web applications with modular structure. With Quantum it’s easy to start any kind of project immediately, whether it\'s regular websites or complex API based service, at the same time it allows to keep the code clean, organized through all the development process.',
'version' => 'Version',
'current_version' => 'Current version is: {%1}',
'cli_commands' => 'Quantum CLI Commands',

// ───── Navigation ─────────────────────────────────────────
'home' => 'Home',
Expand Down
3 changes: 2 additions & 1 deletion shared/resources/lang/es/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

// ───── About framework ───────────────────────────────────
'description' => 'Framework MVC en PHP de nueva generación, muy rápido y extremadamente simple, con una estructura modular.',
'about_framework' => 'Quantum es un framework web en PHP gratuito y de código abierto bajo la licencia MIT...',
'about_framework' => 'Quantum es un framework web PHP gratuito y de código abierto bajo la licencia MIT, diseñado especialmente para desarrollar aplicaciones web muy rápidas con una estructura modular. Con Quantum es fácil iniciar de inmediato cualquier tipo de proyecto, ya sean sitios web tradicionales o servicios complejos basados en API, y al mismo tiempo permite mantener el código limpio y organizado durante todo el proceso de desarrollo.',
'version' => 'Versión',
'current_version' => 'La versión actual es: {%1}',
'cli_commands' => 'Comandos CLI de Quantum',

// ───── Navigation ─────────────────────────────────────────
'home' => 'Inicio',
Expand Down