PHP code example of ongom / hot-lib

1. Go to this page and download the library: Download ongom/hot-lib 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/ */

    

ongom / hot-lib example snippets


Hot\Hot::session('key', 'value');

Hot\Hot::session('active_user', ['user_id'=>2]);
// will set active_user to the session variable 

Hot\Hot::session('active_user');
// will get active_user from the session variable 

Hot\Hot::deleteSession('active_user');
// will delete session key called active_user from the session variable

Hot\Hot::deleteSession();
// unsets the session.


Hot\Hot::flash('seccess', 'sent the messege successfully');
// will set flash messege with key success 

Hot\Hot::flash('success');
// will get flash messege with key sucsess  

Hot\Hot::randomString(5);

Hot\Hot::randomLetters(5);

Hot\Hot::randomNumber(5);

Hot\Data::env(); //returns array;
Hot\Data::env('passcode'); //returns the value of the key;

public static function redirect(
        string $url,
        string|array|null $query = null,
        int $status = 302
    ): never 

//usage
Hot\Url::redirect('/login', ['name'=>'tom'], 300)
Hot\Url::redirect('https://www.youtube.com');

public static function redirectBack(
        string|array|null $query = null,
        int $status = 302
    ):never

//usage
Hot\Url::redirectBack(['name'=>'tom'], 300)

 public static function serverBase(string|array|null $query = null): string

//usage
Hot\Url::serverBase()
//https://ongom.com

public static function incoming(string|array|null $query = null): string

//usage
Hot\Url::incoming()
//https://ongom.com/home

public static function incomingBase(string|array|null $query = null): string
//usage
Hot\Url::incomingBase()

 public static function incomingPath(string|array|null $query = null): string

//usage
Hot\Url::incomingPath()

public static function body(bool $as_array = true):array|object|null
Hot\Request::body()

public static function params(bool $as_array = true):array|object|null
Hot\Request::params()

public static function post(bool $as_array = true):array|object|null
Hot\Request::post()

public static function get(bool $as_array = true):array|object|null
Hot\Request::get()

public static function files()
Hot\Request::files()

public static function json($data, int $status_code = 200)
Hot\Response::json()

public static function send($data, int $status_code = 200)
Hot\Response::send()

   public static function upload($files, array $options)
$options = [
            'allowed_extension'=>['jpg','png'], //(optional)
            'min_size'=>3, //optionsl in kb (optional)
            'max_size'=>6, //optional in kb (optional)
            'upload_path'=>'path/to/upload/directory', //(optional)
            'new_name'=>'mode_term_2' //optional
            'fixed_name'='any unique upload filename' //optional
            ];
Hot\Files::upload($_FILES['files'], $options);
// min size = 5 and max size = 20

Hot\Files::delete('logo.png','path/to/directory',); 
//or
Hot\Files::delete(['logo.png','image.jpg'] , 'path/to/directory');

Hot\Files::getFiles('logo.png','path/to/directory');
//
Hot\Files::getFiles(['logo.png','image.jpg'],'/public/uploads');
//
Hot\Files::getFiles(['logo.png','image.jpg'],'path/to/directory', 'default.png');

Hot\Files::exist('logo.png','path/to/directory/');

Hot\Files::exist('logo.png','/public/uploads');

public static function numberToWords(float|int $number): string
// usage
Hot\Number::numberToWords(1002);
//one thousand two 

public static function currency(float $amount, string $code): string
// usage
Hot\Number::currency(1002, 'USD');
//one thousand two  US dollars

Hot\Number::sequence(1,8,3);
// OR
Hot\Number::sequence(8, 5, 0.2);

Hot\Number::format(10000);
// 10,000
Hot\Number::format(10000000, '.');
//10.000.000

Hot\Number::martix(10000);
// 10K
Hot\Number::martix(10000000, 2);
//10.00M

Hot\Hot::chop('Test text', 1, 6);
// Test t
Hot\Hot::chop([1,2,3,4,5,6,], 1, 4);
//[1,2,3,4]

Hot\Number::trancate(15.57, 1);
//15.5

Hot\Time::ago('2024-11-10 14:00:00');

Hot\Time::left('2024-11-15 11:38:00');

Hot\Password::hash('123456');

Hot\Password::verify('123455', '$pdojshjs...');

public static function encode(int|string $id, string $secret, int $length = 24): string

// Usage
$secret = "my_ultra_secret_key";
$publicId = Hot\SecureId::encode(1254, $secret);
// hu7ui78yu78FFhgfd

public static function decode(string $token, string $secret): string|false

// Usage  
$secret = "my_ultra_secret_key";
$id = Hot\SecureId::decode($publicId, $secret);
// 1254

public static function encrypt(int $id, $secret): string

// Usage
$publicId = Hot\SecureId::encrypt(1254, $secret);
// hu7ui7P

public static function decrypt(string $hash): int

// Usage  
$id = Hot\SecureId::decrypt($hash);
// 1254

public static function encode(int|string $id, ?string $secret=null)

// Usage
$token = Id::encode($id); // Endcodes
$id = Id::decode($token) // Id  

// or 

// Usage
$token = Id::encrypt($id, $secret = null); // Endcodes
$id = Id:: decrypt($has, $secret = null) // Id  



View::setViewPath(__DIR__ . '/views');
View::setLayoutPath(__DIR__ . '/layouts');
View::setComponentPath(__DIR__ . '/views/components');
View::setCachePath(__DIR__ . '/storage/views');
View::setViewExtension('.blade.php');
View::setGlobalVariables(['global_name'=>'I am global']);

View::render(string $view, array $data = [], ?string $layout = null):void;

// Template file with layout
View::render('home', ['name'=>'Felix'], 'main');
// 
View::render('/home', ['name'=>'Felix'], 'main');
// 
View::render('dashboard.home', ['name'=>'Felix'], 'main');
// 
View::render('<h1>Hello <?= $name 

View::fetch(string $view, array $data = [], ?string $layout = null): string

//Escaped automatically
<?= $var 

<?= $current_layout 

View::setGlobalVariables(['global_name'=>'I am global']);

//OR

View::render('home', ['global_name'=>'I am global'], 'main');

  View::setComponentPath(__DIR__ . '/views/components');

  <div> profile: <?= $user['name'] 

<x-profile user="$user" users="$users" count="5" />

//OR

<x-profile user="$user" users="$users" count="5"></x-profile>

//OR

<x-profile user="$user" users="$users" count="5">
  Profile HTML markup
</x-profile>

//OR
//acces components located in sub-folder
<x-admin.message.alert type="error" message="$msg">
  Hello
</x-admin.message.alert>

//OR

//Nested components

<x-post-card post="$post">
  <x-image img="$image">
  <x-post img="$post_content">
  display slot
</x-profile>


<main>
  <?= $$slot 
 
"storage/views/" //must be writable

project/
│── index.php
│── test.php
│── views/
│    ├── home.php
│    ├── user.php
│    └── partial.php
│── layouts/
|    ├── main.php
|    └── nested.php
── components/
    ├── dasboard
    |     └── navbar.php
    └── nested.php
 echo $$slot 
 echo $var 
 echo $var