Overview

Classes

  • Api1
  • Array1
  • ArrayObject1
  • Auth1
  • AuthModel1
  • Chat1
  • Class1
  • Color1
  • Console1
  • Controller1
  • Converter1
  • Cookie1
  • Date1
  • DateManager1
  • Db1
  • DbPref1
  • EasyBook
  • EasyCountry
  • EasyGenerator
  • EasyProduct
  • EasyProject
  • EasySchool
  • EasyStatus
  • exApiController1
  • exBlade1
  • exClass
  • exData1
  • exMail1
  • exRoute1
  • exTranslate1
  • exUrl1
  • FileManager1
  • FilePref1
  • Form1
  • Function1
  • Header1
  • Html1
  • HtmlAsset1
  • HtmlForm1
  • HtmlStyle1
  • HtmlWidget1
  • Math1
  • Model1
  • Model1FileLocator
  • Number1
  • Object1
  • Page1
  • Picture1
  • Popup1
  • QUESTION_TYPE
  • RecursiveArrayObject1
  • RegEx1
  • ResultObject1
  • ResultStatus1
  • ServerRequest1
  • Session1
  • SessionPreferenceSave1
  • String1
  • TaskManager1
  • Url1
  • Validation1
  • Value1

Interfaces

  • Controller1RouteInterface
  • Model1ActionInterface
  • Model1PageInterface

Functions

  • __
  • api_and_form_default_route
  • app
  • app_api_list
  • app_class_list
  • app_class_paths
  • app_class_with_interface
  • app_controller_list
  • app_dashboard_list
  • app_db_model_list
  • app_db_table_list
  • app_model_list
  • app_page_list
  • asset
  • csrf_token
  • current_layout_asset
  • current_plugin_asset
  • current_resources_asset_path
  • d
  • dd
  • file_base
  • file_session
  • file_session_get
  • file_session_remove
  • file_session_save
  • form_call_api
  • form_call_controller
  • form_token
  • get_all_view_in_directory
  • get_valid_view_path
  • is_token_valid
  • is_ajax_request
  • layout_asset
  • mailer
  • mailer_send_mail_to_list
  • make_default_route
  • makeRoute
  • normalizeSharedPath
  • now
  • now_date
  • now_time
  • old
  • paginate
  • path_app
  • path_asset
  • path_asset_url
  • path_clear_cache
  • path_main
  • path_main_url
  • path_shared
  • path_shared_app
  • path_shared_asset
  • path_shared_asset_url
  • path_shared_resources
  • path_to_viewpath
  • plugin_asset
  • pre
  • redirect
  • redirect_back
  • redirect_failed
  • redirect_to_view
  • register_path_for_layout_asset
  • request
  • resources_path
  • resources_path_asset
  • resources_path_cache
  • resources_path_plugin
  • resources_path_view
  • resources_path_view_cache
  • resources_path_view_layout
  • route
  • routes
  • shared_asset
  • token
  • translate_language
  • translated_language
  • url
  • view
  • view_exists
  • view_make
  • viewpath_to_path
  • Overview
  • Class
  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: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 
<?php

/************************************************
 *  Ehex Helper Function
 ***********************************************/












$__ENV = [];


/**
 * Access config data through $__ENV or config();
 * @param null $key
 * @param string $default_value
 * @return Config1|mixed
 */
//function config($key = null, $default_value = ''){
//    global $__ENV;
//    if($key === null) return Object1::convertArrayToObject($__ENV);
//    return isset($__ENV[$key])? $__ENV[$key] : $default_value;
//}
//=======[ Break and Print ]===========
function pre($arr,$them=1){
    switch ($them) {
        case 1: $color='#2295bc'; $background='#e4e7e7'; break;
        case 2: $color='#e4e7e7'; $background='#2295bc'; break;
        case 3: $color='#064439'; $background='#51bba8'; break;
        case 4: $color='#efc75e'; $background='#324d5b'; break;
        case 5: $color='#000000'; $background='#b1eea1'; break;
        case 6: $color='#fff'; $background='#e2574c';    break;
        default:    $color='#2295bc'; $background='#e4e7e7'; break;
    }?>
    <pre style="direction: ltr;background:<?= $background;?>;color:<?= $color;?>;
    max-width: 90%;margin: 30px auto;overflow:auto;
    font-family: Monaco,Consolas, 'Lucida Console',monospace;font-size: 16px;padding: 20px;"><?php print_r($arr); echo "</pre>";
}

/**
 * Use for debugging and end page
 * @param mixed ...$logArr
 */
function dd(...$logArr){
    echo "<script> dd(".Array1::toJSON($logArr).") </script>";
    Page1::$FLAG_SHOW_LOAD_TIME = true;
    Page1::start();
    foreach ($logArr as $data) {
        Util1::var_dump($data);
    }
    Page1::end([], false);
    die('');
}

/**
 * Use for debugging but don't end page
 * @param mixed ...$logArr
 */
function d(...$logArr){ foreach ($logArr as $data) Util1::var_dump($data); }






//=======[  instance class App ]=====================
/**
 * Get App Route and RequestInformation
 * @param null $c
 * @return RouteApp|RouteRequest
 */
function app($c = null) {
    $app = RouteApp::instance();
    if ($c) return $app->$c;
    return $app;
}



/**
 * app full class path list
 * @return array
 */
function app_class_paths(){
    global $__ENV;
    if(!empty($__ENV['app_class_paths'])) return $__ENV['app_class_paths'];
    $all_path = $__ENV['app_class_paths'] =  array_merge(
        [PATH_APP], // Application Folders

        // include App Layout Dynamic Class Profile
        FileManager1::getDirectoriesFolders([rtrim(PATH_LAYOUTS, DS), rtrim(PATH_PLUGINS, DS)], '', 'inc/'),
        Config1::ENABLE_INCLUDES_SHARED ?
                array_merge(
                    [PATH_SHARED_APP],
                    FileManager1::getDirectoriesFolders([PATH_SHARED_RESOURCE.'views/layouts', PATH_SHARED_RESOURCE.'plugins'], '', 'inc/')
                ): [] // include Main Layout Dynamic Class Profile
    );
    return ($all_path);
}






/**
 * all known app class.
 *  e.g AuthModel1::class, Model1::class, Controller1::class, Api1::class;
 * @param array $typeList
 * @return array
 */
function app_class_list($typeList = [AuthModel1::class, Model1::class, Controller1::class, Api1::class]){
    global $__ENV;
    $key = implode('_', $typeList);
    if(!empty($__ENV['app_class_with_interface'][$key])) return $__ENV['app_class_with_interface'][$key];
    $model = [];
    foreach (FileManager1::getDirectoriesFiles(app_class_paths(), ['php'], [], -1, true) as $modelFile){
        $name = FileManager1::getFileName($modelFile);
        $name = str_replace( '.php', '', str_replace( '.class.php', '', $name ));
        if( in_array(get_parent_class($name), Array1::toArray($typeList))) $model[] = $name;
    }
    $model = array_diff($model, Config1::EXCLUDE_CLASS);
    return $__ENV['app_class_with_interface'][$key] = $model;
}


/**
 * @param string $interfaceName
 * @param array $classTypeList
 * @return array
 */
function app_class_with_interface($interfaceName = Model1ActionInterface::class, $classTypeList =  [AuthModel1::class, Model1::class]){
    global $__ENV;
    if(!empty($__ENV['app_class_with_interface'][$interfaceName])) return $__ENV['app_class_with_interface'][$interfaceName];
    // get all dashboard model
    $app_dashboard = [];
    foreach (app_class_list($classTypeList) as $key) if(Class1::isInterfaceImplementExistIn($key, $interfaceName)) $app_dashboard[] = $key;
    return $__ENV['app_class_with_interface'][$interfaceName] = $app_dashboard;
}

/**
 * app controller list
 * @return array
 */
function app_controller_list(){ return app_class_list([Controller1::class]); }

/**
 * get list of api class
 * @return array
 */
function app_api_list(){ return app_class_list([Api1::class]); }

/**
 * get model with page interface.
 * E.g FrontendPage::class, DashboardPage::class
 * @return array
 */
function app_page_list(){ return app_class_with_interface(Model1PageInterface::class); }

/**
 * get model with Dashboard Interface
 * @return array
 */
function app_dashboard_list(){ return app_class_with_interface(Model1ActionInterface::class); }

/**
 * get all model list
 * @param bool $remove_page
 * @return array
 */
function app_model_list($remove_page = true){ return array_diff(app_class_list([Model1::class, AuthModel1::class]), $remove_page? array_merge(app_page_list(), ['Dashboard']): []); }

/**
 * Get Existing Model and Table List
 * @return array
 *
 */
function app_db_table_list(){ return Db1::getExistingTables(true); }

/**
 * Existing Model with table List
 * @return array
 *
 */
function app_db_model_list(){ return Db1::getExistingModels(); }






/************************************************
 *  Date Function
 ***********************************************/
/**
 * return current date and time information
 * @param bool $pretty DATE (  as Number = 'Y-m-d')  or (as Text = 'Y-M-D'); and TIME ( as AM/PM or 24hours)
 * @return false|string
 */
function now($pretty = false){ return DateManager1::now($pretty); }
/**
 * Current date information
 * @param bool $pretty (  as Number = 'Y-m-d')  (as Text = 'Y-M-D');
 * @return string
 */
function now_date($pretty = false){ return DateManager1::nowDate($pretty); }
/**
 * current time information
 * @param bool $pretty ( as AM/PM or 24hours)
 * @return string
 */
function now_time($pretty = false){ return DateManager1::nowTime($pretty); }





/************************************************
 *  hold on to last request
 ***********************************************/
/*
 *
 */
if(($_SERVER['REQUEST_METHOD'] == 'POST')){
    $request = $_REQUEST;
    unset($request['password']);
    Session1::set('__old', array_merge(isset($_SESSION['__old'])? $_SESSION['__old']:[],  $request));
    // Keep Involved Request
    Page1::$FLAG_KEEP_OLD_REQUEST = true;
}

/**
 * All Last Request, Select From Last Request of No Parameter to return all.
 * @param string $inputName (control name)
 * @param string $defaultValueOnFailed (default value if not exists or form not sent yet)
 * @return mixed|string
 */
function old($inputName = '', $defaultValueOnFailed = ''){ return String1::is_empty($inputName)? Object1::toArrayObject(true, Session1::get('__old')) :   String1::isset_or(Session1::get('__old')[$inputName], String1::isset_or($_REQUEST[$inputName], $defaultValueOnFailed));} //   isset()? $_SESSION['__old'][$inputVariable]: $default; }


/**
 * Get any sent request like $_GET, $_POST and $_FILES... Also all value are being normalized.
 * Checkbox value are set to either true of false, and files are well arrange, in Parameter, Set the Names
 * @param array $insertOrReplaceKeyValue :override any request data or add new one to it
 * @param array $filterCheckBoxNameList : convert boolean on and off to php boolean true and false
 * @param array $filterFileUploadNameList ; normalize file name very well, use in Ehex Sample blog
 * @return mixed
 */
function request(array $insertOrReplaceKeyValue = [], array $filterCheckBoxNameList = [], array $filterFileUploadNameList = []){
    $request = Object1::toArrayObject(true, array_merge($_REQUEST, $_FILES, $insertOrReplaceKeyValue));
    if($filterCheckBoxNameList)  foreach ($filterCheckBoxNameList as $value) $request[$value] = String1::toBoolean($request->{$value}, true, false);
    if($filterFileUploadNameList)  foreach ($filterFileUploadNameList as $value) $request[$value] = Array1::normalizeLinearRequestList($_FILES[$value]);
    return $request;
}





/************************************************
 *  Validating Security Token
 ***********************************************/


/**
 * Ehex Token Generator
 * @return string
 */
function token(){
    if(!empty($_SESSION['token'])) return $_SESSION['token'];
    else{
        $_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32)).'____'.String1::encodeStringToNumber(Url1::backUrl()); //$_SESSION['token'] =  bin2hex(random_bytes(32)); //md5(Form1::encrypt_base64(Math1::getUniqueId()));
        $_SESSION['token_time'] = time();
        return $_SESSION['token'];
    }
}


/**
 * validate token
 * @param null $token
 * @param bool $moreValidation
 * @return bool
 */
function is_token_valid($token = null, $moreValidation = true){
    $token = $token? $token: String1::isset_or($_POST['token'], '');
    $is_match = hash_equals(token(), $token);
    if($is_match){
        if(is_ajax_request() || !$moreValidation) return true;
        else{
            if(explode('____', token())[1] != String1::encodeStringToNumber(Url1::backUrl())) return false;
            unset($_SESSION['token'], $_SESSION['token_time']);
            return true;
        }
    }
    unset($_SESSION['token'], $_SESSION['token_time']);
    return false;
}



/**
 * Get Session Token
 * @return string
 */
function csrf_token(){ return token(); }

/**
 * Get Session Token Form, Hidden form with token field
 * @return null|string
 */
function form_token(){ return HtmlForm1::addHidden('token', token()); }

/**
 * Generate Url to Form Controller
 * @param string $classStaticFunction
 * @return string
 */
function form_call_controller($classStaticFunction = 'className::function(param1, param2)'){ return Form1::callController($classStaticFunction); }

/**
 * Generate Url to API
 * @param string $classStaticFunction
 * @return string
 */
function form_call_api($classStaticFunction = 'className::function(param1, param2)'){ return Form1::callApi($classStaticFunction); }



function is_ajax_request() {
    return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
}
/************************************************
 *  Helper Function
 ***********************************************
 * @param array $except
 * @param bool $listAsMenu
 * @param array @see Array1::replaceKeyNames(),  $renameLinkName_oldName_equals_newName  E.g ['dashboard'=>'My Dashboard']
 * @return ArrayObject|mixed
 * @internal param array $rename
 */
//[XAMTAX EDIT]
/**
 * Navigate to any menu and Return all Menu, can be accessed through routes()->login
 * =======[ get all route link and value array as ArrayObject and call by name, e.g routes()->home,  routes()->current,   ]=================
 * @param array $except
 * @param bool $listAsMenu
 * @param array $renameLinkName_oldName_equals_newName
 * @return array|mixed
 */
function routes($except = [], $listAsMenu = false, $renameLinkName_oldName_equals_newName = []) {
    $routeKeyValueList = Array1::removeKeys(array_merge(  Array1::wrap( array_merge(['index'=> '/',  'home'=>'/'], app('route')->getAllRoutes()), path_main_url('/')), ['current'=>@explode('?', Url1::getPageFullUrl())[0] ]), $except);
    $routeKeyValueList = Array1::replaceKeyNames($routeKeyValueList, $renameLinkName_oldName_equals_newName);
    if($listAsMenu) { $menuLink = []; foreach ($routeKeyValueList as $item => $value) $menuLink[ucwords(String1::convertToCamelCase(String1::replace($item, '.', ' '), ' '))] = $value; return $menuLink; }
    else return Object1::toArrayObject(true, $routeKeyValueList);
}





/**
 * redirect with route | Navigate to any menu
 * @param null $name
 * @param array $args
 * @return Route|RouteSystem|string
 */
function route($name = null, array $args = []) {
    if($name) return url(app('route')->getRoute($name, $args));
    global $route; return $route;
}

/**
 * redirect with route url
 * @param null $path
 * @return string
 */
function url($path = null) { return path_main_url().'/'.trim($path, '/'); }

/**
 * use mostly in controller
 * @param $viewPageName
 * @param array $param
 * @param bool $actionResult
 * @param array $trueMessage
 * @param array $falseMessage
 * @return string
 */
function redirect_to_view($viewPageName, array $param = [], $actionResult = false, $trueMessage = [], $falseMessage = []){
    // disable form/action/controller auto redirect
    global $FORM_ACTION_SHOULD_REDIRECT;
    $FORM_ACTION_SHOULD_REDIRECT = false;
    // set status
    if(!empty($trueMessage) || !empty($trueMessage)) Session1::setStatusFrom(($actionResult)? $trueMessage: $falseMessage );
    // set page rendering
    return view($viewPageName, $param);
}


/**
 * Goto a particular address
 * use mostly in controller
 * @param string $routeUrl
 * @param array $status
 * @param array $param
 * @return string
 */
function redirect($routeUrl = '/', $status = [], $param = []){
    if(String1::startsWith($routeUrl, '/') || !String1::startsWith(strtolower($routeUrl), 'http')) return Url1::redirect(url($routeUrl), $status, $param);
    else return Url1::redirect($routeUrl, $status, $param);
}

/**
 * redirect to previous page or to error404 Page if previous failed
 * @param array $status
 * @return string
 */
function redirect_failed($status = ['Request Failed', 'Could not retrieve necessary data', 'error']){
    Session1::setStatusFrom($status? $status: ['Request Failed']);
    $backUrl = Url1::backUrl();
    $returnUrl = url('/error404');
    if($backUrl !== Url1::getPageFullUrl()) $returnUrl = $backUrl;
    Url1::redirect($returnUrl);
    return Console1::println($status, true);
}

/**
 * Goto a previous address
 * @param array $status
 * @param array $param
 * @return string
 */
function redirect_back($status = [], $param = []){
    Url1::redirect(Url1::backUrl(), $status, $param);
    return '';
}


/**
 * Get Layout Assets directory ( Layout serve as Theme )
 * @see current_layout_asset(); // to get current layout assets
 * @see register_path_for_layout_asset(); // to register theme assets
 * @param string $file_path_name
 * @param string $assets_folder_name
 * @param null $layout_name
 * @param bool $isInSharedLayout
 * @return string
 *
 */
function layout_asset($file_path_name = '', $assets_folder_name = 'assets', $layout_name= null, $isInSharedLayout = false){
    // path gotten from register_path_for_layout_asset() or auth from Blade compiler
    //$layout_name_or_path = String1::contains( DS, $layout_name_or_path)? $optional_layoutViewPath_or_layoutFullPath: viewpath_to_path($optional_layoutViewPath_or_layoutFullPath) )
    $path = exBlade1::$CURRENT_LAYOUT_PATH ? exBlade1::$CURRENT_LAYOUT_PATH: (resources_path_view_layout($isInSharedLayout).DS.$layout_name);
    $path = $path.DS.$assets_folder_name.(!empty($file_path_name)? DS.$file_path_name: '');
    // if shared_assets, create symlink to assets and put under website. (otherwise move __include folder to your website) because assets file must be a subdirectory under website domain and not outside website folder wic we don't knw url location for.
    $path = normalizeSharedPath($path, '/shared/resources/views/', 'layout_list');
    return Url1::pathToUrl($path);
}

/**
 * Get Plugin Assets directory
 * @param string $file_path_name
 * @param string $assets_folder_name
 * @param null $plugin_name
 * @param bool $isInSharedLayout
 * @return string
 *
 */
function plugin_asset($file_path_name = '', $assets_folder_name = 'assets', $plugin_name = null, $isInSharedLayout = false){
    // path gotten from register_path_for_layout_asset() or auth from Blade compiler
    $path =  resources_path_plugin($isInSharedLayout).DS.$plugin_name;
    $path = $path.DS.$assets_folder_name.(!empty($file_path_name)? DS.$file_path_name: '');
    // if shared_assets, create symlink to assets and put under website. (otherwise move __include folder to your website) because assets file must be a subdirectory under website domain and not outside website folder wic we don't knw url location for.
    $path = normalizeSharedPath($path, '/shared/resources/plugins/', 'plugin_list');
    return Url1::pathToUrl($path);
}





/**
 * if shared_assets, create symlink to assets and put under website. (otherwise move __include folder to your website) because assets file must be a subdirectory under website domain and not outside website folder wic we don't knw url location for.
 * normalizeSharedPath('', '/shared/resources/plugins/', 'plugin_asset');
 * @param string $file_system_path
 * @param string $shared_path_delimiter
 * @param string $destination_asset_folder_name
 * @return string
 *
 */
function normalizeSharedPath($file_system_path = '', $shared_path_delimiter = '/shared/resources/', $destination_asset_folder_name = 'shared_asset_list'){
    if(String1::contains($shared_path_delimiter, $file_system_path) && String1::startsWith(Config1::INCLUDES_PATH, '../') ){
        $name = String1::replace(explode($shared_path_delimiter, $file_system_path)[1], DS, '_');
        $layout_asset = path_asset()."/shared/$destination_asset_folder_name/$name";
        if(!is_link($layout_asset)){
            @unlink($layout_asset);
            @mkdir(path_asset()."/shared/$destination_asset_folder_name", 0777, true);
            Session1::setStatus('Shared Resources Linked', ["Resources ('".String1::convertToCamelCase($name, ' ')."') Linked to app!",   Url1::createSymLinks($file_system_path, $layout_asset)]);
        }
        $file_system_path = $layout_asset;
    }
    return $file_system_path;
}


/**
 * Use in your plugin/layout to get current location of  assets
 * @see layout_asset();
 * @see register_path_for_layout_asset();
 * @param string $file_path_name
 * @param string $assets_folder_name
 * @param string $app_path_delimiter
 * @param string $shared_path_delimiter
 * @param string $destination_asset_folder_name
 * @return mixed
 *
 */
function current_resources_asset_path($file_path_name = '', $assets_folder_name = 'assets', $app_path_delimiter = '/resources/views/layouts/',  $shared_path_delimiter = '/shared/resources/', $destination_asset_folder_name = 'shared_asset_list', $debug_backtrace = 0){
    $current_file_full_path = debug_backtrace(null, 2)[$debug_backtrace]['file'];
    // split and confirm if is layout path
    if(!String1::contains($app_path_delimiter, $current_file_full_path)) throw new Exception(Console1::println('Current Layout Assets function Can only be run in Layout Folder, to retrieve assets of the layout. E.g Can be use to retrieve assets/css for plugin instead of using layout_asset("layout-name")'));
    // extract layout name
    $slitter = explode($app_path_delimiter, $current_file_full_path);
    $full_layout =  $slitter[0].$app_path_delimiter.explode(DS, $slitter[1])[0];
    // merge up
    $path = $full_layout.DS.$assets_folder_name.(!empty($file_path_name)? DS.$file_path_name: '');
    // if shared_assets
    $path = normalizeSharedPath($path, $shared_path_delimiter, $destination_asset_folder_name);
    // return path
    return Url1::pathToUrl($path);
}

/**
 * Use in your plugin to get current location of plugin assets
 * Get Current Plugin Assets ( Function can only be used inside resources/plugins/plugin_name )
 * @param string $file_path_name
 * @param string $assets_folder_name
 * @return mixed
 *
 */
function current_plugin_asset($file_path_name = '', $assets_folder_name = 'assets'){
    return current_resources_asset_path($file_path_name, $assets_folder_name, '/resources/plugins/', '/shared/resources/plugins/', 'plugin_list', 1);
}

/**
 * Use in your layout to get current location of layout assets
 * Get Current Layout Assets ( Function can only be used inside resources/layouts/layouts_name )
 * @param string $file_path_name
 * @param string $assets_folder_name
 * @return mixed
 *
 */
function current_layout_asset($file_path_name = '', $assets_folder_name = 'assets'){
    return current_resources_asset_path($file_path_name, $assets_folder_name, '/resources/views/layouts/',  '/shared/resources/views/',  'layout_list', 1);
}


/**
 * Call on all layout template. It will use the template path to locate assets folder and use it for the website
 * @param null $optional_layoutViewPath_or_layoutFullPath (can be layouts.bootstrap.template or resources_path_view_layout().'/bootstrap/template.blade.php')
 * @param int $backtrace_index
 * @return string
 * @see current_layout_asset(); // to get current layout assets
 * @see layout_asset(); // to get current layout assets
 */
function register_path_for_layout_asset($optional_layoutViewPath_or_layoutFullPath = null, $backtrace_index = 0){
    if($optional_layoutViewPath_or_layoutFullPath) return exBlade1::$CURRENT_LAYOUT_PATH = dirname(String1::contains( DS, $optional_layoutViewPath_or_layoutFullPath)? $optional_layoutViewPath_or_layoutFullPath: viewpath_to_path($optional_layoutViewPath_or_layoutFullPath) );
    $allData = array_flip(exBlade1::$LOADED_VIEW_AND_CACHE_LIST);
    $cachePath = debug_backtrace(null, 2)[$backtrace_index]['file'];
    if($allData[$cachePath]) return  exBlade1::$CURRENT_LAYOUT_PATH = dirname($allData[$cachePath]);
    else return die('Error in register_path_for_layout_asset(), Assets Path Not Found');
}





/**
 * @param string $path
 * @return string
 *  Site Url [ http://localhost/Project-Ehex/ ]
 */
function path_main_url($path = ''){
    if(!String1::is_empty($path)) $path = '/'.ltrim($path, '/');
    return rtrim(Url1::getSiteMainAddress().str_replace('index.php', '', $_SERVER['PHP_SELF']), '/').$path;
}




/**
 * @param string $path
 * @return string
 *      Real Path [ /Applications/MAMP/htdocs/Project-Ehex/ ]
 */
function path_main($path = ''){ return rtrim(BASE_PATH.'/'.ltrim($path, '/'), '/'); }










/**
 * Get Assets files
 * @param string $path
 * @param bool $findInSharedAssets
 * @return string Assets Path [ http://localhost/Project-Ehex/resources/assets ]
 * Assets Path [ http://localhost/Project-Ehex/resources/assets ]
 */
function asset($path = '', $findInSharedAssets = false){ return path_asset_url($path, $findInSharedAssets); }
function path_asset_url($path = '', $findInSharedAssets = false){
    if($findInSharedAssets) return path_shared_asset_url($path);
    return  path_main_url().'/resources/assets'.((!empty($path))?  '/'.trim($path, '/'): '');
}
function path_asset($path = '') { return rtrim(str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']), '/').'/resources/assets'.((!empty($path))?  '/'.trim($path, '/'): ''); }






/**
 * @param string $path
 * @return string app_main_path/app/
 */
function path_app($path = ''){ return rtrim(PATH_APP.ltrim($path, '/'), '/'); }





/**
 * Shared Path Information
 *
 * @param string $path
 * @param string $directory
 * @return string
 */
function path_shared($path = '', $directory = ''){ return (!empty($path))? PATH_SHARED.$directory.'/'.ltrim($path, '/'): PATH_SHARED.$directory; }

/**
 * @param string $path
 * @return string
 */
function path_shared_resources($path = ''){ return path_shared($path, 'resources'); }

/**
 * @param string $path
 * @return string
 */
function path_shared_app($path = ''){ return path_shared($path, 'app'); }

/**
 * @param string $path
 * @return string
 */
function path_shared_asset($path = ''){ return path_shared($path, 'resources/assets'); }

/**
 * @param string $path
 * @return string
 *
 */
function path_shared_asset_url($path = ''){
    if(String1::startsWith(Config1::INCLUDES_PATH, '../')){
        $shared_link_path = path_asset()."/shared/assets";
        if(!is_link($shared_link_path)){ Session1::setStatus('Shared Assets Linked', ['Link Successfully Created', Url1::createSymLinks(path_shared_asset(), $shared_link_path)]); } ////symlink(shared_asset(), path_asset().DS.'shared_assets');
    }else{
        $shared_link_path = PATH_SHARED_RESOURCE.'/assets';
    }
    return Url1::pathToUrl($shared_link_path).(    (empty($path)? '': '/'.trim($path, '/')));
}

/**
 * @param string $path
 * @return string
 *
 */
function shared_asset($path = ''){ return (path_shared_asset_url($path)); }



/**
 * Delete All Ehex Creatd Cache
 */
function path_clear_cache(){

    // includes path shared assets
    $all_link_path = [ path_asset()."/shared", resources_path_view_cache()];

    // Ehex
    //Session1::delete();
    @session_destroy();
    
    // delete link directory
    foreach(array_merge($all_link_path) as $path) {
        @unlink(FileManager1::normalizeFilePathSeparator($path));
        @rmdir(FileManager1::normalizeFilePathSeparator($path));
    }

    // recreate
    @mkdir(resources_path_view_cache());
    Session1::setStatus('Session and All Path File Deleted', array_merge($all_link_path));
}

API documentation generated by ApiGen