mochrira / selvi-framework
Super fast PHP Framework for building API
Installs: 1 147
Dependents: 3
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
- dev-master
- 2.x-dev
- 2.2.0
- 2.1.17
- 2.1.16
- 2.1.15
- 2.1.14
- 2.1.13
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.3.x-dev
- 1.3.0
- 1.2.x-dev
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- 0.4.15
- 0.4.14
- 0.4.13
- 0.4.12
- 0.4.11
- 0.4.10
- 0.4.9
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.55
- 0.3.54
- 0.3.53
- 0.3.52
- 0.3.51
- 0.3.50
- 0.3.49
- 0.3.48
- 0.3.47
- 0.3.46
- 0.3.45
- 0.3.44
- 0.3.43
- 0.3.42
- 0.3.41
- 0.3.40
- 0.3.39
- 0.3.38
- 0.3.37
- 0.3.36
- 0.3.35
- dev-master-2.0
This package is auto-updated.
Last update: 2025-07-02 07:16:05 UTC
README
⚡ Super fast PHP Framework for building API
Quick Start
- Get this framework via composer on your project directory (inside www folder if you are using Apache)
$ composer require mochrira/selvi-framework
- Create
app/Controllers
folder inside your project directory - Create file
HomeController.php
insideapp/Controllers
with this content
<?php
namespace App\Controllers;
use Selvi\Controller;
class HomeController extends Controller {
function index() {
return response('Welcome to Selvi Framework');
}
}
- Create index.php
<?php
require('vendor/autoload.php');
Selvi\Routing\Route::get('/', 'App\\Controllers\\HomeController@index');
Selvi\Framework::run();
- Create
.htaccess
file
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
- Edit your composer.json
{
...
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
...
}
- Run
composer update
to update your composer autoload - Done. Open
http://localhost/your-project
on your browser to test it
Database Configuration
- Buka http://localhost:1000, buat database baru dengan nama
example_app
- Buat file
app/Config/database.php
dengan konten sebagai berikut:
<?php
use Selvi\Database\Manager;
use Selvi\Database\Migration;
use Selvi\Cli;
Manager::add('main', [
'driver' => 'mysql',
'host' => 'mariadb.database',
'username' => 'root',
'password' => 'changeme',
'database' => 'example_app'
]);
Migration::addMigrations('main', [ BASEPATH.'/app/Migrations' ]);
Cli::register('migrate', Migration::class);
- Modifikasi file
index.php
dengan menambahkan baris berikut setelah require vendor
<?php
require __DIR__.'/vendor/autoload.php';
define('BASEPATH', __DIR__); // tambahkan baris ini
require __DIR__.'/app/Config/database.php'; // tambahkan baris ini
Selvi\Routing\Route::get('/', 'App\\Controllers\\HomeController@index');
\Selvi\Framework::run();
Migration
- Buat folder
app/Migrations
- Buat file
20250702_01_init.php
(format : YYYYMMDD_{index}_{konteks}.php), dengan konten sebagai berikut :
<?php
return function ($schema, $direction) {
if($direction == 'up') :
$schema->create('kontak', [
'idKontak' => 'INT(11) PRIMARY KEY AUTO_INCREMENT',
'nmKontak' => 'VARCHAR(150)',
'nomor' => 'VARCHAR(50)'
]);
endif;
if($direction == 'down') :
$schema->drop('kontak');
endif;
};
- Jalankan migrasi dengan perintah
php index.php migrate main up
Swagger UI
- Buat file
www/specs/index.html
dengan konten sebagai berikut :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="SwaggerUI" />
<title>SwaggerUI</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" crossorigin></script>
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: './index.yaml',
dom_id: '#swagger-ui',
persistAuthorization: true
});
};
</script>
</body>
</html>
- Buat file
www/specs/index.yaml
dengan konten sebagai berikut :
openapi: '3.0.2'
info:
title: Kontak API
version: '1.0'
servers:
- url: http://localhost:8080
description: Development
paths:
/kontak:
get:
summary: Mengambil semua data kontak
tags: [Kontak]
parameters:
- in: query
name: offset
schema:
type: integer
- in: query
name: limit
schema:
type: integer
- in: query
name: search
schema:
type: string
responses:
'200':
description: Semua object kontak dalam database
post:
summary: Menambahkan kontak baru
tags: [Kontak]
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
nmKontak:
type: string
nomor:
type: string
example:
nmKontak: Moch. Rizal
nomor: 82143255597
responses:
'201':
description: Berhasil menambahkan kontak
/kontak/{idKontak}:
get:
summary: Mengambil kontak berdasarkan ID
tags: [Kontak]
parameters:
- in: path
required: true
name: idKontak
schema:
type: integer
responses:
'200':
description: Object kontak terpilih
patch:
summary: Mengubah kontak berdasarkan ID
tags: [Kontak]
parameters:
- in: path
required: true
name: idKontak
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
nmKontak:
type: string
nomor:
type: string
example:
nmKontak: Moch. Rizal Rachmdani
nomor: 82143255597
responses:
'204':
description: Berhasil merubah kontak
delete:
summary: Menghapus kontak berdasarkan ID
tags: [Kontak]
parameters:
- in: path
required: true
name: idKontak
schema:
type: integer
responses:
'204' :
description: Kontak berhasil dihapus