PHP code example of tamedevelopers / support

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

    

tamedevelopers / support example snippets


NumberToWords::iso('nga');

NumberToWords::cents(true);

NumberToWords::value(1290);

NumberToWords()
    ->iso('TUR')
    ->value('120.953')
    ->cents(true)
    ->toText();

// Output: One hundred and twenty lira, nine hundred and fifty-three kuruş

use Tamedevelopers\Support\NumberToWords;

NumberToWords::value('twelve million three hundred thousand, six hundred and ninety-eight')
        ->cents(true)
        ->toNumber()

// Output: 12300000.698

use Tamedevelopers\Support\Tame;

Tame()->byteToUnit(6880);

// Output: 7kb

Tame()->unitToByte('24mb');

// Output: 25165824

Tame()->fileTime(base_path('filepath.php'));

Tame()->exists(base_path('filepath.php'));
// Output: true or false

Tame()->unlink(base_path('path/to/directory/avatar.png'), 'default.png');

Tame()->mask('[email protected]', 4, 'left');
// Output: "exam***@email.com"

Tame()->mask('[email protected]', 4, 'right');
// Output: "e***[email protected]"

Tame()->mask('shortstring', 4, 'center');
// Output: "sh*******ng"

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)

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)

$platform = Tame()->platformIcon('windows');
// Output: /path/to/icons/platform/windows.svg


$payment =  Tame()->paymentIcon('paypal');
// Output: /path/to/icons/payment/paypal.svg


Tame()->calPercentageBetweenNumbers(100, 80);

Tame()->formatNumberToNearestThousand(1500000);
// Output: "1.5m"

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('&lt;b&gt;Hi&lt;/b&gt;');                  // '<b>Hi</b>'
Str::text('<b>Hi</b>');                            // 'Hi'
Str::shorten('Long sentence here', 10);            // 'Long sente...'
Str::encrypt('secret');                            // encrypted
Str::decrypt('...');                               // original

use Tamedevelopers\Support\Country;

Country::getCountryIso3('name');
Country::getCountryIso2('name');
Country::getCountryFlagIso3('name');
Country::getCountryFlagIso2('name');

Country::getMonths('short');
Country::getWeeks('mon');
Country::getTimeZone('Europe/London');
Country::getCaptchaLocale('en');

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

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]

Tamedevelopers\Support\Mail

Mail::to('[email protected]')
        ->subject('subject')
        ->body('<div>Hello Body</div>')
        ->send();

Mail::to('[email protected]')

Mail::to(['[email protected]', '[email protected]'])

Mail::to('[email protected]', '[email protected]', '[email protected]')

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'],
])

Mail::subject('subject');

Mail::subject('body');

Mail::to('[email protected]')->send();

Mail::to('[email protected]')->send(function($reponse){

    // $reponse
});

Mail::to('[email protected]')
    ->body('<p>Body Text</p>')
    ->flush(true)
    ->send();

TameZip()->zip('app/Http', 'app.zip')

TameZip()->unzip('newData.zip', base_path('public/zip'))

TameZip()->download('newData.zip')

Tamedevelopers\Support\PDF

$generate = strtotime('now') . '.pdf';

PDF::create([
    'content'     => '<h1>Hello World!</h1>',
    'destination' => public_path("invoice/{$generate}"),
    'output'      => 'view',
]);

TamePDF()->read('invoice100.pdf')

// This will read the PDF to the browser

$time = new Time('now', 'Africa/Lagos');

[
    $time4->time(),
    $time4->sec(),
    $time4->min(),
    $time4->hour(),
    $time4->day(),
    $time4->week(),
    $time4->month(),
    $time4->year(),
]

$time->now()->format()

$time->date("first day of this month")->toDateTimeString()

$time->today();
$time->yesterday();

$time->createFromFormat('24 Jan 2025 14:00:00', 'm/d/Y h:ia');
// object(Tamedevelopers\Support\Time)

$time->timestamp('24 Jan 2025 14:00:00');
// Output: 2025-01-24 14:00:00

$time->toJsTimer('24 Jan 2025 14:00:00');
$time->jsTimer('24 Jan 2025 14:00:00');
// Output: Jan 24, 2025 14:00:00

$time->date('last year december')->diff('month');
// Output: 1

$time->diffBetween('last year december', 1737752400, 'weeks');
// Output: 4

$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"
]

$time->range('0-10', 'D, M j')
// Output: returns class of Tamedevelopers\Support\Capsule\TimeHelper

$time->range('0-10')->format(true, true)
// Output: Thu, Jan 23 - Tue, Mar 4, 2025

$time->range('0-10')->format()
// Output: Tue, Mar 4

$time4->now()->addMonth(3)->addSeconds(2)->addDays(2)->format()

$time4->now()->subMonth(3)->subSecond(2)->subDays(2)->format()

Time::allTimezone();

Time::setTimeZone('Pacific/Pago_Pago');

Time::getTimeZone();

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(),
]

use Tamedevelopers\Support\Cookie;

Cookie::set('cookie_name', 'value');
// TameCookie()->set('user', '__user');

Cookie::get('cookie_name');

Cookie::forget('cookie_name');

if(Cookie::has('cookie_name')){
    // execute code
}

use Tamedevelopers\Support\Hash;

bcrypt('testPassword');
// or
Hash::make('testPassword');

// $2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6

Hash::make('secret');

$oldPassword = "$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6";
Hash::check('testPassword', $oldPassword);
// or native
password_verify('testPassword', $oldPassword);

use Tamedevelopers\Support\Asset;

Asset::asset('css/style.css');

// - Returns
// http://domain.com/assets/css/style.css

use Tamedevelopers\Support\Asset;

Asset::config('public/storage');

// - Returns
// http://domain.com/public/storage/[asset_file]

// config_asset('public');

Asset::config('storage', false);

// - Returns
// http://domain.com/storage/[asset_file]

// 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

use Tamedevelopers\Support\View;

// Using a child view that extends a layout
$view = new View('tests.layout.home2', [
    'title' => 'Homepage',
]);

echo $view->render();

$view = new View('tests.layout.home2', [
    'title' => 'Homepage',
]);

// First render
echo $view->render();

// Second render (fresh render, no duplicated sections)
echo $view->render();

$html = (new View('tests.layout.home2', ['title' => 'Homepage']))->render();

$extensions = [
    '.php',        // Generic / CodeIgniter / CakePHP 4+
    '.blade.php',  // Laravel
    '.twig',       // Symfony/Twig generic
    '.html.twig',  // Symfony typical
];

// 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']);

use Tamedevelopers\Support\Env;

Env::createOrIgnore()

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')

use Tamedevelopers\Support\Env;

Env::updateENV('DB_PASSWORD', 'newPassword');
env_update('DB_CHARSET', 'utf8', false);

use Tamedevelopers\Support\Server;

Server::getServers();
// server()->getServers('domain');

use Tamedevelopers\Support\Server;

Server::config('tests.lang.email', [], 'tests');

/**
 * 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 ackage 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)
│   └── ...
└── ...

server()->config("en/message.{$key}", "message.{$key}", 'Lang');

server()->config("app.name");

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();

// Generate and persist a new key
tmanager()->regenerate();

// Optionally start env and enforce key
tmanager()->startEnvIFNotStarted();

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']);