Download the PHP package ongom/hot-lib without Composer
On this page you can find all versions of the php package ongom/hot-lib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ongom/hot-lib
More information about ongom/hot-lib
Files in ongom/hot-lib
Package hot-lib
Short Description A PHP library for providing most of the common PHP function like session, flash messeging, view/template engine, URL methodes, encrypting id and also file hundling.
License MIT
Informations about the package hot-lib
Hot-lib
This is a php library that provides most of the common methods used in controller. It has on it static methods like;
session()
It saves and retrieve session variable. You don't need to start session.
deleteSession()
Will delete the session key from the the session variable. If no parameter is passed, it unset the entire session.
flash()
It sets and retrieve flash messege. This messege will appear only once. It also uses sessinon under in the background.
randomString()
Generate random string of default length 8. Takes in the length of the string as one parameter.
randomLetters()
Generate random letters of default length 8. Takes in the length of the string as one parameter.
randomNumber()
Generate random number of default length 8. Takes in the length of the string as one parameter. Returns a string of numbers
env()
It reads a particular evironment variable from the .env file. It returns the value of the key passed. If no key is passed it returns the whole env array results.
URL
redirect()
Redirect to any URL. It takes in the new redirect route, array or string query params and status.
redirectBack()
Redirects the request back to the url it is comming from. It takes in array or string query params and status and a status code.
serverBase()
Returns the base URL of the the server you are currently running the website on. Server base URL (domain only)
incoming()
Returns the full URL where the request is comming from. Full incoming URL (path + query)
incomingBase
Base URL of incoming request (includes app subfolder)
incomingPath()
Returns the incoming path only (no scheme, no host)
Request
body()
Gets request body from an api call. It can return Object or array or null
params()
Gets request query params from an api call. It can return Object or array or null
post()
Gets posted data from a form in post request. It can return Object or array or null
get()
Gets posted data from a form in a get request. It can return Object or array or null
files()
Gets file(s) submited from form or api call. It can return the file or null
Response
json()
Converts array or object to json object. Has no effect on numbers and strings.
send()
Converts array or object to json object and send back. Has no effect on numbers and strings.
Files
upload()
It uploads single or multiple files locally on the server. It also renames the files before saving it. Takes in array parameter,and it retuns a string for single file, array for multiple files and false for failure to upload.
delete()
It deletes any file from the server. It takes in a string or array of filenames and the directory where it is stored.
getFiles()
It gets all the files from the provided directory. It take in an array or string of filename, and the derectory where the files is stored and an optional fallback image which can either be a link or the file on the server.
exist()
checks if a file exist in the directory. Takes in the file path and returns a boolean.
Number
numberToWords()
Converts number to word upto the range of trillion.
currency
Converts money to words
sequence()
Generate and returns sequence of number from down to up or from up to down. Takes in the three number parameter; from, to and steps.
format()
It formats the number with commas by default. It takes in the number and an optional formatter, if formatter is not passed, it default to comma.
matrix()
Converts large numbers to shorthands like 10M for 10000000, 1.3k for 1300, etc. It takes in the number and the optional precision.
chop()
It cuts some part of the array or string off from some position to a particular position.
trancate()
Instead of rounding off, it trancates the number to some required precision.
ago()
Takes in the date or time and returns how much time has passed. Returns false if less than 1 seconds.
left()
Takes in the date or time ahead and returns how much time is left. Returns false if less than 1 seconds.
Password
hash()
Takes in plain text and reterns the hash. There more methods with different algorithms like bcrypt(123456), algon2i(123456), algon21i(123456)
verify()
Takes in plain text and hashed text then, reterns a boolean, true for match and false for not matching.
SecureId
A PRO ID encryption system built specifically for; numeric DB IDs, UUIDs / strings, public URLs, constant length output, URL-safe, reversible, collision-safe and faster than normal OpenSSL usage.
It has methods encode/encrypt for encrypting the content and decode/decrypt for decrypting the content to original.
Encode
Decode
Encrypt
It encrypts numerical values to random string that is reversible
Decrypt
It brings back the original number thar was decrypted. What this protects against are /user/abc@@ → null, /user/zzzzz → null, /user/ → null, tampered token → null, non-integer results → null.
Only valid encoded IDs return a number.
Id
Secure method (AES encryption — recommended). Use OpenSSL so the ID cannot be guessed or reversed.
View Engine
This is a lightweight, class-based PHP View Engine that allows you to:
- Render template files.
- Use layouts with slots as
<?= $$slot ?>or `` to render content. - Use layouts optionally and support nested layouts via component slot.
- Automatically echo output via
View::render()or return as string viaView::fetch().
FEATURES
- Dot-notation views (dashboard.home)
- Dot-notation components (admin.message.alert)
- Sub-folders for views, layouts, components
- Inline HTML / text templates auto-detected
- Single API: render() / fetch() only
- Component variable isolation
- Slot support
- Cached compilation
- Escaped & raw output
- Nested components
Setting Paths
setViewPath: Define the directory where your template files reside.setLayoutPath: Define the directory where your layout files reside.setComponentPath: Define the directory where your components files reside.setCachePath: Define the directory where your cache files reside.setViewExtension: Define the extension of the view, layout and component files.setGlobalVariables: Define global variables to the view, layout and component files.
Rendering Templates
render()
- Automatically echoes the output.
- Accepts template file name (from
viewPath). - Accepts inline string (from
viewPath). - Navigate folders though dot notation
dashboard.home - Passind data as associtive array
- Optional layout wraps the content.
Example:
fetch()
- Works like
render(), but returns the content as string instead of echoing. - Useful for storing or manipulating the rendered content before output.
Template Syntax
Variables
- Basic variable: Normal PHP echo syntax,
<?= $var ?>and `` - Nested variables: Access with normal php syntax.
- Global variables
Basic Variables and Nested Variables
Global Variables
This are variables that can automatically be access every where within the page/view. Current component, current layout, current view/page and current pathname are accessed anywhere within the app by default as below
Setting global Variables
There are two ways of passing youn own global variables to view/page too.
- Using
View::setGlobalVariables(['tab'=> 'Home Tab']); - Using
globalsubstring in the varable name when passing variable through view/fetch.
Components / Partials
Set up path to component directory
Create an html file in that directory eg. profile.html, Add content to you html. You can have sub-folders in components folder too
Display the component within your templete using its name as before
Example: in the templete
Component Summary table for paaing vairiables to components
| Data type | Supported | Access in component |
|---|---|---|
| String | ✓ | $title |
| Integer | ✓ | $count |
| Boolean | ✓ | $isAdmin |
| Array | ✓ | $users[] |
| Object | ✓ | $user->name |
| Closure | ✓ | $callback() |
| Slot content | ✓ | $$slot |
Available variables in components
-
$$slot → inner content
-
All passed props → $text, $class, etc.
-
Props are unlimited.
-
Props are scoped to the component.
Layouts and Slots
-
Use a layout:
View::render('home', $data, 'main') - Inside layouts, the child content is available as
<?= $$slot ?>just like in components
Example Project Structure
View Caching
- Compiled templates are cached to disk for high performance.
How it works
-
Templates compile once
-
Cached PHP files are reused
- Cache invalidates automatically when source files change
Security Notes
-
<?= $var ?>is always escaped -
<?= $$var ?>is raw (use carefully) -
Components and layouts share the same escape rules
- Avoid rendering untrusted content with raw syntax
Best Practices
-
Always prefer
<?= $var ?>and `` unless HTML is trusted -
Use components for reusable UI
-
Keep layouts minimal
-
Do not edit cached files manually
- Clear storage/views/cached during deployments if needed