Skip to content

Commit 592095d

Browse files
update
1 parent ffe34a6 commit 592095d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3234
-843
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/.github
66
/.env
77
/.env.example
8+
/.zencoder
89
composer.lock

Asset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Asset{
2222
*
2323
* @return string
2424
*/
25-
static public function asset(?string $asset = null, $cache = null, $path_type = null)
25+
public static function asset(?string $asset = null, $cache = null, $path_type = null)
2626
{
2727
// if coniguration has not been used in the global space
2828
// then we call to define paths for us
@@ -95,7 +95,7 @@ static public function asset(?string $asset = null, $cache = null, $path_type =
9595
*
9696
* @return void
9797
*/
98-
static public function config(?string $base_path = null, ?bool $cache = false, $path_type = false)
98+
public static function config(?string $base_path = null, ?bool $cache = false, $path_type = false)
9999
{
100100
// if not defined
101101
if(!defined('ASSET_BASE_DIRECTORY')){

AutoloadRegister.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use RecursiveIteratorIterator;
88
use RecursiveDirectoryIterator;
9+
use Tamedevelopers\Support\Capsule\File;
910
use Tamedevelopers\Support\Traits\ServerTrait;
1011

1112
class AutoloadRegister{
@@ -40,7 +41,7 @@ class AutoloadRegister{
4041
*
4142
* @return void
4243
*/
43-
static public function load(string|array $baseDirectory)
44+
public static function load(string|array $baseDirectory)
4445
{
4546
if(is_array($baseDirectory)){
4647
foreach($baseDirectory as $directory){
@@ -167,7 +168,7 @@ static private function getRelativePath($filePath)
167168
static private function getClassName($filePath)
168169
{
169170
$namespace = '';
170-
$content = file_get_contents($filePath);
171+
$content = File::get($filePath);
171172
$tokens = token_get_all($content);
172173
$count = count($tokens);
173174

Capsule/CustomException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CustomException extends Exception {
1515
* @param int $code The error code (default is 0).
1616
* @param Exception|null $previous The previous exception (default is null).
1717
*/
18-
public function __construct($message, $code = 0, Exception $previous = null)
18+
public function __construct($message, $code = 0, $previous = null)
1919
{
2020
parent::__construct($message, $code, $previous);
2121
}

Capsule/DebugManager.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
class DebugManager{
1212

13-
public static $whoops;
13+
private static $whoops;
1414

1515
/**
1616
* Boot the DebugManager.
17-
* If the constant 'ORMDebugManager' is not defined,
17+
* If the constant 'TAME_DEBUG_MANAGER' is not defined,
1818
* it defines it and starts the debugger automatically.
1919
*
2020
* So that this is only called once in entire application life cycle
@@ -23,14 +23,15 @@ public static function boot()
2323
{
2424
if(!defined('TAME_DEBUG_MANAGER')){
2525
self::autoStartDebugger();
26+
// Define debug manager as true
2627
define('TAME_DEBUG_MANAGER', 1);
2728
}
2829
}
2930

3031
/**
3132
* Autostart debugger for error logger
3233
*
33-
* @return string
34+
* @return void
3435
*/
3536
private static function autoStartDebugger()
3637
{
@@ -39,9 +40,11 @@ private static function autoStartDebugger()
3940
// header not sent
4041
if (!headers_sent()) {
4142
// register error handler
42-
self::$whoops = new Run();
43-
self::$whoops->pushHandler(new PrettyPageHandler());
44-
self::$whoops->register();
43+
if (!isset(self::$whoops)) {
44+
self::$whoops = new Run();
45+
self::$whoops->pushHandler(new PrettyPageHandler());
46+
self::$whoops->register();
47+
}
4548
}
4649
}
4750
}

Capsule/File.php

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tamedevelopers\Support\Capsule;
6+
7+
/**
8+
* Class File
9+
*
10+
* Provides file handling utilities similar to Laravel's Filesystem.
11+
* Supports reading, writing, deleting, copying, moving, and checking files.
12+
*/
13+
class File {
14+
15+
/**
16+
* Get all files in a directory as SplFileInfo objects.
17+
*
18+
* @param string $directory
19+
* @return array<int, \SplFileInfo>
20+
*/
21+
public static function files(string $directory): array
22+
{
23+
$result = [];
24+
if (!self::isDirectory($directory)) {
25+
return $result;
26+
}
27+
28+
$iterator = new \FilesystemIterator($directory, \FilesystemIterator::SKIP_DOTS);
29+
foreach ($iterator as $file) {
30+
if ($file->isFile()) {
31+
$result[] = $file;
32+
}
33+
}
34+
35+
return $result;
36+
}
37+
38+
/**
39+
* Create a directory.
40+
*
41+
* @param string $path
42+
* @param int $mode
43+
* @param bool $recursive
44+
* @return bool
45+
*/
46+
public static function makeDirectory(string $path, int $mode = 0777, bool $recursive = true): bool
47+
{
48+
if (self::isDirectory($path)) {
49+
return true;
50+
}
51+
52+
return mkdir($path, $mode, $recursive);
53+
}
54+
55+
/**
56+
* Validate a file name for unsafe characters.
57+
*
58+
* @param string $fileName
59+
* @param bool $disallowUnsafeCharacters
60+
* @return bool
61+
*/
62+
public static function isValidName(string $fileName, bool $disallowUnsafeCharacters = true): bool
63+
{
64+
if ($disallowUnsafeCharacters) {
65+
// Disallow: / \ ? % * : | " < >
66+
return !preg_match('/[\\\/\?%\*:|"<>]/', $fileName);
67+
}
68+
return true;
69+
}
70+
71+
/**
72+
* Determine if a file exists at a given path.
73+
*
74+
* @param string $path
75+
* @return bool
76+
*/
77+
public static function exists(string $path): bool
78+
{
79+
return is_file($path);
80+
}
81+
82+
/**
83+
* Get the contents of a file.
84+
*
85+
* @param string $path
86+
* @return string|false
87+
*/
88+
public static function get(string $path): string|false
89+
{
90+
return @file_get_contents($path);
91+
}
92+
93+
/**
94+
* Write the contents to a file.
95+
*
96+
* @param string $path
97+
* @param string $contents
98+
* @param int $flags
99+
* @return bool|int
100+
*/
101+
public static function put(string $path, string $contents, int $flags = 0): bool|int
102+
{
103+
return @file_put_contents($path, $contents, $flags);
104+
}
105+
106+
/**
107+
* Delete the file at the given path.
108+
*
109+
* @param string $path
110+
* @return bool
111+
*/
112+
public static function delete(string $path): bool
113+
{
114+
return self::exists($path) ? unlink($path) : false;
115+
}
116+
117+
/**
118+
* Copy a file to a new location.
119+
*
120+
* @param string $from
121+
* @param string $to
122+
* @return bool
123+
*/
124+
public static function copy(string $from, string $to): bool
125+
{
126+
return copy($from, $to);
127+
}
128+
129+
/**
130+
* Move a file to a new location.
131+
*
132+
* @param string $from
133+
* @param string $to
134+
* @return bool
135+
*/
136+
public static function move(string $from, string $to): bool
137+
{
138+
return rename($from, $to);
139+
}
140+
141+
/**
142+
* Get the file size.
143+
*
144+
* @param string $path
145+
* @return int|false
146+
*/
147+
public static function size(string $path): int|false
148+
{
149+
return filesize($path);
150+
}
151+
152+
/**
153+
* Get the file's last modification time.
154+
*
155+
* @param string $path
156+
* @return int|false
157+
*/
158+
public static function lastModified(string $path): int|false
159+
{
160+
return filemtime($path);
161+
}
162+
163+
/**
164+
* Get the file's extension.
165+
*
166+
* @param string $path
167+
* @return string|null
168+
*/
169+
public static function extension(string $path): ?string
170+
{
171+
$ext = pathinfo($path, PATHINFO_EXTENSION);
172+
return $ext !== '' ? $ext : null;
173+
}
174+
175+
/**
176+
* Get the file's basename.
177+
*
178+
* @param string $path
179+
* @return string
180+
*/
181+
public static function name(string $path): string
182+
{
183+
return pathinfo($path, PATHINFO_FILENAME);
184+
}
185+
186+
/**
187+
* Get the file's mime type.
188+
*
189+
* @param string $path
190+
* @return string|false
191+
*/
192+
public static function mimeType(string $path): string|false
193+
{
194+
return mime_content_type($path);
195+
}
196+
197+
/**
198+
* Get the file's type (file, dir, link, etc).
199+
*
200+
* @param string $path
201+
* @return string|false
202+
*/
203+
public static function type(string $path): string|false
204+
{
205+
return filetype($path);
206+
}
207+
208+
/**
209+
* Get the file's permissions.
210+
*
211+
* @param string $path
212+
* @return int|false
213+
*/
214+
public static function permissions(string $path): int|false
215+
{
216+
return fileperms($path);
217+
}
218+
219+
/**
220+
* Check if the file is readable.
221+
*
222+
* @param string $path
223+
* @return bool
224+
*/
225+
public static function isReadable(string $path): bool
226+
{
227+
return is_readable($path);
228+
}
229+
230+
/**
231+
* Check if the file is writable.
232+
*
233+
* @param string $path
234+
* @return bool
235+
*/
236+
public static function isWritable(string $path): bool
237+
{
238+
return is_writable($path);
239+
}
240+
241+
/**
242+
* Check if the file is a directory.
243+
*
244+
* @param string $path
245+
* @return bool
246+
*/
247+
public static function isDirectory(string $path): bool
248+
{
249+
return is_dir($path);
250+
}
251+
252+
/**
253+
* Check if the file is a regular file.
254+
*
255+
* @param string $path
256+
* @return bool
257+
*/
258+
public static function isFile(string $path): bool
259+
{
260+
return is_file($path);
261+
}
262+
263+
/**
264+
* Determines if the given string represents a valid file type.
265+
*
266+
* @param string $string The string to check for file type validity.
267+
* @return bool Returns true if the string is a valid file type, false otherwise.
268+
*/
269+
public static function isFileType(?string $string = null)
270+
{
271+
return pathinfo($string, PATHINFO_EXTENSION) !== '';
272+
}
273+
274+
}

0 commit comments

Comments
 (0)