Example #1
0
 /**
  * Gets the default and possible locales of the shop.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.0.0
  * @since 0.0.1 Use HTTPRequestMethod enum.
  * @since 0.1.0 Save timestamp of the last request.
  * @since 0.1.0 Add configured used Locale.
  * @since 0.1.2 Add error reporting.
  * @since 0.2.1 Implement REST client fixes.
  */
 private static function load()
 {
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         self::errorSet("RESTC-9");
         return;
     }
     RESTClient::send(self::RESTPATH);
     $content = RESTClient::getJSONContent();
     // if respond is empty or there are no default AND items element
     if (InputValidator::isEmptyArrayKey($content, "default") || InputValidator::isEmptyArrayKey($content, "items")) {
         Logger::error("Respond for " . self::RESTPATH . " can not be interpreted.");
         self::errorSet("L-1");
         return;
     }
     // reset values
     self::resetValues();
     // save the default localization
     self::$DEFAULT = $content["default"];
     // parse the possible localizations
     self::$ITEMS = $content["items"];
     // set the configured shop Locale if it is empty.
     if (InputValidator::isEmpty(self::$USED)) {
         self::$USED = $content["default"];
     }
     // update timestamp when make the next request
     $timestamp = (int) (microtime(true) * 1000);
     self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME;
 }
 /**
  * This function resets all locales values.
  */
 public static function resetValues()
 {
     self::$DEFAULT = null;
     self::$ITEMS = array();
 }
 /**
  * Sets the configured Locale.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.1.0
  * @api
  * @param String $locale The new used Locale.
  * @return boolean True if set the Locale works, false if not.
  */
 public static function setLocale($locale)
 {
     self::reload();
     if (array_key_exists($locale, self::$ITEMS)) {
         self::$USED = $locale;
         return true;
     }
     return false;
 }