Skip to content

Commit

Permalink
update: add extra package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirHkrg committed Aug 20, 2024
1 parent 01293b9 commit 285ec85
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 31 deletions.
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"bramus/ansi-php": "^3.1",
"illuminate/database": "^11.10",
"illuminate/events": "^11.10",
"illuminate/support": "^11.10",
"fakerphp/faker": "^1.23"
"bramus/ansi-php": "^3"
}
}
35 changes: 9 additions & 26 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ protected function bindPathsInContainer(): void

public function registerKernel(): static
{
$this->singleton(CoreCommand::class);
$this->alias(CoreCommand::class, 'kernel.core_command');
$this->singleton(Kernel::class);
$this->alias(Kernel::class, 'kernel');

Expand All @@ -135,37 +137,18 @@ public function registerKernel(): static

public function commands(): array
{
$commands = [
\LaraGram\Console\GenerateCommand::class,
\LaraGram\Database\Factories\GenerateFactory::class,
\LaraGram\Database\Migrations\GenerateMigration::class,
\LaraGram\Database\Models\GenerateModel::class,
\LaraGram\Database\Seeders\GenerateSeeder::class,
\LaraGram\Database\Migrations\Migrator\MigrateCommand::class,
\LaraGram\Database\Seeders\SeederCommand::class,
\LaraGram\Foundation\Provider\GenerateProvider::class,
\LaraGram\Foundation\Resource\GenerateResource::class,
\LaraGram\Foundation\Webhook\SetWebhookCommand::class,
\LaraGram\Foundation\Webhook\DeleteWebhookCommand::class,
\LaraGram\Foundation\Webhook\DropWebhookCommand::class,
\LaraGram\Foundation\Webhook\WebhookInfoCommand::class,
\LaraGram\Foundation\Objects\Facade\GenerateFacade::class,
\LaraGram\Foundation\Objects\Class\GenerateClass::class,
\LaraGram\Foundation\Objects\Enum\GenerateEnum::class,
\LaraGram\Foundation\Server\ServeCommand::class,
\LaraGram\Foundation\Server\APIServeCommand::class,
\LaraGram\JsonDatabase\Migrations\GenerateMigration::class,
\LaraGram\JsonDatabase\Models\GenerateModel::class,
\LaraGram\JsonDatabase\MigrateCommand::class,
\LaraGram\Foundation\Objects\Controller\GenerateController::class,
];
/**
* @var CoreCommand $core_command
*/
$core_command = app('kernel.core_command');

return array_merge($commands, $_ENV['COMMANDS']);
return array_merge($core_command->getCoreCommands(), $_ENV['COMMANDS']);
}

public function registerCommands(): static
{
foreach ($this->commands() as $command) {
$commands = $this->commands();
foreach ($commands as $command) {
$this['kernel']->addCommand(new $command);
}

Expand Down
63 changes: 63 additions & 0 deletions src/Foundation/CoreCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace LaraGram\Foundation;

class CoreCommand
{
private array $commands = [];

public function __construct()
{
$this->registerBaseCommands();
}

public function getCoreCommands(): array
{
return $this->commands;
}

private function registerBaseCommands(): void
{
foreach ($this->baseCommands() as $command) {
$this->append($command);
}
}

public function append($command): static
{
$this->commands[] = $command;
return $this;
}

private function baseCommands(): array
{
return [
\LaraGram\Console\GenerateCommand::class,
\LaraGram\Database\Factories\GenerateFactory::class,
\LaraGram\Database\Migrations\GenerateMigration::class,
\LaraGram\Database\Models\GenerateModel::class,
\LaraGram\Database\Seeders\GenerateSeeder::class,
\LaraGram\Database\Migrations\Migrator\MigrateCommand::class,
\LaraGram\Database\Seeders\SeederCommand::class,
\LaraGram\JsonDatabase\Migrations\GenerateMigration::class,
\LaraGram\JsonDatabase\Models\GenerateModel::class,
\LaraGram\JsonDatabase\MigrateCommand::class,
\LaraGram\Foundation\Provider\GenerateProvider::class,
\LaraGram\Foundation\Resource\GenerateResource::class,
\LaraGram\Foundation\Webhook\SetWebhookCommand::class,
\LaraGram\Foundation\Webhook\DeleteWebhookCommand::class,
\LaraGram\Foundation\Webhook\DropWebhookCommand::class,
\LaraGram\Foundation\Webhook\WebhookInfoCommand::class,
\LaraGram\Foundation\Objects\Facade\GenerateFacade::class,
\LaraGram\Foundation\Objects\Class\GenerateClass::class,
\LaraGram\Foundation\Objects\Enum\GenerateEnum::class,
\LaraGram\Foundation\Server\ServeCommand::class,
\LaraGram\Foundation\Server\APIServeCommand::class,
\LaraGram\Foundation\Objects\Controller\GenerateController::class,
\LaraGram\Foundation\PackageManager\Installer\Eloquent::class,
\LaraGram\Foundation\PackageManager\Installer\OpenSwoole::class,
\LaraGram\Foundation\PackageManager\Uninstaller\OpenSwoole::class,
\LaraGram\Foundation\PackageManager\Uninstaller\Eloquent::class,
];
}
}
28 changes: 28 additions & 0 deletions src/Foundation/PackageManager/Installer/Eloquent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace LaraGram\Foundation\PackageManager\Installer;

use LaraGram\Console\Command;
use LaraGram\Support\Facades\Console;

class Eloquent extends Command
{
protected $signature = 'install:eloquent';
protected $description = 'Install Laravel Eloquent ORM';

public function handle()
{
if ($this->getOption('h') == 'h') Console::output()->message($this->description, true);

Console::output()->message("This operation may take time...");

exec("composer require illuminate/database illuminate/events illuminate/support fakerphp/faker 2>&1", $output, $return_var);

if ($return_var !== 0) {
Console::output()->failed("Error installing package: ");
echo implode("\n", $output);
} else {
Console::output()->success("[ Eloquent ORM ] Installed Successfully!", true);
}
}
}
32 changes: 32 additions & 0 deletions src/Foundation/PackageManager/Installer/OpenSwoole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace LaraGram\Foundation\PackageManager\Installer;

use LaraGram\Console\Command;
use LaraGram\Support\Facades\Console;

class OpenSwoole extends Command
{
protected $signature = 'install:openswoole';
protected $description = 'Install Openswoole Core';

public function handle()
{
if ($this->getOption('h') == 'h') Console::output()->message($this->description, true);

if (!extension_loaded('openswoole')) {
Console::output()->failed("openswoole extension not loaded", true);
}

Console::output()->message("This operation may take time...");

exec("composer require openswoole/core 2>&1", $output, $return_var);

if ($return_var !== 0) {
Console::output()->failed("Error installing package: ");
echo implode("\n", $output);
} else {
Console::output()->success("[ OpenSwoole Core ] Installed Successfully!", true);
}
}
}
26 changes: 26 additions & 0 deletions src/Foundation/PackageManager/Uninstaller/Eloquent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace LaraGram\Foundation\PackageManager\Uninstaller;

use LaraGram\Console\Command;
use LaraGram\Support\Facades\Console;

class Eloquent extends Command
{
protected $signature = 'remove:eloquent';
protected $description = 'Remove Laravel Eloquent ORM';

public function handle()
{
if ($this->getOption('h') == 'h') Console::output()->message($this->description, true);

exec("composer remove illuminate/database illuminate/events illuminate/support fakerphp/faker 2>&1", $output, $return_var);

if ($return_var !== 0) {
Console::output()->failed("Error removing package: ");
echo implode("\n", $output);
} else {
Console::output()->success("[ Eloquent ORM ] Removed Successfully!", true);
}
}
}
30 changes: 30 additions & 0 deletions src/Foundation/PackageManager/Uninstaller/OpenSwoole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace LaraGram\Foundation\PackageManager\Uninstaller;

use LaraGram\Console\Command;
use LaraGram\Support\Facades\Console;

class OpenSwoole extends Command
{
protected $signature = 'remove:openswoole';
protected $description = 'Remove Openswoole Core';

public function handle()
{
if ($this->getOption('h') == 'h') Console::output()->message($this->description, true);

if (!extension_loaded('openswoole')) {
Console::output()->failed("openswoole extension not loaded", true);
}

exec("composer remove openswoole/core 2>&1", $output, $return_var);

if ($return_var !== 0) {
Console::output()->failed("Error removing package: ");
echo implode("\n", $output);
} else {
Console::output()->success("[ OpenSwoole Core ] Removed Successfully!", true);
}
}
}

0 comments on commit 285ec85

Please sign in to comment.