Support Package For Tamedevelopers
- Requirements
- Installation
- All Paths
- Number to Words
- Zip
- Time
- 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() | Same as base_path() |
public_path() | Root/public 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
iso (country iso3) | cents | number |
---|---|---|
COUNTRY ISO 3 AFG | NGA | GBR | USA |
true | false |
int|float|string |
If iso is given, it'll automatically converts the text into a currency format |
cents currency format shows, when there's a decimal point in the number | numeric figures: 299 | '42,982' | 3200.98 |
- Takes param as
string
and case-insensitive
NumberToWords::iso('nga')
- Takes param as
boolean
. Default isfalse
NumberToWords::cents(true)
- Takes two param as
int | float | string
and [optional] cents asboolean
- If you do not want to call the cents method, then we can call it directly here
NumberToWords::number(1290)->translate()
NumberToWords()->iso('TUR')->number('120.953', true)->translate()
// One hundred and twenty lira, nine hundred and fifty-three kuruş
- 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')
Visit the Tests/ folder to see more examples.
function name | Description |
---|---|
set() | Used to set cookie |
get() | Used to get cookie |
forget() | Used to expire cookie |
exire() | 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 two param as
string
base_path
path base directorycache
Tells method to returncache
of assets.
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 totrue
- 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');
http://domain.com/storage/[asset_file]?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 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