Example #1
0
 /**
  * Set a localization
  * @param string $prefix
  */
 public function setLocalization($prefix = '')
 {
     $localHelper = new LocalizationHelper();
     if ($localHelper->isCorrectPrefix($prefix)) {
         $this->localization = mb_strtolower($prefix);
     }
     unset($localHelper);
 }
Example #2
0
 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;
     }
 }
Example #3
0
 /**
  * Generate list of fields using filed name
  *
  * @param string $fieldName
  * @return array
  * @throws \Exception
  */
 protected function simpleGenerateLocalizationField($fieldName = "")
 {
     if (!is_string($fieldName)) {
         throw new \Exception("Argument is not a string");
     }
     $fields = array();
     if ($this->localization === null) {
         $localizationHelper = new LocalizationHelper();
         $possibleLocalizations = $localizationHelper->getPossibleLocalizations();
         if ($possibleLocalizations === false) {
             throw new \Exception("Cannot get possible localizations");
         }
         if (!empty($possibleLocalizations)) {
             foreach ($possibleLocalizations as $prefix) {
                 $fields[] = $fieldName . "_" . $prefix;
             }
         }
     } else {
         $fields[] = $fieldName . "_" . $this->localization . "(" . $fieldName . ")";
     }
     return $fields;
 }