mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 09:52:22 +00:00
All the libraries, when it is required, now are using the message helper
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
<?php
|
||||
|
||||
if (! defined("BASEPATH")) exit("No direct script access allowed");
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PCRMLib
|
||||
{
|
||||
const RESOURCE_PARAMETER = "resource";
|
||||
const FUNCTION_PARAMETER = "function";
|
||||
const REG_SPLIT_EXPR = "/\//";
|
||||
const LIB_PREFIX = "Lib";
|
||||
const LIB_FILE_EXTENSION = ".php";
|
||||
const LIBS_PATH = "libraries";
|
||||
const MODEL_PREFIX = "_model";
|
||||
const RESOURCE_PARAMETER = 'resource';
|
||||
const FUNCTION_PARAMETER = 'function';
|
||||
const REG_SPLIT_EXPR = '/\//';
|
||||
const LIB_PREFIX = 'Lib';
|
||||
const LIB_FILE_EXTENSION = '.php';
|
||||
const LIBS_PATH = 'libraries';
|
||||
const MODEL_PREFIX = '_model';
|
||||
|
||||
// Black list of resources that are no allowed to be used
|
||||
private static $RESOURCES_BLACK_LIST = array(
|
||||
"PCRMLib", // disabled self loading
|
||||
"LogLib", // hardly usefull and virtually dangerous
|
||||
"MigrationLib", // virtually dangerous, DB manipulation
|
||||
"FilesystemLib" // virtually dangerous, direct access to file system
|
||||
'PCRMLib', // disabled self loading
|
||||
'LogLib', // hardly usefull and virtually dangerous
|
||||
'MigrationLib', // virtually dangerous, DB manipulation
|
||||
'FilesystemLib' // virtually dangerous, direct access to file system
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -32,9 +32,9 @@ class PCRMLib
|
||||
$this->ci =& get_instance();
|
||||
|
||||
// Loads helper message to manage returning messages
|
||||
$this->ci->load->helper("message");
|
||||
$this->ci->load->helper('message');
|
||||
|
||||
$this->ci->load->library("PermissionLib");
|
||||
$this->ci->load->library('PermissionLib');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ class PCRMLib
|
||||
// Wrong selection!
|
||||
else
|
||||
{
|
||||
$result = $this->_error("Neither a lib nor model: " . $parameters->resourcePath . $parameters->resourceName);
|
||||
$result = error('Neither a lib nor model: ' . $parameters->resourcePath . $parameters->resourceName);
|
||||
}
|
||||
|
||||
// If the resource was found and loaded
|
||||
@@ -137,7 +137,7 @@ class PCRMLib
|
||||
// Separates the resource path from the resource name
|
||||
$splittedResource = preg_split(PCRMLib::REG_SPLIT_EXPR, $parameterValue);
|
||||
$parameters->resourceName = $splittedResource[count($splittedResource) - 1];
|
||||
$parameters->resourcePath = str_replace($parameters->resourceName, "", $parameterValue);
|
||||
$parameters->resourcePath = str_replace($parameters->resourceName, '', $parameterValue);
|
||||
}
|
||||
// The name of the function
|
||||
else if ($parameterName == PCRMLib::FUNCTION_PARAMETER)
|
||||
@@ -163,30 +163,30 @@ class PCRMLib
|
||||
{
|
||||
if (!is_object($parameters))
|
||||
{
|
||||
return $this->_error("Parameter is not an object");
|
||||
return error('Parameter is not an object');
|
||||
}
|
||||
if (!isset($parameters->resourcePath))
|
||||
{
|
||||
return $this->_error("Resource path is not specified");
|
||||
return error('Resource path is not specified');
|
||||
}
|
||||
if (!isset($parameters->resourceName))
|
||||
{
|
||||
return $this->_error("Resource name is not specified");
|
||||
return error('Resource name is not specified');
|
||||
}
|
||||
if (!isset($parameters->function))
|
||||
{
|
||||
return $this->_error("Function is not specified");
|
||||
return error('Function is not specified');
|
||||
}
|
||||
if (!is_array($parameters->parameters))
|
||||
{
|
||||
return $this->_error("Parameters are not specified");
|
||||
return error('Parameters are not specified');
|
||||
}
|
||||
if (in_array($parameters->resourceName, PCRMLib::$RESOURCES_BLACK_LIST))
|
||||
{
|
||||
return $this->_error("You are trying to access to unauthorized resources");
|
||||
return error('You are trying to access to unauthorized resources');
|
||||
}
|
||||
|
||||
return $this->_success("Input data are valid");
|
||||
return success('Input data are valid');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,12 +206,12 @@ class PCRMLib
|
||||
catch (Exception $e)
|
||||
{
|
||||
// Errors while loading the model
|
||||
$result = $this->_error("Errors while loading the model: " . $e->getMessage());
|
||||
$result = error('Errors while loading the model: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (!is_null($loaded))
|
||||
{
|
||||
$result = $this->_success($loaded);
|
||||
$result = success($loaded);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -220,22 +220,22 @@ class PCRMLib
|
||||
private function checkLibraryPermission($resourcePath, $resourceName, $function, $permissionType)
|
||||
{
|
||||
$result = null;
|
||||
$permissionPath = "";
|
||||
$permissionPath = '';
|
||||
|
||||
if ($resourcePath != "")
|
||||
if ($resourcePath != '')
|
||||
{
|
||||
$permissionPath = $resourcePath;
|
||||
}
|
||||
|
||||
$permissionPath .= $resourceName . "." . $function;
|
||||
$permissionPath .= $resourceName . '.' . $function;
|
||||
|
||||
if ($this->ci->permissionlib->hasPermission($permissionPath, $permissionType) === false)
|
||||
{
|
||||
$result = $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$permissionPath, FHC_NORIGHT);
|
||||
$result = error(lang('fhc_'.FHC_NORIGHT).' -> '.$permissionPath, FHC_NORIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_success("Has permission");
|
||||
$result = success('Has permission');
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -244,11 +244,11 @@ class PCRMLib
|
||||
/**
|
||||
* Loads a library using the given path and name
|
||||
*
|
||||
* The method "library" of the class CI_Loader provided by CI has some limitations,
|
||||
* The method 'library' of the class CI_Loader provided by CI has some limitations,
|
||||
* so to be able to check errors was used a workaround.
|
||||
* It consists in:
|
||||
* - Checking if the file (identified by parameters $resourcePath and $resourceName) exists
|
||||
* - If exists it will be loaded using the method "file" from CI_Loader
|
||||
* - If exists it will be loaded using the method 'file' from CI_Loader
|
||||
* - Checks if the loaded file contains a class identified by parameter $resourceName
|
||||
*
|
||||
* If one of the previous tests fails, it will be returned a null value
|
||||
@@ -283,25 +283,25 @@ class PCRMLib
|
||||
{
|
||||
$loaded = null;
|
||||
// Same phrase error as load->model() provided by CI
|
||||
$result = $this->_error($found . " exists, but doesn't declare class " . $resourceName);
|
||||
$result = error($found . ' exists, but doesn\'t declare class ' . $resourceName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$loaded = null;
|
||||
// Same phrase error as load->model() provided by CI
|
||||
$result = $this->_error("Unable to load the requested class: " . $resourceName);
|
||||
$result = error('Unable to load the requested class: ' . $resourceName);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// Errors while loading the library
|
||||
$result = $this->_error("Errors while loading the library: " . $e->getMessage());
|
||||
$result = error('Errors while loading the library: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (!is_null($loaded))
|
||||
{
|
||||
$result = $this->_success($loaded);
|
||||
$result = success($loaded);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -329,7 +329,7 @@ class PCRMLib
|
||||
// If the function is static
|
||||
if ($reflectionMethod->isStatic() === true)
|
||||
{
|
||||
$classMethod = $resourceName . "::" . $function;
|
||||
$classMethod = $resourceName . '::' . $function;
|
||||
}
|
||||
// If the function is not static
|
||||
else
|
||||
@@ -349,48 +349,32 @@ class PCRMLib
|
||||
// it will be recognized like a running error. A little bit tricky ;)
|
||||
if ($resultCall === false)
|
||||
{
|
||||
$result = $this->_error("Error running " . $resourceName . "->" . $function . "()");
|
||||
$result = error('Error running ' . $resourceName . '->' . $function . '()');
|
||||
}
|
||||
// Returns the result of resource->function()
|
||||
else
|
||||
{
|
||||
$result = $this->_success($resultCall);
|
||||
$result = success($resultCall);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_error($resourceName . "->" . $function . "() is not callable!");
|
||||
$result = error($resourceName . '->' . $function . '() is not callable!');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_error(
|
||||
"Number of required parameters: " . $reflectionMethod->getNumberOfRequiredParameters() .
|
||||
". Given: " . count($parameters)
|
||||
$result = error(
|
||||
'Number of required parameters: ' . $reflectionMethod->getNumberOfRequiredParameters() .
|
||||
'. Given: ' . count($parameters)
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$result = $this->_error($e->getMessage());
|
||||
$result = error($e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private function _error($retval = '', $message = EXIT_ERROR)
|
||||
{
|
||||
return error($retval, $message);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private function _success($retval, $message = EXIT_SUCCESS)
|
||||
{
|
||||
return success($retval, $message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user