Support Package For PHP and Laravel
- Requirements
- Installation
- All Paths
- Number to Words
- Tame
- Str
- Zip
- Time
- now
- ago
- sec
- min
- day
- hour
- weeks
- month
- year
- today
- date
- format
- yesterday
- timestamp
- toJsTimer
- getSeconds
- getMinutes
- getHours
- getDays
- getWeeks
- getMonths
- getYears
- addSeconds
- subSeconds
- addMinutes
- subMinutes
- addHours
- subHours
- addDays
- subDays
- addWeeks
- subWeeks
- addMonths
- subMonths
- addYears
- subYears
- greeting
- timeDiff
- dateRange
- allTimezone
- setTimeZone
- getTimeZone
- toDateTimeString
- setGlobalTimeZone
- getGlobalTimeZone
- UrlHelper
- Cookie
- Hash
- Asset
- Env
- Server
- Autoload Register
- Helpers Functions
- Error Dump
- Error Status
- Useful links
>= php 8.0+
Prior to installing support package
get the Composer dependency manager for PHP because it'll simplify installation.
composer require tamedevelopers/support
function name | Description |
---|---|
base_path() | Get absolute base directory path. Accepts a param string if given, and append to path |
directory() | Thesame as base_path() |
public_path() | Root/public path. Accepts a param string if given, and append to path |
storage_path() | Root/storage path. Accepts a param string if given, and append to path |
app_path() | Root/app path. Accepts a param string if given, and append to path |
config_path() | Root/config path. Accepts a param string if given, and append to path |
lang_path() | Root/lang path. Accepts a param string if given, and append to path |
domain() | Returns domain URI. Accepts a param string if given, and append to path |
- Has three chainable methods
- Can translate all the way to
vigintillion
- Can translate all the way to
iso (country iso3) | cents | number |
---|---|---|
NGA | GBR | USA |
true | false |
int|float|string |
If iso is given and found, it'll automatically converts the text into a currency format |
If you want the decimals to be translated to text as well. | numeric figures: 299 | '42,982' | 3200.98 |
- Takes param as
string
and case-insensitive
NumberToWords::iso('nga');
- Takes param as
boolean
. Default isfalse
- By default, it doesn't format the decimals
.00
Must be set to true, to format if needed.
- By default, it doesn't format the decimals
NumberToWords::cents(true);
- Takes one param as
int | float | string
- If numbers is larger than a trillion
1_000_000_000_000
, then the value must be passed as a string.
- If numbers is larger than a trillion
NumberToWords::value(1290);
- Convert number to readable words
- Below, we're using the function helper method
NumberToWords()
->iso('TUR')
->value('120.953')
->cents(true)
->toText();
// Output: One hundred and twenty lira, nine hundred and fifty-three kuruş
- Convert words to number
- comma
,
is used to seperate decimals in words
- comma
use Tamedevelopers\Support\NumberToWords;
NumberToWords::value('twelve million three hundred thousand, six hundred and ninety-eight')
->cents(true)
->toNumber()
// Output: 12300000.698
- The Core Class of Components
- It's helper class can be called, using --
Tame()
- It's helper class can be called, using --
Tamedevelopers\Support\Tame
- Accepts 5 param. first param alone is needed
- All other params are [optional]
Params | Description |
---|---|
bytes | The size in bytes to be converted |
format | Whether to preserve case (default: lowercase) |
gb | Custom label for GB (default: 'GB') |
mb | Custom label for MB (default: 'MB') |
kb | Custom label for KB (default: 'KB') |
Tame()->byteToUnit(6880);
// Output: 7kb
Tame()->unitToByte('24mb');
// Output: 25165824
- Returns last edited time of the file as an -
int|false
Tame()->fileTime(base_path('filepath.php'));
- Checks if a file exists and is not a directory -
bool
Tame()->exists(base_path('filepath.php'));
// Output: true or false
- Deletes a file from the server if it exists and does not match the restricted file name -
void
- [optional] second param <filename.extension>
Tame()->unlink(base_path('path/to/directory/avatar.png'), 'default.png');
- Masks characters in a string based on position and length, with support for emails and custom masking characters.
Params | Description |
---|---|
$str |
The string to be masked. |
$length |
The number of characters to mask (default is 4). |
$position |
The position to apply the mask: 'left' , 'center' , or 'right' (default is 'right' ). |
$mask |
The character used for masking (default is * ). |
Tame()->mask('[email protected]', 4, 'left');
// Output: "****[email protected]"
Tame()->mask('[email protected]', 4, 'right');
// Output: "exa****@email.com"
Tame()->mask('shortstring', 4, 'center');
// Output: "sho****ing"
- Converts an image file to its Base64 representation. Supports local files and direct URLs -
null|string
Tame()->imageToBase64(base_path('path/to/image.jpg'));
// Output: "data:image/jpg;base64,..." (Base64 string for the image)
Tame()->imageToBase64('https://example.com/image.png', true);
// Output: "data:image/png;base64,..." (Base64 string for the URL image)
- Validates an email address with optional domain and server verification -
bool
Params | Description |
---|---|
The email address to validate. | |
use_internet | By default is set to false . If true , checks the domain using DNS (checkdnsrr() and getmxrr() ) for validity. If false , skips domain validation (default: false ). |
server_verify | Verifies the mail server by checking MX records (default: false ). Only used if use_internet is true . |
Tame()->emailValidator('[email protected]');
// Output: true (Valid email with domain check using DNS)
Tame()->emailValidator('[email protected]', false);
// Output: true (Valid format only, no internet or DNS checks)
Tame()->emailValidator('[email protected]', true, true);
// Output: true or false (Valid format with domain and server verification)
- Returns the path to the SVG icon for the specified platform or operating system.
Params | Description |
---|---|
$platform |
Platform name windows | linux | android | mobile | phone | unknown | mac | macintosh | ios | iphone | c | os x |
$os_name |
OS name 'macos' , 'os x' , 'ios' |
$platform = Tame()->platformIcon('windows');
// Output: /path/to/icons/platform/windows.svg
include $platform;
- Retrieves the path to the SVG icon for a specified payment method.
Params | Description |
---|---|
$payment |
add-money | alipay | bank | cc | credit-card | discover | faster-pay | groupbuy | maestro | mastercard | pay | payme | payment-card | payment-wallet | paypal | stripe-circle | tripe-sqaure | stripe | visa |
$payment = Tame()->paymentIcon('paypal');
// Output: /path/to/icons/payment/paypal.svg
include $payment;
- Calculates the percentage relationship between two numbers as an -
int
Tame()->calPercentageBetweenNumbers(100, 80);
- Formats a number to its nearest thousand, million, billion, or higher as a -
string|float|int
Tame()->formatNumberToNearestThousand(1500000);
// Output: "1.5m"
- The Core Class For String Manipulations
- It's helper class can be called, using --
TameStr()
- It's helper class can be called, using --
Tamedevelopers\Support\Str
- The Core Class/Wrapper For
PHPMailer
- It's helper class can be called, using --
TameMail()
- It's helper class can be called, using --
Tamedevelopers\Support\Mail
Mail::to('[email protected]')
->subject('subject')
->body('<div>Hello Body</div>')
->send();
- Accepts multiple emails as
array|string
Mail::to('[email protected]')
Mail::to(['[email protected]', '[email protected]'])
Mail::to('[email protected]', '[email protected]', '[email protected]')
Mail::to('[email protected], [email protected]')
- Accepts multiple complex data as attachment as
array|string
Mail::attach(public_path("image.png"), 'New File Name')
Mail::attach(['path' => public_path("image.png"), 'as' => 'New name'])
Mail::attach([
['path' => public_path("image.png"), 'as' => 'New name'],
['path' => public_path("image2.zip"), 'as' => 'New name2'],
['path' => public_path("image3.jpeng"), 'as' => 'New name2'],
])
- Accepts mandatory
string
Mail::subject('subject');
- Accepts mandatory
string
Mail::subject('body');
- Accepts [optional] closure/function
Mail::to('[email protected]')->send();
Mail::to('[email protected]')->send(function($reponse){
// $reponse
});
- Takes two param as
string
- [sourcePath] relative path of zip-file
- [destination] relative folder path to save zip file
TameZip()->zip('app/Http', 'app.zip')
- Takes two param as
string
- [sourcePath] relative path of zip-file
- [destination] relative folder path to unzip-file
TameZip()->unzip('newData.zip', '/public/zip')
- Takes two param as
string | boolean
- [fileName] relative path of zip-file
- [unlink] Default is
true
unlinks file after download
TameZip()->download('newData.zip')
- Require package to be installed -
composer require dompdf/dompdf
options | Description |
---|---|
content string |
HTML Content |
paper_size string |
Default is A4 --- letter | legal |
paper_type string |
Default is portrait --- landscape |
destination string |
Full path to where file has to be save public_path(invoice/file.pdf) |
By default it saves the pdf generated by timename to your project root [dir] |
| output string
| Default is view
--- save \| download
|
| isRemoteEnabled bool
| Default is false
--- true
If the content of html contains file/image link |
| title string
| If the html content of PDF has no title, file name will automatically become the title |
| delete bool
| Default is true
--- false
If output is view
you can choose to delete file after preview |
Tamedevelopers\Support\PDF
$generate = strtotime('now') . '.pdf';
PDF::create([
'content' => '<h1>Hello World!</h1>',
'destination' => public_path("invoice/{$generate}"),
'output' => 'view',
]);
- or --
Helpers Function
TamePDF()->create([
'content' => '<h1>Hello World!</h1>',
'destination' => public_path("invoice/{$generate}"),
'output' => 'save',
]);
- Takes one param as
string
- [path] absolute path to PDF file
TamePDF()->read('invoice100.pdf')
This will read the PDF to the browser
- Helper function is called using
TameTime()
- Visit the Tests/ folder to see more examples.
$time = TameTime('now', 'Africa/Lagos');
- Build date range according to value given
- Accepts (2) params
value and format
- Accepts (2) params
use Tamedevelopers\Support\Time;
$time = new Time();
$time->dateRange('0-10', 'D, M j')
// Output: returns class of Tamedevelopers\Support\Capsule\TimeHelper
To get the output, we need to call the TimeHelper format method
The format() method takes two [optional] param. `start, year` as boolean
$time->dateRange('0-10', 'D, M j')
->format(true, true)
// Output: Thu, Jan 23 - Tue, Mar 4, 2025
$time->dateRange('0-10', 'D, M j')
->format()
// Output: Tue, Mar 4
Time::allTimezone();
Time::setTimeZone('Pacific/Pago_Pago');
Time::getTimeZone();
Time::setGlobalTimeZone('Pacific/Pago_Pago');
Time::getGlobalTimeZone();
[
urlHelper()->server(),
urlHelper()->url(),
urlHelper()->full(),
urlHelper()->request(),
urlHelper()->referral(),
urlHelper()->http(),
urlHelper()->host(),
urlHelper()->path(),
]
function name | Description |
---|---|
set() | Used to set cookie |
get() | Used to get cookie |
forget() | Used to expire cookie |
expire() | Same as forget method |
all() | Get all available cookie |
has() | Cookie exists |
- Takes
7 param
- Mandatory
$name
param asstring
- [optional]
$value
param asstring | null
- [optional]
$minutes
param asint | string
- [optional]
$path
param asstring | null
- [optional]
$domain
param asstring | null
- [optional]
$secure
param asbool | null
- [optional]
$httponly
param asbool | null
- Mandatory
use Tamedevelopers\Support\Cookie;
Cookie::set('cookie_name', 'value');
- Takes param as
string
Cookie::get('cookie_name');
- Takes
3 param
- Mandatory
$name
param asstring
- [optional]
$path
param asstring | null
- [optional]
$domain
param asstring | null
- Mandatory
Cookie::forget('cookie_name');
- Takes param as
string
- Returns
bool
- Returns
if(Cookie::has('cookie_name')){
// execute code
}
- or --
Helpers Function
TameCookie()->set('user', '__user');
- Password hashing and verify
use Tamedevelopers\Support\Hash;
bcrypt('testPassword');
or
Hash::make('testPassword');
// $2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6
$oldPassword = "$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6";
Hash::check('testPassword', $oldPassword)
password_verify('testPassword', $oldPassword);
- Takes a param as
string
path to asset file- Default [dir] is set to
public
- Default [dir] is set to
use Tamedevelopers\Support\Asset;
Asset::asset('css/style.css');
- Returns
http://domain.com/assets/css/style.css
- or --
Helpers Function
tasset('css/style.css');
- Takes three param as
string
params | Description |
---|---|
base_path | PAth to file |
cache | By Default is false . Tell method to include cache for each file |
path_type | By Default is false , which uses absolute path for all files. While true will use relative path |
use Tamedevelopers\Support\Asset;
Asset::config('public/storage');
- Returns
http://domain.com/public/storage/[asset_file]
- or --
Helpers Function
config_asset('public');
- By Default,
cache
is set tofalse
- You'll see a link representation as
http://domain.com/[path_to_asset_file]?v=111111111
- You'll see a link representation as
Asset::config('storage', false);
- Returns
http://domain.com/storage/[asset_file]
- or --
Helpers Function
asset_config('storage/main.js', true);
// Output: http://domain.com/storage/main.js?v=111111111
asset_config('storage/style.css', true, true);
// Output: /storage/style.css?v=111111111
- By default it use the default root as
.env
path, so mandatory to install vendor in root directory.
- To load the environment
.env
file- Takes optional param as
string
$path
- Takes optional param as
use Tamedevelopers\Support\Env;
Env::load('path_to_env_folder')
- or --
loadOrFail('optional_path')
- Just as the name says. It'll load the
.env
file or fail with status code of 404. An error logger will also be created insidestorage/logs/orm.log
- Just as the name says. It'll load the
Env::loadOrFail('path_to_env_folder')
- Returns
true|false
. Used to update env variables
Params | Description |
---|---|
key | ENV key |
value | ENV value |
allow_quote | true | false - Default is true (Allow quotes within value) |
allow_space | true | false - Default is false (Allow space between key and value) |
use Tamedevelopers\Support\Env;
Env::updateENV('DB_PASSWORD', 'newPassword');
- or --
Helpers Function
env_update('DB_CHARSET', 'utf8', false);
- Return instance of
Server
- Returns assoc arrays of Server
server\|domain
use Tamedevelopers\Support\Server;
Server::getServers();
- or --
Helpers Function
server()->getServers('domain');
- With this helper you can be able to create your own custom config by extending the Default Config Method
- When using this model, make sure every of your php file returns an associative array for the key to work
Params | Description |
---|---|
key | File array key |
default | Default value if no data is found from the key |
folder | Folder to search from and Default folder is config |
use Tamedevelopers\Support\Server;
Server::config('tests.lang.email', [], 'Tests');
- Create our own config to extends the default
/**
* Custom Language Handler
*
* @param mixed $key
* @return mixed
*/
function __lang($key){
// since the config only takes the filename follow by dot(.) and keyname
// then we can manually include additional folder-name followed by / to indicate that it's a folder
// then message.key_name
// To make this Laravel kind of language, we can add the default value to be returned as the key
// Do not forget that it starts from your root base directory, as the Package already has your root path
return Server()->config("en/message.{$key}", "message.{$key}", 'lang');
}
--- Structure of folder example
--- (d) for directory and (f) for file
Base/
├── Lang/
│ ├── en/
| | ────── message.php (File)
| | ────── error.php (File)
| |
│ ├── tr/
| | ────── message.php (File)
| | ────── error.php (File)
│ └── ...
└── ...
- or --
Helpers Function
server()->config("en/message.{$key}", "message.{$key}", 'Lang');
server()->config("app.name");
- Takes an
string\|array
as param- You can use register a folder containing all needed files
- This automatically register
Files\|Classes
in the folder and sub-folders.
use Tamedevelopers\Support\AutoloadRegister;
AutoloadRegister::load('folder');
or
autoload_register(['folder', 'folder2]);
function name | Description |
---|---|
env() | env method To get environment variable |
server() | Return instance of (new Server) class |
to_array() | array Convert value to array |
to_object() | object Convert value to object |
to_json() | string Convert value to json |
function | Description |
---|---|
dump | Dump Data |
dd | Dump and Die |
- @author Fredrick Peterson (Tame Developers)
- If you love this PHP Library, you can Buy Tame Developers a coffee