1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174:
<?php
require PATH_LIBRARY . 'blade-5.4/src/Autoloader.php';
Xiaoler\Blade\Autoloader::register();
use Xiaoler\Blade\FileViewFinder;
use Xiaoler\Blade\Factory;
use Xiaoler\Blade\Compilers\BladeCompiler;
use Xiaoler\Blade\Engines\CompilerEngine;
use Xiaoler\Blade\Filesystem;
use Xiaoler\Blade\Engines\EngineResolver;
$view_path = [
BASE_PATH.'resources/views',
Config1::ENABLE_INCLUDES_SHARED? PATH_SHARED_RESOURCE.'views' : null
];
$view_cachePath = BASE_PATH.'resources/cache/views';
$view_file = new Filesystem;
$view_compiler = new BladeCompiler($view_file, $view_cachePath);
$view_compiler->directive('datetime', function($timestamp) {
return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
});
$view_resolver = new EngineResolver;
$view_resolver->register('blade', function () use ($view_compiler) {
return new CompilerEngine($view_compiler);
});
$view = new Factory($view_resolver, new FileViewFinder($view_file, $view_path));
function view($view_name, $param = [], $noPageAutoWrap = false){
global $view;
if(!$noPageAutoWrap && Config1::AUTO_PAGE_WRAPPER) { Page1::start(); }
echo $newView = $view->make($view_name, @array_merge(Config1::onPageStart(), String1::isset_or($_SESSION['__SHARED_VARIABLE'], []), $param))->render();
if(!Page1::$FLAG_KEEP_OLD_REQUEST) { unset($_SESSION['__old']); Session1::delete('__old'); }
if(!$noPageAutoWrap && Config1::AUTO_PAGE_WRAPPER) { Page1::end(); } Config1::onPageEnd();
return '';
}
function view_make($view_name, $param = []){ global $view; return $view->make($view_name, $param)->render(); }
function view_exists($view_name){ global $view; return $view->exists($view_name); }
function path_to_viewpath($full_filename){
$full_filename = FileManager1::normalizeFilePathSeparator($full_filename, DS);
if(String1::contains('/resources/views/', $full_filename)){
$delimiter = '/resources/views/';
$full_filename = explode($delimiter, $full_filename)[1];
}
$full_filename = \String1::replaceEnd($full_filename, '.blade.php', '');
$full_filename = \String1::replace($full_filename, DIRECTORY_SEPARATOR, '.');
return $full_filename;
}
function viewpath_to_path($full_view_path, $validate = true){
if(!$validate){
$fullPath = get_valid_view_path($full_view_path);
return $fullPath? $fullPath: Console1::println("View Path [$full_view_path] Not Found in either AppView or SharedView", true);
}
global $view; return $view->getViewFullPath($full_view_path);
}
function get_all_view_in_directory($full_filename = '/Applications/MAMP/htdocs/ex/', $view_name_only = false, $recursive = false){
return array_map(
function($path) use ($view_name_only) {
if($view_name_only) {
$last = explode('/', $path);
$path = end($last);
}
return path_to_viewpath($path);
}, FileManager1::getDirectoriesFiles($full_filename, [], [], -1, $recursive));
}
function resources_path($isShared = false){ return $isShared? PATH_SHARED_RESOURCE: PATH_RESOURCE; }
function get_valid_view_path($view_path = '', $searchCurrentAppViewFirstThenSharedView = true){
$full_view_path = String1::replace($view_path, '.', DIRECTORY_SEPARATOR);
$lookupPath1 = resources_path_view(!$searchCurrentAppViewFirstThenSharedView).DIRECTORY_SEPARATOR.$full_view_path;
$lookupPath2 = resources_path_view($searchCurrentAppViewFirstThenSharedView).DIRECTORY_SEPARATOR.$full_view_path;
if( is_dir($lookupPath1) ) return $lookupPath1;
else if(is_dir($lookupPath2) ) return $lookupPath2;
return null;
}
function resources_path_view($isShared = false){ return resources_path($isShared).'views' ; }
function resources_path_view_layout($isShared = false){ return resources_path($isShared).'views/layouts' ; }
function resources_path_plugin($isShared = false){ return resources_path($isShared).'plugins' ; }
function resources_path_view_cache(){ global $view_cachePath; return $view_cachePath; }
function resources_path_cache(){ return resources_path(false).'/cache'; }
function resources_path_asset($isShared = false){ return resources_path($isShared).'/assets'; }