Skip to content

Commit

Permalink
update library jefyokta/oktaax
Browse files Browse the repository at this point in the history
  • Loading branch information
jefyokta committed Nov 12, 2024
1 parent 0147af3 commit 62ba33c
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 35 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
APP_NAME=Kamelapermai
APP_HOST=kamela-permai.oktaa
APP_PORT=8000
APP_KEY=

DB_HOST=127.0.0.1
DB_NAME=Kamela
DB_USER=root
DB_PASSWORD=
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# kamela2

### Requirement
- wsl or docker (if you using windows)
- php 8.1+
- php-ext openswoole

### Built with:
Frontend: blade,tailwindcss,flowbite
Backend: Php, jefyokta/oktaax
Database: Mysql

21 changes: 20 additions & 1 deletion app/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

use Swoole\Coroutine;


class Command
{


public function handle(array $argument)
{

switch ($argument[1]) {
case 'start':

require_once __DIR__ . "/../../index.php";
break;

Expand All @@ -22,6 +24,23 @@ public function handle(array $argument)
$test = require __DIR__ . "/../Test/Test.php";
$test->run();
break;
case "migrate":
require_once __DIR__ . "/../init.php";

foreach (glob(__DIR__ . "/../Models/*.php") as $model) {

require $model;

$modelName = basename($model, ".php");
$fullClassName = "Kamela\\Models\\" . $modelName;

if (class_exists($fullClassName)) {
$fullClassName::migrate();
} else {
echo "migration failed for $modelName\n";
}
}
break;
default:
# code...
break;
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function guest(Request $req, Response $res)
{
$guest = Guest::select("*");

if ($req->get['filter'] == null) {
if (!isset($req->get['filter'])) {
$guest = $guest;
} else {
if ($req->get['filter'] ?? false) {
Expand Down
10 changes: 8 additions & 2 deletions app/Models/Gallery.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php
namespace Kamela\Models;

namespace Kamela\Models;
use oktaa\Database\Database;

class Gallery extends Database
{
protected string $table = 'gallery';

}
protected array $definition = [
"id" => "INT AUTO_INCREMENT PRIMARY KEY",
"typeid" => "VARCHAR(255) NOT NULL",
"img" => "VARCHAR(255) NOT NULL",
"name" => "VARCHAR(255) NOT NULL",
];
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"jefyokta/oktaax": "^2.0.2",
"jefyokta/oktaax": "^2.0.3",
"firebase/php-jwt": "^6.10",
"vlucas/phpdotenv": "^5.6"

Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use PDOException;
use InvalidArgumentException;
use Oktaax\Console;
use Swoole\Coroutine;
use Swoole\Process;

Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL);

Expand Down Expand Up @@ -48,9 +50,15 @@ public function __construct()

if (!$databaseExists) {
Console::warning(" database `{$this->db} doesnt'nt exist`");
Console::info("Creating....");
$pdo->exec("CREATE DATABASE `$this->db`");
Console::info("Database {$this->db} created!");

$accept = readline("wanna create it?[y/n]\n");
if (stripos($accept, 'y') === false) {
exit(0);
} else {
Console::info("Creating....");
$pdo->exec("CREATE DATABASE `$this->db`");
Console::info("Database {$this->db} created!");
}
}

$this->dbh = new PDO(config('db.connection') . ":host=$this->host;port=$this->port;dbname=$this->db", $this->user, $this->password);
Expand Down
19 changes: 1 addition & 18 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,6 @@
]);
});

$app->get("/trigger", function ($req, $res) {
go(function () use ($res) {
$client = new Client('kamela-permai.oktaa', 8000, true);

if ($client->upgrade("/notification/house")) {
$message = json_encode([
'event' => 'booking',
'message' => 'Ada tamu baru yang membooking rumah!'
]);
$client->push($message);
$res->end();
} else {
echo "Upgrade ke WebSocket gagal.";
}
});
});


$app->ws("/notification", [Notification::class, 'handle'])
->ws("/notification/house", [Notification::class, 'house']);
Expand All @@ -251,6 +234,6 @@

$app
->withSSL(__DIR__ . "/cert/kamela-cert.pem", __DIR__ . "/cert/kamela-key.pem")
->listen(8000, "kamela-permai.oktaa", function ($url) {
->listen(3000, "kamela-permai.oktaa", function ($url) {
Console::log("Server Started on {$url}");
});
27 changes: 25 additions & 2 deletions okta
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
#!/usr/bin/env php

<?php

use Oktaax\Console;
use Swoole\Coroutine;
use Swoole\ExitException;

require_once __DIR__ . "/app/Command/Command.php";

require_once __DIR__ . "/vendor/autoload.php";

$argument = $argv;


$command = new Command();
$command->handle($argument);
if (count($argument) > 1) {

Coroutine::run(function () use ($argument) {
$command = new Command();
try {
$command->handle($argument);
} catch (ExitException $e) {
Console::info("Swoole Exit!");
} catch (\Throwable $th) {
Console::error($th->getMessage());
}
});
} else {
echo "empty arguments!\n";

}

0 comments on commit 62ba33c

Please sign in to comment.