A Simple/Minimal PHP Web Framework.
bibioo-php is a simple/minimal PHP web framework. It's easy to use and requires no complex setup. Just setup your Database details and you are good to go.
To start. Let's first clone this repository with the below command
Now we change directory into the cloned project
cd bibioo-php
Next is to setup your database (MySQL/MariaDB only) plus a few config values.
The Config.php
file can be loacted in <PROJECT_ROOT/Api/Config.php>
<?php
// DATABASE
$_config['DB'] = 'bibioo_db'; // Change this
$_config['DB_USER'] = 'root'; // Change this
$_config['DB_PASSWORD'] = ''; // Change this
$_config['DB_HOST'] = '127.0.0.1'; // Change this
// GENERAL
$_config['SESSION_NAME'] = '_bibioo_api';
$_config['SESSION_COOKIE_HTTP_ONLY'] = 1;
Once the approriate config is set. We can start by creating some endpoints.
All Api endpoints must be created in the index.php
file located in the project root.
<?php
Route::get('/api/v1/items', function ($page = 1, $limit = 2, $otherBy = ['id'], $sortDirection = 'DESC') {
$database = Database::getInstance();
if ( !is_array($otherBy) ) {
$otherBy = explode(",", urldecode($otherBy));
}
$result = $database->findPaged('items', $page, $limit, $otherBy, $sortDirection);
$pager = [
'page' => $page,
'limit' => $limit,
'sortParams' => $otherBy,
'sortDirection' => $sortDirection,
'total' => $result['count']
];
$response = Response::newInstance(0, $result['data'], $pager);
$response->render();
});
<?php
Route::post('/api/v1/items', function ($payload = null) {
$database = Database::getInstance();
$id = $database->save('items', $payload);
if ( $id ) {
$payload['id'] = $id;
}
$response = Response::newInstance(0, $payload);
$response->render();
});
<?php
Route::get('/api/v1/items/:id', function ($id) {
$database = Database::getInstance();
$result = $database->findById('items', $id);
$response = Response::newInstance(0, $result);
$response->render();
});
Route::put('/api/v1/items/:id', function ($payload = null, $id) {
$database = Database::getInstance();
$updated = $database->updateRecord('items', $id, $payload);
$response = Response::newInstance(0, $updated);
$response->render();
});
Route::delete('/api/v1/items/:id', function ($id) {
$database = Database::getInstance();
$deleted = $database->delete($id, 'items');
$response = Response::newInstance(0, $deleted);
$response->render();
});