Hati - A powerful PHP library written in PHP 8 with various library functions and classes to make API or App development effortless.

Fund package maintenance!
Paypal

Installs: 181

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 2

Type:hati-installer

v5.0.0 2024-01-01 03:46 UTC

README

                                                  .'``'.__
                                                 /      \ `'"-,
                                .-''''--...__..-/ .     |      \
                              .'               ; :'     '.  a   |
                             /                 | :.       \     =\
                            ;                   \':.      /  ,-.__;.-;`

PHP Version Require Latest Stable Version Total Downloads License

Welcome to the Hati wiki! Hati is a powerful PHP library written in PHP 8 which has various library functions and classes to make API or application development in PHP effortless. This library has great support for crafting:-

  • APIs development support
  • Form data & request validations
  • Basic Template engine
  • Email functions [using PHPMailer]
  • Easy file uploading
  • Multiple database operations
  • Simplistic Date-Timing functions
  • Number crunching utility functions etc.
  • Zip files creation

Hati utilizes composer autoload. You can use apache's dot htaccess file to prepend the Hati init file which will require 'vendor/autoload.php' behind the scene to resolve the loader dependencies. Many aspect of Hati can be configured by using the configuration files found on project root hati/hati.json & hati/db.json.

Hati comes with a few tools which are found on the project root's hati/tool folder. These tools are used to help working with multiple database, API documentation etc.

Library functions, class names are inspired by Bengali language. Many common words from Bengali language such Kuli, Biscut, Shomoy are found within this library.

Install

Install the latest version using:

composer require rootdata21/hati

Or add to your composer.json file as a requirement:

{
    "require": {
        "rootdata21/hati": "~5.0.0"
    }
}

Setup

  1. Hati can only be used in PHP 8 or above. In order to set up the Hati, you can use the htaccess file provided with the library to prepend the "hati/init.php" file or manually require it using require function.
  2. Adjust the "hati/hati.json" file to configure the environment.

Demo

Below an API is written using Fluent class to perform database query where sql is prepared and behind the scene and the result is fetched using datum method. With traditional approach such task would take up to 10 lines. Hati really shrinks down the line of code you have to write over and over again. Finally, it return the output as JSON to requester.

<?php

/*
 * Register the API in the "api/hati_api_registry.php" file using
 * HatiAPIHandler::register method.
 */
\hati\api\HatiAPIHandler::register([
	'method' => 'GET',
	'path' => 'welcome/get',
	'handler' => 'v1/ExRate.php',
	'description' => 'A GET API'
]);

// Use a specific database connection
Fluent::use(DBPro::exampleDb); 

// search the name by id from the database table using PDO extension
$id = 5;
Fluent::exePrepared("SELECT name FROM user WHERE user.id = ?", [$id]);

// get the name value from the select statement with simple datum method
$name = Fluent::datum('name');

// craft and reply JSON output
$response = new Response();
$response -> add('name', $name);
$response -> reply('Operation has been done', header: [
    'X-EXAMPLE-HEADER: SOMETHING',
    'Content-Type: application/json'
]);

Output

Hitting the API at: https://example.com/api/welcome/get

{
    "name": "Abdul Ahad",
    "response": {
        "status": 1,
        "msg": "Operation has been done"
    }
}

Donation/Support

If you find this project helpful then why don't you buy the developer a cup of tea? Any amount of donation is appreciated. Please follow the link to donate by using PayPal. PayPal Payment

License

This project is maintained under MIT license.