PHP code example of jodijonatan / jo-server
1. Go to this page and download the library: Download jodijonatan/jo-server library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jodijonatan / jo-server example snippets
LKSCore\Core\{Router, Database};
// Konfigurasi Database
Database::init([
'host' => 'localhost',
'db' => 'lks_db',
'user' => 'root',
'pass' => ''
]);
// CORS
Router::handleCORS();
// Routes
Router::get('/api/products', 'ProductController@index');
Router::post('/api/products', 'ProductController@store', [[AuthManager::class, 'protect']]);
Router::put('/api/products/{id}', 'ProductController@update', [[AuthManager::class, 'protect']]);
Router::delete('/api/products/{id}', 'ProductController@destroy', [[AuthManager::class, 'protect']]);
Router::run();
use LKSCore\Core\{Database, Schema};
// Migration
Schema::drop('products');
Schema::create('products', function($table) {
$table->id();
$table->string('name');
$table->decimal('price');
$table->text('description');
$table->timestamps();
});
// CRUD
$products = Database::table('products')->all();
$product = Database::table('products')->find(1);
$filtered = Database::table('products')->where('price', '>', 100)->orderBy('name')->all();
$id = Database::table('products')->insert(['name' => 'Item', 'price' => 50000]);
Database::table('products')->where('id', 1)->update(['name' => 'Updated']);
Database::table('products')->where('id', 1)->delete();
use LKSCore\Core\Request;
// Simple ', 'password']);
// Advanced validation
$data = Request::validate([
'email' => '
use LKSCore\Auth\AuthManager;
// Hash & Verify
$hashed = AuthManager::hash('password123');
$valid = AuthManager::verify('password123', $hashed);
// Generate & Decode Token
$token = AuthManager::generateToken(['id' => 1, 'role' => 'admin']);
$payload = AuthManager::decodeToken($token);
// Proteksi Endpoint
$user = AuthManager::protect(); // Cek token valid
$admin = AuthManager::
use LKSCore\Core\Controller;
class ProductController extends Controller {
public function index() {
$data = $this->db('products')->all();
$this->success("Data retrieved", $data);
}
public function store() {
$data = $this->validate(['name' => 'te(Request::only(['name', 'price']));
$this->success("Product updated");
}
public function destroy($id) {
$this->db('products')->where('id', $id)->delete();
$this->success("Product deleted");
}
}
text
src/
├── Auth/
│ └── AuthManager.php # Hash, Token (HMAC-SHA256), Protect, RequireRole
├── Core/
│ ├── Controller.php # Base Controller dengan helper methods
│ ├── Database.php # PDO Wrapper, Query Builder (where, orderBy, CRUD)
│ ├── Request.php # Input sanitasi, validasi rules, file upload
│ ├── Router.php # Regex Router, CORS, Middleware, Groups
│ └── Schema.php # Migration Builder
└── Utils/
├── Response.php # JSON Response formatter
└── ImageProcessor.php # GD Wrapper (resize, crop)
resources/
├── css/jo-ui.css # Complete UI library (layout + components)
└── js/jo-ui.js # Toast, Modal, Confirm, Loading helpers