Support Package For Tamedevelopers

4.0.3 2024-10-13 03:47 UTC

README

Support Package For Tamedevelopers

Documentation

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

Number to Words

  • Has three chainable methods

ISO

  • Takes param as string and case-insensitive
NumberToWords::iso('nga')

Cents

  • Takes param as boolean. Default is false
NumberToWords::cents(true)

Number

  • Takes two param as int | float | string and [optional] cents as boolean
    • If you do not want to call the cents method, then we can call it directly here
NumberToWords::number(1290)->translate()

Usage

NumberToWords()->iso('TUR')->number('120.953', true)->translate()

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

Zip

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

Unzip

  • Takes two param as string
    • [sourcePath] relative path of zip-file
    • [destination] relative folder path to unzip-file
TameZip()->unzip('newData.zip', '/public/zip')

Download

  • Takes two param as string | boolean
    • [fileName] relative path of zip-file
    • [unlink] Default is true unlinks file after download
TameZip()->download('newData.zip')

Time

Visit the Tests/ folder to see more examples.

Cookie

Set

  • Takes 7 param
    • Mandatory $name param as string
    • [optional] $value param as string | null
    • [optional] $minutes param as int | string
    • [optional] $path param as string | null
    • [optional] $domain param as string | null
    • [optional] $secure param as bool | null
    • [optional] $httponly param as bool | null
use Tamedevelopers\Support\Cookie;

Cookie::set('cookie_name', 'value');

Get

  • Takes param as string
Cookie::get('cookie_name');

Forget

  • Takes 3 param
    • Mandatory $name param as string
    • [optional] $path param as string | null
    • [optional] $domain param as string | null
Cookie::forget('cookie_name');

Has

  • Takes param as string
    • Returns bool
if(Cookie::has('cookie_name')){
    // execute code
}
  • or -- Helpers Function
TameCookie()->set('user', '__user');

Hash

  • Password hashing and verify
use Tamedevelopers\Support\Hash;

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

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

Password verify

$oldPassword = "$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6";

Hash::check('testPassword', $oldPassword)

password_verify('testPassword', $oldPassword);

Asset

  • Takes a param as string path to asset file
    • Default [dir] is set to public
use Tamedevelopers\Support\Asset;

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

- Returns
http://domain.com/assets/css/style.css
  • or -- Helpers Function
tasset('css/style.css');

Asset Config

  • Takes two param as string
    • base_path path base directory
    • cache Tells method to return cache of assets.
use Tamedevelopers\Support\Asset;

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

- Returns
http://domain.com/public/storage/[asset_file]
  • or -- Helpers Function
config_asset('public');

Asset Cache

  • By Default, cache is set to true
    • You'll see a link representation as http://domain.com/[path_to_asset_file]?v=111111111
Asset::config('storage', false);

- Returns
http://domain.com/storage/[asset_file]
  • or -- Helpers Function
asset_config('storage');

http://domain.com/storage/[asset_file]?v=111111111

ENV

  • By default it use the default root as .env path, so mandatory to install vendor in root directory.

ENV Load

  • To load the environment .env file
    • Takes optional param as string $path
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 inside storage/logs/orm.log
Env::loadOrFail('path_to_env_folder')

ENV Update

  • Returns true|false. Used to update env variables
use Tamedevelopers\Support\Env;

Env::updateENV('DB_PASSWORD', 'newPassword');
  • or -- Helpers Function
env_update('DB_CHARSET', 'utf8', false);

Server

  • Return instance of Server

Get Servers

  • Returns assoc arrays of Server
    • server\|domain
use Tamedevelopers\Support\Server;

Server::getServers();
  • or -- Helpers Function
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
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 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");

Autoload Register

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

Helpers Functions

Error Dump

Useful Links