Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 91d3f39

Browse files
author
Darren Jacoby
authored
Merge pull request #105 from briggySmalls/fix/104-sage-namespacing
Allow changing of sage function namespace
2 parents 32470b6 + cd4999c commit 91d3f39

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

controller.php

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

55
use Brain\Hierarchy\Hierarchy;
66

7-
use function App\sage;
7+
/**
8+
* @brief Gets the sage function.
9+
* @return The sage function if found, otherwise false
10+
*/
11+
function get_sage_function()
12+
{
13+
$function_name = apply_filters('sober/controller/sage_namespace', 'App') . '\sage';
14+
if (function_exists($function_name)) {
15+
return $function_name;
16+
}
17+
return false;
18+
}
819

920
/**
1021
* Loader
1122
*/
1223
function loader()
1324
{
14-
if (!function_exists('\App\sage')) {
25+
$sage = get_sage_function();
26+
if (!$sage) {
1527
return;
1628
}
1729

@@ -22,7 +34,7 @@ function loader()
2234
$loader = new Loader($hierarchy);
2335

2436
// Use the Sage DI container
25-
$container = sage();
37+
$container = $sage();
2638

2739
// Loop over each class
2840
foreach ($loader->getClassesToRun() as $class) {
@@ -63,26 +75,27 @@ function loader()
6375
*/
6476
function blade()
6577
{
66-
if (!function_exists('\App\sage')) {
78+
$sage = get_sage_function();
79+
if (!$sage) {
6780
return;
6881
}
6982

7083
// Debugger
71-
sage('blade')->compiler()->directive('debug', function () {
84+
$sage('blade')->compiler()->directive('debug', function () {
7285
return '<?php (new \Sober\Controller\Blade\Debugger(get_defined_vars())); ?>';
7386
});
7487

75-
sage('blade')->compiler()->directive('dump', function ($param) {
88+
$sage('blade')->compiler()->directive('dump', function ($param) {
7689
return "<?php (new Illuminate\Support\Debug\Dumper)->dump({$param}); ?>";
7790
});
7891

7992
// Coder
80-
sage('blade')->compiler()->directive('code', function ($param) {
93+
$sage('blade')->compiler()->directive('code', function ($param) {
8194
$param = ($param) ? $param : 'false';
8295
return "<?php (new \Sober\Controller\Blade\Coder(get_defined_vars(), {$param})); ?>";
8396
});
8497

85-
sage('blade')->compiler()->directive('codeif', function ($param) {
98+
$sage('blade')->compiler()->directive('codeif', function ($param) {
8699
$param = ($param) ? $param : 'false';
87100
return "<?php (new \Sober\Controller\Blade\Coder(get_defined_vars(), {$param}, true)); ?>";
88101
});

0 commit comments

Comments
 (0)