PHP Classes

File: app/Core/Helpers/generalHelperFunctions.php

Recommend this page to a friend!
  Classes of Ahmad Mustapha  >  Utility Web PHP API  >  app/Core/Helpers/generalHelperFunctions.php  >  Download  
File: app/Core/Helpers/generalHelperFunctions.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Utility Web PHP API
API to retrieve movie details and other resources
Author: By
Last change:
Date: 1 year ago
Size: 1,639 bytes
 

Contents

Class file image Download
<?php

use App\Core\Helpers\Classes\ValidationHelper;

$root = dirname(__DIR__, 3);
$slash = DIRECTORY_SEPARATOR;

function
url($url = null)
{
    global
$serverConfig;
    return
"http://{$serverConfig['host']}:{$serverConfig['port']}/{$url}";
}

/**
 * Root directory path
 * @param null $path
 * @return string
 */
function root_path($path = null)
{
    global
$root, $slash;
    return
"{$root}{$slash}{$path}";
}


/**
 * Application directory path
 * @param null $path
 * @return string
 */
function app_path($path = null)
{
    global
$root, $slash;
    return
"{$root}{$slash}app{$slash}{$path}";
}

/**
 * Application view directory path
 * @param null $path
 * @return string
 */
function view_path($path = null)
{
    global
$root, $slash;
    return
"{$root}{$slash}resources{$slash}views{$slash}{$path}";
}

/**
 * Storage directory path
 * @param null $path
 * @return string
 */
function storage_path($path = null)
{
    global
$root, $slash;
    return
"{$root}{$slash}storage{$slash}{$path}";
}

/**
 * Controllers path
 * @param null $path
 * @return string
 */
function controller_path($path = null)
{
    global
$root, $slash;
    return
"{$root}{$slash}app{$slash}Http{$slash}Controllers{$slash}{$path}";
}

$loadedConfig = [];
function
config(string $file)
{
    global
$slash, $loadedConfig;
    if (
array_key_exists($file, $loadedConfig)) {
        return
$loadedConfig[$file];
    }

   
$loaded = require root_path("config{$slash}{$file}.php");
    return
$loadedConfig[$file] = $loaded;
}

/**
 * Input validation helper
 * @return ValidationHelper
 */
function validator()
{
    return new
ValidationHelper();
}

For more information send a message to info at phpclasses dot org.