/** * Universalizing data structure * @param null $localization * @param bool $isExternalCall Set true if script called from external sources * @throws \Exception * @internal param null $localiztion */ public function __construct($localization = null, $isExternalCall = false) { $currentClass = get_class($this); if ($currentClass === "RootClass") { throw new \Exception("RootClass can not be used directly."); } if (is_array(static::$dataStructure) !== true) { throw new \Exception("Invalid Data Structure "); } $this->gp = new GroupPolicy($this); $reflection = new \ReflectionClass($currentClass); $this->classNameWithoutNm = $reflection->getShortName(); $this->dbTable = strtolower($this->classNameWithoutNm); unset($reflection); if (is_string($localization)) { $localizationHelper = new LocalizationHelper(); if ($localizationHelper->isCorrectPrefix($localization)) { $this->localization = $localization; } unset($localizationHelper); } $this->dbConnection = $GLOBALS['EMA']['DB']['connection']; $this->appConfig = new AppConfig($this->classNameWithoutNm); $this->isExternalCall = (bool) $isExternalCall; }
/** * Set a localization * @param string $prefix */ public function setLocalization($prefix = '') { $localHelper = new LocalizationHelper(); if ($localHelper->isCorrectPrefix($prefix)) { $this->localization = mb_strtolower($prefix); } unset($localHelper); }
private static function standardMethodCall() { if ($_POST['action'] === "standardMethod") { if (isset($_POST['class']) === false || is_string($_POST['class']) === false) { throw new RuntimeException("Invalid Request"); } if (isset($_POST['method']) === false || is_string($_POST['method']) === false) { throw new RuntimeException("Invalid Request"); } $className = $_POST['class']; $methodName = $_POST['method']; $arguments = null; if (isset($_POST['arguments']) === true) { if (is_string($_POST['arguments']) === true || is_array($_POST['arguments']) === true) { if (is_string($_POST['arguments']) === true) { if (RootClass::isJson($_POST['arguments']) === true) { $parsedArgs = json_decode($_POST['arguments'], true); } else { $parsedArgs = $_POST['arguments']; } } else { $parsedArgs = $_POST['arguments']; } $arguments = $parsedArgs; unset($parsedArgs); } else { throw new RuntimeException("Invalid Request"); } } $local = null; if (isset($_COOKIE['local'])) { $local = $_COOKIE['local']; } elseif (isset($_SERVER['HTTP_EMA_LOCALIZATION'])) { $local = $_SERVER['HTTP_EMA_LOCALIZATION']; } if ($local !== null) { $localizationHelper = new LocalizationHelper(); if (!$localizationHelper->isCorrectPrefix($local)) { $local = $localizationHelper->getDefault(); } unset($localizationHelper); } $rpc = new RpcCall($className, $methodName, $arguments); $rpc->setLocalization($local); $result = $rpc->run(); print json_encode($result); return self::APP_JSON_TYPE; } }