-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
27 changed files
with
3,473 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Bot\App\Controller\Api; | ||
|
||
use Bot\Core\http\RegisterApi; | ||
|
||
class Api extends RegisterApi | ||
{ | ||
|
||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Bot\App\Model; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class User extends Model | ||
{ | ||
|
||
} |
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,8 @@ | ||
<?php | ||
|
||
use Bot\Core\Bot; | ||
use Bot\Core\Request; | ||
|
||
$bot = new Bot(); | ||
|
||
// Code ... |
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,49 @@ | ||
<?php | ||
|
||
namespace Bot\Core\Cli\Action; | ||
|
||
use Bot\Core\Cli\Error\Logger; | ||
|
||
class ApiMaker | ||
{ | ||
private mixed $cmd; | ||
|
||
public function __construct() | ||
{ | ||
global $argv; | ||
$this->cmd = $argv; | ||
} | ||
|
||
public function createApi(): void | ||
{ | ||
if (!isset($this->cmd[2])) { | ||
Logger::status('Warning', 'Enter the Api name!', 'warning'); | ||
return; | ||
} | ||
|
||
$apiPage = str_replace('&&&', $this->cmd[2], file_get_contents('Core/Cli/Layout/api.txt')); | ||
|
||
$fileName = 'App/Controller/Api/' . $this->cmd[2] . '.php'; | ||
if (file_exists($fileName)) { | ||
Logger::warning('Api is already exist!'); | ||
} else { | ||
file_put_contents($fileName, $apiPage); | ||
Logger::success('Api Created Successfully!'); | ||
} | ||
} | ||
|
||
public function removeApi(): void | ||
{ | ||
if (!isset($this->cmd[2])) { | ||
Logger::status('Warning', 'Enter the Api name!', 'warning'); | ||
return; | ||
} | ||
|
||
if (file_exists("App/Controller/Api/{$this->cmd[2]}.php")) { | ||
unlink("App/Controller/Api/{$this->cmd[2]}.php"); | ||
Logger::status('Success', 'Api deleted successfully!'); | ||
} else { | ||
Logger::status('Failed', 'Api is not exist!', 'failed'); | ||
} | ||
} | ||
} |
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,106 @@ | ||
<?php | ||
|
||
namespace Bot\Core\Cli\Action; | ||
|
||
require_once 'Bootstrap/bootstrap.php'; | ||
|
||
use Bot\Core\Cli\Kernel; | ||
|
||
$kernel = new Kernel(); | ||
//----------------------------------------------------------------- | ||
$kernel->call('make:model', function () { | ||
$database = new DatabaseMaker(); | ||
$database->createModel(); | ||
}); | ||
//----------------------------------------------------------------- | ||
$kernel->call('make:resource', function () { | ||
$resource = new ResourceMaker(); | ||
$resource->createResources(); | ||
}); | ||
|
||
$kernel->call('remove:resource', function () { | ||
$resource = new ResourceMaker(); | ||
$resource->removeResources(); | ||
}); | ||
//----------------------------------------------------------------- | ||
$kernel->call('make:api', function () { | ||
$resource = new ApiMaker(); | ||
$resource->createApi(); | ||
}); | ||
|
||
$kernel->call('remove:api', function () { | ||
$resource = new ApiMaker(); | ||
$resource->removeApi(); | ||
}); | ||
//----------------------------------------------------------------- | ||
$kernel->call('serve', function () { | ||
$server = new ServerMaker(); | ||
$server->serve(); | ||
}); | ||
|
||
$kernel->call('start:apiserver', function () { | ||
$server = new ServerMaker(); | ||
$server->runApiServer(); | ||
}); | ||
|
||
$kernel->call('start:openswoole', function () { | ||
$server = new ServerMaker(); | ||
$server->runOpenswoole(); | ||
}); | ||
|
||
$kernel->call('setWebhook', function () { | ||
$server = new ServerMaker(); | ||
$server->setWebhook(); | ||
}); | ||
|
||
$kernel->call('deleteWebhook', function () { | ||
$server = new ServerMaker(); | ||
$server->deleteWebhook(); | ||
}); | ||
//----------------------------------------------------------------- | ||
$kernel->call('get:eloquent', function () { | ||
$installer = new Installer(); | ||
$installer->install_Eloquent(); | ||
}); | ||
|
||
$kernel->call('remove:eloquent', function () { | ||
$installer = new Installer(); | ||
$installer->uninstall_Eloquent(); | ||
}); | ||
|
||
$kernel->call('get:amphp', function () { | ||
$installer = new Installer(); | ||
$installer->install_Amphp(); | ||
}); | ||
|
||
$kernel->call('remove:amphp', function () { | ||
$installer = new Installer(); | ||
$installer->uninstall_Amphp(); | ||
}); | ||
|
||
$kernel->call('get:openswoole', function () { | ||
$installer = new Installer(); | ||
$installer->install_Openswoole(); | ||
}); | ||
|
||
$kernel->call('remove:openswoole', function () { | ||
$installer = new Installer(); | ||
$installer->uninstall_Openswoole(); | ||
}); | ||
|
||
$kernel->call('get:redis', function () { | ||
$installer = new Installer(); | ||
$installer->install_Redis(); | ||
}); | ||
|
||
$kernel->call('remove:redis', function () { | ||
$installer = new Installer(); | ||
$installer->uninstall_Redis(); | ||
}); | ||
|
||
$kernel->call('clear:vendor', function () { | ||
$installer = new Installer(); | ||
$installer->clear_vendor(); | ||
}); | ||
//----------------------------------------------------------------- | ||
$kernel->shutdown(); |
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,33 @@ | ||
<?php | ||
|
||
namespace Bot\Core\Cli\Action; | ||
|
||
use Bot\Core\Cli\Error\Logger; | ||
|
||
class DatabaseMaker | ||
{ | ||
private mixed $cmd; | ||
|
||
public function __construct() | ||
{ | ||
global $argv; | ||
$this->cmd = $argv; | ||
} | ||
|
||
public function createModel(): void | ||
{ | ||
if (!isset($this->cmd[2])) { | ||
Logger::status('Warning', 'Enter the Model name!', 'warning'); | ||
return; | ||
} | ||
|
||
$migrationPage = str_replace('&&&', $this->cmd[2], file_get_contents('Core/Cli/Layout/mysqlModel.txt')); | ||
$fileName = 'App/Model/' . $this->cmd[2] . '.php'; | ||
if (file_exists($fileName)) { | ||
Logger::warning('Model is already exist!'); | ||
} else { | ||
file_put_contents($fileName, $migrationPage); | ||
Logger::success('Mysql Model Created Successfully!'); | ||
} | ||
} | ||
} |
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,169 @@ | ||
<?php | ||
|
||
namespace Bot\Core\Cli\Action; | ||
|
||
use Bot\Core\Cli\Error\Logger; | ||
use Symfony\Component\Process\Process; | ||
|
||
class Installer | ||
{ | ||
private mixed $cmd; | ||
|
||
public function __construct() | ||
{ | ||
global $argv; | ||
$this->cmd = $argv; | ||
} | ||
|
||
public function install_Eloquent(): void | ||
{ | ||
if (file_exists('vendor/illuminate/database')){ | ||
Logger::status('Failed', 'Database Eloquent already installed!', 'failed', true); | ||
} | ||
|
||
$command = new Process(["composer", "require", "illuminate/database", "illuminate/events", "doctrine/dbal"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('Database Eloquent Installed Successfully!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
|
||
public function uninstall_Eloquent(): void | ||
{ | ||
if (!file_exists('vendor/illuminate/database')){ | ||
Logger::status('Failed', 'Database Eloquent not installed!', 'failed', true); | ||
} | ||
|
||
$command = new Process(["composer", "remove", "illuminate/database", "illuminate/events", "doctrine/dbal"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('Database Eloquent Removed Successfully!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
|
||
public function install_Amphp(): void | ||
{ | ||
if (file_exists('vendor/amphp')){ | ||
Logger::status('Failed', 'AMPHP already installed!', 'failed', true); | ||
} | ||
|
||
$command = new Process(["composer", "require", "amphp/http-client"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('AMPHP Installed Successfully!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
|
||
public function uninstall_Amphp(): void | ||
{ | ||
if (!file_exists('vendor/amphp')){ | ||
Logger::status('Failed', 'AMPHP not installed!', 'failed', true); | ||
} | ||
|
||
$command = new Process(["composer", "remove", "amphp/http-client"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('AMPHP Removed Successfully!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
|
||
public function install_Openswoole(): void | ||
{ | ||
if (file_exists('vendor/openswoole')){ | ||
Logger::status('Failed', 'OpenSwoole already installed!', 'failed', true); | ||
} | ||
|
||
$command = new Process(["composer", "require", "openswoole/core"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('OpenSwoole Installed Successfully!'); | ||
}else{ | ||
Logger::failed('Failed to install OpenSwoole!'); | ||
if (str_contains($command->getErrorOutput(), 'requires ext-openswoole')){ | ||
Logger::message('Make sure the openswoole extension is installed!'); | ||
}else{ | ||
Logger::message('Make sure you are connected to the network! '); | ||
Logger::message('If the problem is not solved, directly use the command'); | ||
Logger::message(' >> composer require openswoole/core '); | ||
} | ||
} | ||
} | ||
|
||
public function uninstall_Openswoole(): void | ||
{ | ||
if (!file_exists('vendor/openswoole')){ | ||
Logger::status('Failed', 'OpenSwoole not installed!', 'failed', true); | ||
} | ||
|
||
$command = new Process(["composer", "remove", "openswoole/core"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('OpenSwoole Removed Successfully!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
|
||
public function install_Redis(): void | ||
{ | ||
$command = new Process(["composer", "require", "ext-redis:*"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('Ext-Redis Installed Successfully!'); | ||
}else{ | ||
Logger::failed('Failed to install Ext-Redis!'); | ||
} | ||
} | ||
|
||
public function uninstall_Redis(): void | ||
{ | ||
$command = new Process(["composer", "remove", "ext-redis:*"]); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('Ext-Redis Removed Successfully!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
|
||
public function clear_vendor(): void | ||
{ | ||
$command = ["composer", "remove"]; | ||
if (file_exists('vendor/openswoole')){ | ||
$command[] = "openswoole/core"; | ||
} | ||
|
||
if (file_exists('vendor/amphp')){ | ||
$command[] = "amphp/http-client"; | ||
} | ||
|
||
if (file_exists('vendor/illuminate/database')){ | ||
$command = array_merge($command, ["illuminate/database", "illuminate/events", "doctrine/dbal"]); | ||
} | ||
|
||
$command = new Process($command); | ||
$command->start(); | ||
$command->wait(); | ||
if ($command->isSuccessful()) { | ||
Logger::success('Vendor was successfully cleared!'); | ||
}else{ | ||
Logger::failed('An error occurred!'); | ||
} | ||
} | ||
} |
Oops, something went wrong.