Skip to content

Commit 5ac0747

Browse files
author
Fredrick Peter
committed
Changelog Update
1 parent f765918 commit 5ac0747

File tree

17 files changed

+263
-62
lines changed

17 files changed

+263
-62
lines changed

Capsule/FileCache.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Tamedevelopers\Support\Capsule;
66

7-
class FileCache
8-
{
7+
class FileCache{
98

109
/**
1110
* cachePath

Capsule/Forge.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
namespace Tamedevelopers\Support\Capsule;
66

77
use Tamedevelopers\Support\Str;
8-
use Tamedevelopers\Support\Traits\ExpressionTrait;
9-
108

119
class Forge extends Str {
1210

13-
use ExpressionTrait;
1411
}

Cookie.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Tamedevelopers\Support;
66

7-
class Cookie
8-
{
7+
class Cookie{
8+
99
/**
1010
* Site name
1111
* @var string

Core.php renamed to Country.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
namespace App\Core;
3+
declare(strict_types=1);
44

5-
class Core {
5+
namespace Tamedevelopers\Support;
6+
7+
final class Country {
68

79
/**
810
* Get Country ISO 3

Env.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Tamedevelopers\Support\Traits\ReusableTrait;
1313
use Tamedevelopers\Support\Capsule\CustomException;
1414

15-
class Env{
15+
class Env {
1616

1717
use ServerTrait, ReusableTrait;
1818

Hash.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Tamedevelopers\Support\Capsule\CustomException;
1010

1111

12-
class Hash
13-
{
12+
final class Hash {
13+
1414
/**
1515
* Count
1616
* @var string

PDF.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
use Tamedevelopers\Support\Capsule\Manager;
1313
use Tamedevelopers\Support\Capsule\CustomException;
1414

15-
/*
16-
* DOM PDF
17-
* @author DOMPDF
18-
* @url composer require dompdf/dompdf
19-
* @url https://github.com/dompdf/dompdf/blob/v0.8.2/src/Adapter/CPDF.php#L45
20-
* @url https://github.com/dompdf/dompdf
21-
*/
22-
class PDF
23-
{
15+
/**
16+
* DOM PDF Wrapper
17+
* Usage: composer require dompdf/dompdf
18+
* @url https://github.com/dompdf/dompdf/blob/v0.8.2/src/Adapter/CPDF.php#L45
19+
* @url https://github.com/dompdf/dompdf
20+
*
21+
* @property object \Dompdf\Dompdf|object
22+
* @property object \Dompdf\Options|object
23+
*/
24+
class PDF{
2425

2526
/**
2627
* dompdf
@@ -57,7 +58,7 @@ static private function init()
5758
]
5859
]);
5960

60-
// instantiate and use the dompdf class
61+
// instantiate and use the \Dompdf\Dompdf() class
6162
self::$dompdf = new Dompdf($options);
6263
}
6364

@@ -83,7 +84,6 @@ static public function create(array $options = [])
8384
'destination' => strtotime('now') . '.pdf',
8485
'output' => 'preview',
8586
], $options);
86-
8787

8888
// pass html content
8989
self::$dompdf->loadHtml(self::$options['content']);
@@ -119,7 +119,7 @@ static public function create(array $options = [])
119119
/**
120120
* READ PDF To Server
121121
*
122-
* @param string $path -- Absolute path to PDF file
122+
* @param string $path --- Absolute path to PDF file
123123
* @return void
124124
*/
125125
static public function read(string $path)
@@ -136,6 +136,7 @@ static private function isDOMPDFInstalled()
136136
{
137137
try {
138138
if (class_exists('Dompdf\Options')) {
139+
// instantiate and use the \Dompdf\Options() class
139140
return new Options();
140141
} else {
141142
throw new CustomException(

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Support Package For Tamedevelopers
1313
* [Env Update](#env-update)
1414
* [Server](#server)
1515
* [Get Servers](#get-servers)
16+
* [Create Custom Config](#create-custom-config)
17+
* [Create Config Template File](#create-config-template-file)
1618
* [Autoload Register](#autoload-register)
1719
* [Helpers Functions](#helpers-functions)
1820
* [Error Dump](#error-dump)
@@ -22,7 +24,7 @@ Support Package For Tamedevelopers
2224

2325
## Requirements
2426

25-
- `>= php7.2.5+`
27+
- `>= php 8.0+`
2628

2729
## Installation
2830

@@ -31,7 +33,7 @@ Prior to installing `support package` get the [Composer](https://getcomposer.org
3133
**Step 1** — update your `composer.json`:
3234
```composer.json
3335
"require": {
34-
"tamedevelopers/support": "^1.0.3"
36+
"tamedevelopers/support": "^1.0.0"
3537
}
3638
```
3739

@@ -143,7 +145,6 @@ Env::updateENV('DB_PASSWORD', 'newPassword');
143145
env_update('DB_CHARSET', 'utf8', false);
144146
```
145147

146-
147148
## Server
148149
- Return instance of `Server`
149150

@@ -163,6 +164,61 @@ Server::getServers();
163164
server()->getServers('domain');
164165
```
165166

167+
### Create Custom Config
168+
- With this helper you can be able to create your own custom config by extending the Default Config Method
169+
- When using this model, make sure every of your php file returns an associative array for the key to work
170+
171+
| Params | Description |
172+
|---------------|-------------------|
173+
| key | File array key |
174+
| default | Default value if no data is found from the key |
175+
| folder | Folder to search from and Default folder is `config` |
176+
177+
```
178+
use Tamedevelopers\Support\Server;
179+
180+
Server::config('tests.lang.email', [], 'Tests');
181+
```
182+
183+
- Create our own config to extends the default
184+
```
185+
/**
186+
* Custom Language Handler
187+
*
188+
* @param mixed $key
189+
* @return mixed
190+
*/
191+
function __($key){
192+
193+
// since the config only takes the filename follow by dot(.) and keyname
194+
// then we can manually include additional folder-name followed by / to indicate that it's a folder
195+
// then message.key_name
196+
// To make this Laravel kind of language, we can add the default value to be returned as the key
197+
// Do not forget that it starts from your root base directory, as the Package already has your root path
198+
199+
return config("en/message.{$key}", "message.{$key}", 'Lang');
200+
}
201+
202+
203+
--- Structure of folder example
204+
--- (d) for directory and (f) for file
205+
206+
Base -d ---
207+
Lang -d --
208+
en -d
209+
message.php -f
210+
error.php -f
211+
212+
tr -d
213+
message.php -f
214+
error.php -f
215+
```
216+
217+
- or -- `Helpers Function`
218+
```
219+
server()->config("app.name");
220+
```
221+
166222
## Autoload Register
167223
- Takes an `string\|array` as param
168224
- You can use register a folder containing all needed files

Server.php

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ final class Server{
2222
* @param mixed $default
2323
* [optional] The default value to return if the configuration option is not found
2424
*
25+
* @param mixed $folder
26+
* [optional] Custom base folder after the base_path()
27+
* - Default base for config() is 'config' folder.
28+
*
2529
* @return mixed
2630
* The value of the configuration option, or null if it doesn't exist
2731
*/
28-
public static function config(string $key, $default = null)
32+
public static function config(string $key, $default = null, string $folder = null)
2933
{
3034
// Convert the key to an array
3135
$parts = explode('.', $key);
3236

3337
// Get the file name
34-
$filePath = base_path("config/{$parts[0]}.php");
38+
$filePath = base_path("{$folder}/{$parts[0]}.php");
3539

3640
// Check if the configuration file exists
3741
if (file_exists($filePath)) {
@@ -51,13 +55,67 @@ public static function config(string $key, $default = null)
5155
}
5256
}
5357

58+
// if config not set
59+
if(!isset($config)){
60+
$config = null;
61+
}
62+
5463
// try merging data if an array
5564
if(is_array($config) && is_array($default)){
5665
return array_merge($config, $default);
5766
}
5867

5968
return $config ?? $default;
6069
}
70+
71+
/**
72+
* Create Template File
73+
*
74+
* @param array $data
75+
* @param string|null $filename
76+
* @return void
77+
*/
78+
static public function createTemplateFile(?array $data = [], ?string $filename = null)
79+
{
80+
// Get the file name
81+
$filePath = base_path($filename);
82+
83+
// Generate PHP code
84+
$exported = var_export($data, true);
85+
$string = explode("\n", $exported);
86+
$string = array_map('trim', $string);
87+
$string = implode("\n ", $string);
88+
$string = ltrim($string, 'array (');
89+
$string = rtrim($string, ')');
90+
$string = trim($string);
91+
92+
// Generate PHP code with specific formatting
93+
$phpCode = <<<PHP
94+
<?php
95+
96+
return [
97+
98+
/*
99+
|--------------------------------------------------------------------------
100+
| Template File Lines
101+
|--------------------------------------------------------------------------
102+
|
103+
| The following template lines are used during text formatting for various
104+
| messages that we need to display to the user. You are free to modify
105+
| these template lines according to your application's requirements.
106+
|
107+
*/
108+
109+
$string
110+
];
111+
PHP;
112+
113+
// to avoid warning error
114+
// we check if path is a directory first before executing the code
115+
if(is_dir(dirname($filePath))){
116+
file_put_contents($filePath, $phpCode);
117+
}
118+
}
61119

62120
/**
63121
* Convert Value to an Array

Slugify.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
use Tamedevelopers\Support\Capsule\Manager;
1010
use Tamedevelopers\Support\Capsule\CustomException;
1111

12-
/*
13-
* To change this license header, choose License Headers in Project Properties.
14-
* To change this template file, choose Tools | Templates
15-
* and open the template in the editor.
16-
* https://github.com/cocur/slugify
17-
* composer require cocur/slugify
18-
*/
19-
class Slugify
20-
{
12+
/**
13+
* Cocur\Slugify\Slugify Wrapper
14+
* Usage: composer require cocur/slugify
15+
* @url https://github.com/cocur/slugify
16+
*/
17+
class Slugify{
2118

2219
/**
2320
* language

0 commit comments

Comments
 (0)