Example #1
0
 /**
  * save the data to the storage
  *
  * @error 16404
  * @throws Xapp_Util_Exception_Storage
  * @return void
  */
 public function save()
 {
     $return = null;
     switch ($this->_storageType) {
         case 'json':
             $return = file_put_contents($this->_storage, Xapp_Util_Json::prettify(Xapp_Util_Json::encode($this->getArrayCopy())), LOCK_EX);
             break;
         case 'serialized':
             $return = file_put_contents($this->_storage, serialize($this->getArrayCopy()), LOCK_EX);
             break;
         default:
             //nothing
     }
     if ($return === false) {
         throw new Xapp_Util_Exception_Storage('unable to save to storage', 1640401);
     }
 }
Example #2
0
 /**
  * json implementation of saveTo method, see Xapp_Util_Std_Store::saveTo for more details
  *
  * @error 16905
  * @param string $file expects absolute file path to store object at
  * @param bool $pretty expects boolean value whether to store json string pretty or non pretty
  * @return bool
  * @throws Xapp_Util_Json_Exception
  */
 public function saveTo($file, $pretty = true)
 {
     $result = null;
     if ((bool) $pretty) {
         $result = file_put_contents($file, Xapp_Util_Json::prettify(Xapp_Util_Json::encode($this->_object)), LOCK_EX);
     } else {
         $result = file_put_contents($file, Xapp_Util_Json::encode($this->_object), LOCK_EX);
     }
     if ($result !== false) {
         $result = null;
         return true;
     } else {
         throw new Xapp_Util_Json_Exception(xapp_sprintf(_("unable to save to file: %s"), $file), 1690501);
     }
 }
Example #3
0
 /**
  * @param $storage
  * @param $data
  * @param string $type
  * @param bool $pretty
  * @return null
  * @throws Xapp_Util_Exception_Storage
  */
 public static function write_json($storage, $data, $type = 'json', $pretty = false, $pass = null)
 {
     $return = null;
     switch ($type) {
         case 'json':
             $_dataStr = is_string($data) ? $data : Xapp_Util_Json::encode($data);
             if (strpos($storage, '.php') != -1) {
                 $_dataStr = '<?php ' . PHP_EOL . $_dataStr;
             }
             if (isset($pass) && strlen($pass)) {
                 $_dataStr = '~~~~~' . self::encrypt($_dataStr, $pass);
             }
             if ($pretty === true) {
                 $return = file_put_contents($storage, Xapp_Util_Json::prettify($_dataStr), LOCK_EX);
             } else {
                 $return = file_put_contents($storage, $_dataStr, LOCK_EX);
             }
             break;
         case 'serialized':
             $return = file_put_contents($storage, serialize($data), LOCK_EX);
             break;
         default:
             //nothing
     }
     if ($return === false) {
         throw new Xapp_Util_Exception_Storage('unable to save to storage', 1640401);
     }
     return null;
 }