tamedevelopers / support
Support Package For PHP and PHP Frameworks
Installs: 224
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: >=8.0
- composer-plugin-api: ^2.0
- ext-ctype: *
- ext-mbstring: *
- cocur/slugify: ^4.2.0
- dompdf/dompdf: ^3.0
- filp/whoops: ^2.15
- phpmailer/phpmailer: ^6.9
- symfony/console: ^6.0
- symfony/var-dumper: *
- vlucas/phpdotenv: ^5.4.1
Suggests
- dompdf/dompdf: Required to use the `PDF` class and helper (^3.0)
- dev-master
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2025-09-05 22:49:46 UTC
README
Support Package For PHP and Laravel
Documentation
- Requirements
- Installation
- All Paths
- Number to Words
- Tame
- Str
- Usage
- phone
- mask
- html
- text
- shorten
- random
- formatString
- formatOnlyString
- encrypt
- decrypt
- bindings
- flattenValue
- exceptArray
- replaceFirst
- replaceLast
- renameArrayKeys
- forgetArrayKeys
- changeKeyCase
- convertArrayCase
- padLeft
- padRight
- words
- ascii
- is
- snake
- camel
- kebab
- title
- studly
- slugify
- slug
- before
- after
- between
- contains
- truncate
- reverse
- count
- countOccurrences
- uuid
- randomWords
- extension
- wrap
- head
- last
- Country
- File
- Collection
- Usage
- has
- count
- all
- isNotEmpty
- isEmpty
- isSame
- isDuplicate
- reverse
- pad
- combine
- collapse
- flatten
- zip
- merge
- only
- except
- chunk
- keys
- values
- filter
- reject
- where
- whereIn
- whereNotIn
- whereNull
- whereNotNull
- first
- firstWhere
- last
- contains
- doesntContain
- every
- some
- select
- map
- mapWithKeys
- pluck
- pluckDot
- groupBy
- search
- sort
- sortBy
- sortByMany
- sortByDesc
- sortKeys
- sortKeysDesc
- keyBy
- slice
- take
- takeUntil
- skip
- concat
- union
- toBase
- pipe
- crossJoin
- join
- unique
- each
- forget
- changeKeyCase
- reduce
- shuffle
- partition
- tap
- chunkWhile
- nth
- paginate
- zipWith
- countBy
- duplicates
- shuffleKeys
- average
- avg
- sum
- max
- min
- Zip
- Time
- time-usage
- now
- date
- today
- yesterday
- createFromFormat
- timestamp
- toJsTimer
- diff
- diffBetween
- ago
- range
- format
- toDateTimeString
- addSeconds
- subSeconds
- addMinutes
- subMinutes
- addHours
- subHours
- addDays
- subDays
- addWeeks
- subWeeks
- addMonths
- subMonths
- addYears
- subYears
- greeting
- allTimezone
- setTimeZone
- getTimeZone
- HttpRequest
- Cookie
- Hash
- Asset
- View
- Env
- Manager
- Server
- Autoload Register
- Helpers Functions
- Error Dump
- Error Status
- Useful links
Requirements
>= php 8.0+
Installation
Prior to installing support package
get the Composer dependency manager for PHP because it'll simplify installation.
composer require tamedevelopers/support
All Paths
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 |
Number to Words
- Has three chainable methods
- Can translate all the way to
vigintillion
- It's helper class can be called, using --
NumberToWords()
- 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 |
Iso
- Takes param as
string
and case-insensitive
NumberToWords::iso('nga');
Cents
- 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);
Value
- 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);
toText
- 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ş
toNumber
- 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
Tame
- The Core Class of Components
- It's helper class can be called, using --
Tame()
- It's helper class can be called, using --
use Tamedevelopers\Support\Tame;
byteToUnit
- 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
unitToByte
Tame()->unitToByte('24mb'); // Output: 25165824
fileTime
- Returns last edited time of the file as an -
int|false
Tame()->fileTime(base_path('filepath.php'));
exists
- Checks if a file exists and is not a directory -
bool
Tame()->exists(base_path('filepath.php')); // Output: true or false
unlink
- 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');
mask
- 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 visible characters. 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 * ). |
Example:
Tame()->mask('example@email.com', 4, 'left'); // Output: "exam***@email.com" Tame()->mask('example@email.com', 4, 'right'); // Output: "e***mple@email.com" Tame()->mask('shortstring', 4, 'center'); // Output: "sh*******ng"
imageToBase64
- 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)
emailValidator
- 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('example@example.com'); // Output: true (Valid email with domain check using DNS) Tame()->emailValidator('example@example.com', false); // Output: true (Valid format only, no internet or DNS checks) Tame()->emailValidator('example@example.com', true, true); // Output: true or false (Valid format with domain and server verification)
platformIcon
- 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' |
Example
$platform = Tame()->platformIcon('windows'); // Output: /path/to/icons/platform/windows.svg include $platform;
paymentIcon
- 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 |
Example
$payment = Tame()->paymentIcon('paypal'); // Output: /path/to/icons/payment/paypal.svg include $payment;
calPercentageBetweenNumbers
- Calculates the percentage relationship between two numbers as an -
int
Tame()->calPercentageBetweenNumbers(100, 80);
formatNumberToNearestThousand
- Formats a number to its nearest thousand, million, billion, or higher as a -
string|float|int
Tame()->formatNumberToNearestThousand(1500000); // Output: "1.5m"
Str
- The Core Class For String Manipulations
- It's helper class can be called, using --
TameStr()
- It's helper class can be called, using --
Str Usage
use Tamedevelopers\Support\Str; // Replace first/last occurrence Str::replaceFirst('foo', 'bar', 'foofoo'); // 'barfoo' Str::replaceLast('foo', 'bar', 'foofoo'); // 'foobar' // Word limiting & ASCII Str::words('The quick brown fox jumps', 3); // 'The quick brown...' Str::ascii('Jürgen'); // 'Jurgen' // Padding Str::padLeft('7', 3, '0'); // '007' Str::padRight('7', 3, '0'); // '700' // Pattern matching Str::is('user/*', 'user/42'); // true Str::contains('brown', 'The quick brown fox'); // true // Case/format helpers Str::snake('Hello World'); // 'hello_world' Str::camel('hello world'); // 'helloWorld' Str::kebab('Hello World'); // 'hello-world' Str::title('hello world'); // 'Hello World' Str::studly('hello world'); // 'HelloWorld' Str::slug('Hello World!'); // 'hello-world' Str::slugify('À bientôt'); // 'a-bientot' // Slicing Str::before('user:42', ':'); // 'user' Str::after('user:42', ':'); // '42' Str::between('a[core]z', '[', ']'); // 'core' // Transformations Str::reverse('abc'); // 'cba' Str::truncate('lorem ipsum', 5); // 'lo...' // Randoms Str::random(8); // 'a1B9...' Str::uuid(); // 'xxxxxxxx-xxxx-4xxx-...' Str::randomWords(3); // 'lor em ip' // Arrays Str::exceptArray(['a'=>1,'b'=>2], 'a'); // ['b'=>2] Str::renameArrayKeys([['id'=>1]], 'id', 'user_id');// [['user_id'=>1]] Str::forgetArrayKeys(['a'=>1,'b'=>2], 'a'); // ['b'=>2] Str::bindings(['where'=>[1,2], 'join'=>[3]]); // [1,2,3] Str::flattenValue([[1,2],[3]]); // [1,2,3] Str::convertArrayCase(['Name'=>['Age'=>1]], 'lower', 'upper'); // ['name'=>['age'=>1]] // Security/text helpers Str::phone('+1 (555) 123-4567'); // '+15551234567' Str::mask('1234567890', 4, 'right'); // '******7890' Str::html('<b>Hi</b>'); // '<b>Hi</b>' Str::text('<b>Hi</b>'); // 'Hi' Str::shorten('Long sentence here', 10); // 'Long sente...' Str::encrypt('secret'); // encrypted Str::decrypt('...'); // original
Country
- Country data and helpers
- Class:
Tamedevelopers\Support\Country
- It's helper class can be called, using --
TameCountry()
- Class:
Country Usage
- ISO codes and flags
use Tamedevelopers\Support\Country; Country::getCountryIso3('name'); Country::getCountryIso2('name'); Country::getCountryFlagIso3('name'); Country::getCountryFlagIso2('name');
- Months, Weeks, Time Zones, Captcha Locale
Country::getMonths('short'); Country::getWeeks('mon'); Country::getTimeZone('Europe/London'); Country::getCaptchaLocale('en');
File
- The Core File utilities (read, write, copy, move, info).
- Class:
Tamedevelopers\Support\Capsule\File
- It's helper class can be called, using --
TameFile()
- Class:
File Usage
use Tamedevelopers\Support\Capsule\File; // Create directory File::makeDirectory(storage_path('logs')); // Write & read File::put(storage_path('logs/app.log'), 'Hello'); $content = File::get(storage_path('logs/app.log')); // 'Hello' // Info File::exists(storage_path('logs/app.log')); // true File::size(storage_path('logs/app.log')); // int bytes File::extension(storage_path('logs/app.log')); // 'log' File::lastModified(storage_path('logs/app.log')); // timestamp // Move/Copy/Delete File::copy(storage_path('logs/app.log'), storage_path('logs/app_copy.log')); File::move(storage_path('logs/app_copy.log'), storage_path('logs/app_moved.log')); File::delete(storage_path('logs/app_moved.log')); // List files $files = File::files(storage_path('logs')); // array of SplFileInfo
Collection
- Lightweight collection utilities.
- Class:
Tamedevelopers\Support\Collections\Collection
- It's helper class can be called, using --
TameCollect() | tcollect()
- Class:
Collection Usage
use Tamedevelopers\Support\Collections\Collection; $users = new Collection([ ['id' => 1, 'name' => 'Ada'], ['id' => 2, 'name' => 'Ben'], ['id' => 3, 'name' => 'Cee'], ]); $users->isEmpty(); // false $users->count(); // 3 $users->keys()->all(); // [0,1,2] $users->values()->all(); // same as original but reindexed // Keep only specific keys from an associative array $profile = new Collection(['id'=>1,'name'=>'Ada','role'=>'admin']); $profile->only('id', 'name')->all(); // ['id'=>1,'name'=>'Ada'] $profile->except('role')->all(); // ['id'=>1,'name'=>'Ada'] // Filtering $even = (new Collection([1,2,3,4]))->filter(fn($v) => $v % 2 === 0)->all(); // [2,4] // Merge/Chunk/Reverse (new Collection([1,2]))->merge([3,4])->all(); // [1,2,3,4] (new Collection(range(1,6)))->chunk(2)->all(); // [[1,2],[3,4],[5,6]] (new Collection([1,2,3]))->reverse()->all(); // [3,2,1]
- 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@example.com') ->subject('subject') ->body('<div>Hello Body</div>') ->send();
to
- Accepts multiple emails as
array|string
Mail::to('email@example.com') Mail::to(['email@example.com', 'email2@example.com']) Mail::to('email@example.com', 'email2@example.com', 'email3@example.com')
attach
- 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'], ])
subject
- Accepts mandatory
string
Mail::subject('subject');
body
- Accepts mandatory
string
Mail::subject('body');
send
- Accepts [optional] closure/function
Mail::to('email@example.com')->send(); Mail::to('email@example.com')->send(function($reponse){ // $reponse });
flush
- Accepts mandatory
bool
Default value is false- Clear buffers and send email in the background without waiting (But only to be used when using an API/Submitting via Ajax/Fetch or similar method of form submission)
Mail::to('email@example.com') ->body('<p>Body Text</p>') ->flush(true) ->send();
Zip
- Takes two param as
string
- [sourcePath] path to zip-directory
- [destination] path to save zip file
TameZip()->zip('app/Http', 'app.zip')
Unzip
- Takes two param as
string
- [sourcePath] path of zip-file
- [destination] path to unzip-directory
TameZip()->unzip('newData.zip', base_path('public/zip'))
Zip Download
- Takes two param as
string | boolean
- [fileName] 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
- It's helper class can be called, using --
TamePDF()
- It's helper class can be called, using --
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 |
PDF Usage
Tamedevelopers\Support\PDF $generate = strtotime('now') . '.pdf'; PDF::create([ 'content' => '<h1>Hello World!</h1>', 'destination' => public_path("invoice/{$generate}"), 'output' => 'view', ]);
Read PDF
- Takes one param as
string
- [path] absolute path to PDF file
TamePDF()->read('invoice100.pdf') // This will read the PDF to the browser
Time
- Class:
\Tamedevelopers\Support\Time
- It's helper class can be called, using --
TameTime()
- It's helper class can be called, using --
Time Usage
- Get time date from class
function name | Description |
---|---|
sec() | getSec() |
Get seconds from time |
min() | getMin() |
Get minutes |
hour() | getHour() |
Get hour |
day() | getDay() |
Get days |
week() | getWeek() |
Get weeks |
month() | getMonth() |
Get months |
year() | getYear() |
Get years |
time() | getTime() |
Get time as int |
$time = new Time('now', 'Africa/Lagos'); [ $time4->time(), $time4->sec(), $time4->min(), $time4->hour(), $time4->day(), $time4->week(), $time4->month(), $time4->year(), ]
now
- Returns the Time Object with current timestamp of
now
$time->now()->format()
date
- Accepts one param as (time)
int|string
$time->date("first day of this month")->toDateTimeString()
today
- Thesame as
now()
with timestamp oftoday
yesterday
- Thesame as
now()
with timestamp ofyesterday
$time->today(); $time->yesterday();
createFromFormat
- Accepts two parameter [date, format]
- only [date] is mandatory and returns the Time(object)
$time->createFromFormat('24 Jan 2025 14:00:00', 'm/d/Y h:ia'); // object(Tamedevelopers\Support\Time)
timestamp
- Accepts two parameter [date, format]
- only [date] is mandatory and returns formated timestamp
$time->timestamp('24 Jan 2025 14:00:00'); // Output: 2025-01-24 14:00:00
toJsTimer
- Accept one parameter as [date]. Returns formated javascript timestamp
$time->toJsTimer('24 Jan 2025 14:00:00'); $time->jsTimer('24 Jan 2025 14:00:00'); // Output: Jan 24, 2025 14:00:00
diff
- Takes one paramater as
mode
. Different between the given date a current time asnow
- Return an array if [mode] is not found or value of
mode set
- Return an array if [mode] is not found or value of
mode |
---|
year | month | hour | mins | sec | days | weeks |
$time->date('last year december')->diff('month'); // Output: 1
diffBetween
- Takes three paramater as
firstDate \| lastDate \| mode
. Thesame as diff.
$time->diffBetween('last year december', 1737752400, 'weeks'); // Output: 4
ago
ago() or timeAgo()
, Takes one paramater asmode
mode |
---|
full | short | duration | time | date | date_time | time_stamp |
$time->date('today')->ago() $time->date('today')->timeAgo() // Output: [ "full" => "4 hours ago" "short" => "4h" "duration" => 4 "time" => 1737752400 "date" => "24 Jan, 2025" "date_time" => "24 Jan, 2025 10:01am" "time_stamp" => "Jan 24, 2025 10:00:00" ]
range
- Build date range according to value given
- Accepts (2) params
value and format
- Accepts (2) params
$time->range('0-10', 'D, M j') // Output: returns class of Tamedevelopers\Support\Capsule\TimeHelper
get output
- To get the output, we need to call the TimeHelper format method
- The format() method takes two [optional] param.
start, year
as boolean
- The format() method takes two [optional] param.
$time->range('0-10')->format(true, true) // Output: Thu, Jan 23 - Tue, Mar 4, 2025 $time->range('0-10')->format() // Output: Tue, Mar 4
addSeconds
- Can be called using boht [plural|singular] formats. To add more dates with already existing time.
$time4->now()->addMonth(3)->addSeconds(2)->addDays(2)->format()
subSeconds
- Can be called using boht [plural|singular] formats. To subtract dates from already existing time.
$time4->now()->subMonth(3)->subSecond(2)->subDays(2)->format()
allTimezone
Time::allTimezone();
setTimeZone
Time::setTimeZone('Pacific/Pago_Pago');
getTimeZone
Time::getTimeZone();
HttpRequest
- Http Request Helper
- It's helper class can be called, using --
TameRequest()|urlHelper()
urlHelper()
was older method name. We still keep for older project support.
- It's helper class can be called, using --
use Tamedevelopers\Support\Process\HttpRequest; use Tamedevelopers\Support\Process\Http; // same as HttpRequest $http = TameRequest(); [ Http::url(), HttpRequest::server(), HttpRequest::method(), $http->full(), $http->request(), $http->referral(), $http->http(), $http->host(), $http->path(), ]
Cookie
- Class:
\Tamedevelopers\Support\Cookie
- It's helper class can be called, using --
TameCookie()
- It's helper class can be called, using --
Cookie Usage
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 |
Set
- 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'); // TameCookie()->set('user', '__user');
Get
- Takes param as
string
Cookie::get('cookie_name');
Forget
- Takes
3 param
- Mandatory
$name
param asstring
- [optional]
$path
param asstring | null
- [optional]
$domain
param asstring | null
- Mandatory
Cookie::forget('cookie_name');
Has
- Takes param as
string
- Returns
bool
- Returns
if(Cookie::has('cookie_name')){ // execute code }
Hash
Hash Usage
- Password hashing and verify
use Tamedevelopers\Support\Hash; bcrypt('testPassword'); // or Hash::make('testPassword'); // $2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6
hash-make
Hash::make('secret');
hash-check
$oldPassword = "$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6"; Hash::check('testPassword', $oldPassword); // or native password_verify('testPassword', $oldPassword);
Asset
- Takes a param as
string
path to asset file- Default [dir] is set to
public
- It's helper class can be called, using --
tasset()
- Default [dir] is set to
use Tamedevelopers\Support\Asset; Asset::asset('css/style.css'); // - Returns // http://domain.com/assets/css/style.css
Asset Config
- Takes three param as
string
- It's helper class can be called, using --
config_asset()
- It's helper class can be called, using --
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] // config_asset('public');
Asset Cache
- 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 --
using helper method
// absolute path config_asset('storage/main.js', true); // Output: http://domain.com/storage/main.js?v=111111111 // relative url path config_asset('storage/style.css', true, true); // Output: /storage/style.css?v=111111111
View
View Usage
- Basic usage with layout and sections
use Tamedevelopers\Support\View; // Using a child view that extends a layout $view = new View('tests.layout.home2', [ 'title' => 'Homepage', ]); echo $view->render();
- Rendering multiple times safely (same instance)
$view = new View('tests.layout.home2', [ 'title' => 'Homepage', ]); // First render echo $view->render(); // Second render (fresh render, no duplicated sections) echo $view->render();
- Render and capture as a string
$html = (new View('tests.layout.home2', ['title' => 'Homepage']))->render();
View Support
- Supported extensions for views [only resolves filename]
- Similar Laravel blade syntax usage
$extensions = [ '.php', // Generic / CodeIgniter / CakePHP 4+ '.blade.php', // Laravel '.twig', // Symfony/Twig generic '.html.twig', // Symfony typical ];
Samples
@extends('layout.partials.app') @section('content') <h1>Welcome to the Homepage!</h1> @endsection @include('layout.partials.footer', ['year' => 2025]) @yield('content') @foreach($condition as $value) @endforeach @if($condition) @else @endif
View Helper
- It's helper class can be called, using --
tview()
// set base folder for views // [optional], but when set - this will be the default path to look for view files. tview()->base('tests'); // Create a view instance via helper and render $view = tview('layout.home2', ['title' => 'Homepage']); echo $view->render(); // One-liner (render via static call) use Tamedevelopers\Support\View; echo View::render('layout.home2', ['title' => 'Homepage']);
Env
- By default it use the default root as
.env
path, so mandatory to install vendor in root directory.
Env Create
- To create an environment
.env
file. Create or ignore if exists
use Tamedevelopers\Support\Env; Env::createOrIgnore()
Env Load
- 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 // Just as the name says. It'll load the `.env` file or fail with status code of 404. An error Env::loadOrFail('path_to_env_folder')
Env Update
- Returns
true|false
. Used to update env variables- It's helper class can be called, using --
env_update()
- It's helper class can be called, using --
Params | Description |
---|---|
key | ENV key |
value | ENV value |
quote | true | false - Default is true (Allow quotes within value) |
space | true | false - Default is false (Allow space between key and value) |
use Tamedevelopers\Support\Env; Env::updateENV('DB_PASSWORD', 'newPassword'); env_update('DB_CHARSET', 'utf8', false);
Server
- Return instance of
Server
- It's helper class can be called, using --
server()
- It's helper class can be called, using --
Get Servers
- Returns assoc arrays of Server
server\|domain
use Tamedevelopers\Support\Server; Server::getServers(); // server()->getServers('domain');
Create Custom Config
- 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 --
using helpers
server()->config("en/message.{$key}", "message.{$key}", 'Lang'); server()->config("app.name");
Manager
Key Management
- The package enforces a valid application key in
.env
asAPP_KEY
. - If
APP_KEY
is missing, invalid, or manually altered, the application will return HTTP 500 until a new key is generated via the API below.
use Tamedevelopers\Support\Capsule\Manager; // Generate and persist a new key to .env and the fingerprint store Manager::regenerate(); // Or ensure env is booted then enforce key (called internally) Manager::startEnvIFNotStarted();
- Valid key format is Laravel-style:
base64:
followed by base64 of 32 random bytes.
Helper tmanager
- You can use the helper for convenience:
// Generate and persist a new key tmanager()->regenerate(); // Optionally start env and enforce key tmanager()->startEnvIFNotStarted();
Autoload Register
- Takes a
string|array
as parameter- Register one or more folders containing your PHP files
- Automatically loads
Files|Classes
in the folder and sub-folders
use Tamedevelopers\Support\AutoloadRegister; // Single folder AutoloadRegister::load('folder'); // Multiple folders AutoloadRegister::load(['folder', 'folder2']); // Or use the helper autoload_register('folder'); autoload_register(['folder', 'folder2']);
Helpers Functions
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 |
Error Dump
function | Description |
---|---|
dump | Dump Data |
dd | Dump and Die |
Useful Links
- @author Fredrick Peterson (Tame Developers)
- If you love this PHP Library, you can Buy Tame Developers a coffee