Initial commit
This commit is contained in:
91
app/functions/common.php
Normal file
91
app/functions/common.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* app/functions/common.php
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
function getClassName($class) {
|
||||
$className = get_class($class);
|
||||
$classNameParts = explode('\\', $className);
|
||||
return end($classNameParts);
|
||||
}
|
||||
|
||||
function convertClassNameToFileName( $class_name ) {
|
||||
$lower = lcfirst( $class_name ) . '.php';
|
||||
$upper_split = preg_split( '/(?=[A-Z])/', $lower );
|
||||
$file_name = strtolower( implode( '_', $upper_split ) );
|
||||
return $file_name;
|
||||
}
|
||||
|
||||
function convertFileNameToClassName( $file_name ) {
|
||||
$file_name = str_ireplace( '.php', '', $file_name );
|
||||
$file_name = rtrim( $file_name, DIRECTORY_SEPARATOR );
|
||||
$class_name = '';
|
||||
if ( stripos( $file_name, '_' ) ) {
|
||||
$exploded = explode( '_', $file_name );
|
||||
foreach ( $exploded as $key => $value ) {
|
||||
$class_name .= ucfirst( $value );
|
||||
}
|
||||
} else {
|
||||
$class_name .= ucfirst( $file_name );
|
||||
}
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
function convertFolderToClassName( $folder ) {
|
||||
$file_name = rtrim( $folder, DIRECTORY_SEPARATOR );
|
||||
$parts_array = explode(DIRECTORY_SEPARATOR, $file_name);
|
||||
$file_name = array_pop($parts_array);
|
||||
|
||||
$class_name = '';
|
||||
if ( stripos( $file_name, '_' ) ) {
|
||||
$exploded = explode( '_', $file_name );
|
||||
foreach ( $exploded as $key => $value ) {
|
||||
$class_name .= ucfirst( $value );
|
||||
}
|
||||
} else {
|
||||
$class_name .= ucfirst( $file_name );
|
||||
}
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
function convertFileNameToPluginClass( $file_name ) {
|
||||
$class_name = convertFolderToClassName( $file_name );
|
||||
$class = (string) APP_SPACE . '\\Plugins\\' . $class_name;
|
||||
return $class;
|
||||
}
|
||||
|
||||
function convertFileNameToModelClass( $file_name ) {
|
||||
$class_name = convertFileNameToClassName( $file_name );
|
||||
$class = (string) APP_SPACE . '\\Models\\' . $class_name;
|
||||
return $class;
|
||||
}
|
||||
|
||||
function getFileList( $folder = '' ) {
|
||||
if ( empty( $folder ) ) {
|
||||
$folder = PLUGIN_DIRECTORY;
|
||||
}
|
||||
if ( !file_exists( $folder ) ) {
|
||||
return false;
|
||||
}
|
||||
$pluginFolders = scandir( $folder );
|
||||
array_shift( $pluginFolders ); // remove the .
|
||||
array_shift( $pluginFolders ); // remove the ..
|
||||
return $pluginFolders;
|
||||
}
|
||||
|
||||
function dv( $variable ) {
|
||||
echo '<pre>';
|
||||
echo var_export( $variable, true );
|
||||
echo '</pre>';
|
||||
exit;
|
||||
}
|
||||
|
||||
function iv( $variable ) {
|
||||
echo '<pre>';
|
||||
echo var_export( $variable, true );
|
||||
echo '</pre>';
|
||||
}
|
Reference in New Issue
Block a user