Skip to content

Commit 9103f99

Browse files
committed
Merge branch 'release/1.7-beta'
2 parents 30f88b7 + 13d62fc commit 9103f99

File tree

9 files changed

+500
-64
lines changed

9 files changed

+500
-64
lines changed

bladerunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Bladerunner
44
Plugin URI: http://bladerunner.elseif.se
55
Description: Laravel Blade template engine for WordPress
6-
Version: 1.6.3
6+
Version: 1.7-beta
77
Author: Andreas Ek
88
Author URI: https://www.elseif.se/
99
License: MIT License

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ekandreas/bladerunner",
33
"type": "wordpress-plugin",
4-
"version": "1.6.3",
4+
"version": "1.7-beta",
55
"description": "WordPress Blade L5 template engine",
66
"keywords": ["laravel", "blade", "wordpress"],
77
"license": "MIT",
@@ -14,7 +14,10 @@
1414
"require": {
1515
"php": ">=5.6",
1616
"illuminate/config": "5.*",
17-
"illuminate/view": "5.*"
17+
"illuminate/view": "5.*",
18+
"hassankhan/config": "0.*",
19+
"symfony/yaml": "3.*",
20+
"brain/hierarchy":"2.*"
1821
},
1922
"autoload": {
2023
"psr-4": {

globals/filters.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,60 @@
11
<?php
2+
23
/**
34
* Template Hierarchy should search for .blade.php files
45
*/
56
array_map(function ($type) {
67
add_filter("{$type}_template_hierarchy", function ($templates) {
7-
return call_user_func_array('array_merge', array_map(function ($template) {
8+
$result = call_user_func_array('array_merge', array_map(function ($template) {
89
$transforms = [
910
'%^/?(templates)?/?%' => Bladerunner\Config::repo('bladerunner.disable_option_hack') ? 'templates/' : '',
1011
'%(\.blade)?(\.php)?$%' => ''
1112
];
1213
$normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template);
14+
15+
$controllerPaths = collect([
16+
apply_filters('bladerunner/controller/paths', []),
17+
get_stylesheet_directory() . '/controllers',
18+
])->flatMap(function ($path) use ($normalizedTemplate) {
19+
$controllerPath = "{$path}/{$normalizedTemplate}.php";
20+
if (file_exists($controllerPath)) {
21+
add_filter('bladerunner/controllers/heap', function ($heap) use ($controllerPath) {
22+
if (!in_array($controllerPath, $heap)) {
23+
$heap[] = $controllerPath;
24+
}
25+
return $heap;
26+
});
27+
}
28+
return ["{$path}/{$normalizedTemplate}.php"];
29+
})->unique()->toArray();
30+
1331
return ["{$normalizedTemplate}.blade.php", "{$normalizedTemplate}.php"];
1432
}, $templates));
33+
34+
35+
return $result;
1536
});
1637
}, [
1738
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
1839
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
1940
]);
41+
42+
add_filter('template_include', function ($template) {
43+
$heap = apply_filters('bladerunner/controllers/heap', []);
44+
if ($heap) {
45+
foreach ($heap as $controllerFile) {
46+
require_once $controllerFile;
47+
$class = get_declared_classes();
48+
$class = '\\' . end($class);
49+
$controller = new $class();
50+
if (is_subclass_of($class, "\\Bladerunner\\Controller") && $controller->__getView()) {
51+
$controller->__setup();
52+
echo view($controller->__getView(), $controller->__getData());
53+
return null;
54+
}
55+
}
56+
}
57+
return $template;
58+
}, PHP_INT_MAX);
59+
60+
//TODO: Make the filter bladerunner/controller/path to array as bladerunner/controller/paths to get use in eg plugins

globals/setup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
use Illuminate\Contracts\Container\Container as ContainerContract;
34

45
/**
@@ -42,6 +43,10 @@
4243
(new \Bladerunner\BladeProvider($app))->register();
4344
return new \Bladerunner\Blade($app['view'], $app);
4445
});
46+
47+
\Bladerunner\Container::current('blade')->compiler()->directive('controller', function () {
48+
return '<?php (new \Bladerunner\ControllerDebug(get_defined_vars())); ?>';
49+
});
4550
});
4651

4752
/**

0 commit comments

Comments
 (0)