Skip to content

Commit 6d93a0c

Browse files
update
1 parent 933effc commit 6d93a0c

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

src/PDF.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ private static function init()
5757
]);
5858

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

6364
/**
@@ -170,7 +171,8 @@ private static function isDOMPDFInstalled()
170171
try {
171172
if (class_exists('Dompdf\Options')) {
172173
// instantiate and use the \Dompdf\Options() class
173-
return new Options();
174+
$option = '\Dompdf\Options';
175+
return new $option();
174176
} else {
175177
throw new CustomException(
176178
"Class Dompdf\Options not found: \nRequire the package by running: `composer require dompdf/dompdf`\n" .

src/Server.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Tamedevelopers\Support\Str;
99
use Tamedevelopers\Support\Capsule\File;
1010
use Tamedevelopers\Support\Traits\ServerTrait;
11+
use Tamedevelopers\Support\Process\HttpRequest;
1112
use Tamedevelopers\Support\Traits\ReusableTrait;
13+
use Tamedevelopers\Support\Tame;
1214

1315
class Server{
1416

@@ -32,6 +34,28 @@ class Server{
3234
*/
3335
public static function config($key, $default = null, string $base_folder = 'config')
3436
{
37+
// When running our custom CLI inside a framework (e.g., Laravel), ensure
38+
// the framework Application is registered to satisfy helpers like database_path().
39+
try {
40+
if (HttpRequest::runningInConsole()) {
41+
$tame = new Tame();
42+
43+
if ($tame->isAppFramework()) {
44+
$basePath = self::pathReplacer(self::formatWithBaseDirectory(), '\\');
45+
46+
if($tame->isLaravel()){
47+
// Laravel: register Application if not already set on the container
48+
$laravel = "\Illuminate\Foundation\Application";
49+
new $laravel(
50+
$_ENV['APP_BASE_PATH'] ?? $basePath
51+
);
52+
}
53+
}
54+
}
55+
} catch (\Throwable $e) {
56+
// Ignore and fall back to normal file-based config loading
57+
}
58+
3559
// Convert the key to an array
3660
$parts = explode('.', $key);
3761

@@ -47,12 +71,6 @@ public static function config($key, $default = null, string $base_folder = 'conf
4771
// Remove the file name from the parts array
4872
unset($parts[0]);
4973

50-
dd(
51-
$parts,
52-
$filePath,
53-
$config
54-
);
55-
5674
// Compile the configuration value
5775
foreach ($parts as $part) {
5876
if (isset($config[$part])) {

src/Traits/ReusableTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait ReusableTrait{
1414
*
1515
* @return mixed
1616
*/
17-
public function dump(...$data)
17+
public static function dump(...$data)
1818
{
1919
$dataArray = $data[0] ?? $data;
2020
if(is_array($dataArray)){

src/Traits/TameTrait.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function isAppFramework()
2727
// using `get_declared_classes()` function will return all classes in your project
2828
return self::checkAnyClassExists([
2929
'\Illuminate\Foundation\Application', // Laravel
30+
'\Illuminate\\Container\\Container', // Laravel
3031
'\CI_Controller', // CodeIgniter
3132
'\Cake\Controller\Controller', // CakePHP
3233
'\Symfony\Component\HttpKernel\Kernel', // Symfony
@@ -41,7 +42,10 @@ public static function isAppFramework()
4142
*/
4243
public static function isLaravel()
4344
{
44-
return self::checkClassExists('\Illuminate\Foundation\Application');
45+
return self::checkAnyClassExists([
46+
'\Illuminate\Foundation\Application',
47+
'\Illuminate\\Container\\Container',
48+
]);
4549
}
4650

4751
/**
@@ -51,7 +55,7 @@ public static function isLaravel()
5155
*/
5256
public static function isCodeIgniter()
5357
{
54-
return self::checkClassExists('\CI_Controller');
58+
return self::checkAnyClassExists('\CI_Controller');
5559
}
5660

5761
/**
@@ -61,7 +65,7 @@ public static function isCodeIgniter()
6165
*/
6266
public static function isCakePhp()
6367
{
64-
return self::checkClassExists('\Cake\Controller\Controller');
68+
return self::checkAnyClassExists('\Cake\Controller\Controller');
6569
}
6670

6771
/**
@@ -71,7 +75,7 @@ public static function isCakePhp()
7175
*/
7276
public static function isSymfony()
7377
{
74-
return self::checkClassExists([
78+
return self::checkAnyClassExists([
7579
'\Symfony\Component\HttpKernel\Kernel',
7680
'\Symfony\Component\Routing\Annotation\Route'
7781
]);

src/helpers.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ function TameSession()
324324
*/
325325
function config($key, $default = null)
326326
{
327-
return server()->config($key, $default);
327+
return Server::config($key, $default);
328328
}
329329
}
330330

@@ -474,7 +474,7 @@ function __($key = null, $locale = null, $base_folder = null)
474474
*/
475475
function base_path($path = null)
476476
{
477-
return server()->formatWithBaseDirectory($path);
477+
return Server::formatWithBaseDirectory($path);
478478
}
479479
}
480480

@@ -580,7 +580,7 @@ function lang_path($path = null)
580580
*/
581581
function domain($path = null)
582582
{
583-
return server()->formatWithDomainURI($path);
583+
return Server::formatWithDomainURI($path);
584584
}
585585
}
586586

@@ -593,7 +593,7 @@ function domain($path = null)
593593
*/
594594
function to_array($value)
595595
{
596-
return server()->toArray($value);
596+
return Server::toArray($value);
597597
}
598598
}
599599

@@ -606,7 +606,7 @@ function to_array($value)
606606
*/
607607
function to_object($value)
608608
{
609-
return server()->toObject($value);
609+
return Server::toObject($value);
610610
}
611611
}
612612

@@ -619,7 +619,7 @@ function to_object($value)
619619
*/
620620
function to_json($value)
621621
{
622-
return server()->toJson($value);
622+
return Server::toJson($value);
623623
}
624624
}
625625

@@ -632,7 +632,7 @@ function to_json($value)
632632
*/
633633
function dump(...$data)
634634
{
635-
server()->dump($data);
635+
Server::dump($data);
636636
}
637637
}
638638

0 commit comments

Comments
 (0)