/**
  * Encode the given data in plist format
  *
  * @param array   $data
  *            resulting data that needs to
  *            be encoded in plist format
  * @param boolean $humanReadable
  *            set to true when restler
  *            is not running in production mode. Formatter has to
  *            make the encoded output more human readable
  *
  * @return string encoded string
  */
 public function encode($data, $humanReadable = false)
 {
     //require_once 'CFPropertyList.php';
     if (!isset(self::$compact)) {
         self::$compact = !$humanReadable;
     }
     /**
      *
      * @var CFPropertyList
      */
     $plist = new CFPropertyList();
     $td = new CFTypeDetector();
     $guessedStructure = $td->toCFType(Util::objectToArray($data));
     $plist->add($guessedStructure);
     return self::$compact ? $plist->toBinary() : $plist->toXML(true);
 }
 public function encode($data, $humanReadable = false)
 {
     $data = Util::objectToArray($data);
     $params = array();
     if (isset($this->restler->apiMethodInfo->metadata)) {
         $metadata = $this->restler->apiMethodInfo->metadata;
         $params = $metadata['param'];
     }
     foreach ($params as $index => &$param) {
         $index = intval($index);
         if (is_numeric($index)) {
             $param['value'] = $this->restler->apiMethodInfo->arguments[$index];
         }
     }
     $data['param'] = $params;
     if (isset($metadata['template'])) {
         self::$template = $metadata['template'];
     }
     $m = new Mustache_Engine();
     return $m->render($this->loadTemplate(self::$template), $data);
 }
Ejemplo n.º 3
0
 public function decode($data)
 {
     $options = 0;
     if (self::$bigIntAsString) {
         if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4 || PHP_MAJOR_VERSION > 5) {
             $options |= JSON_BIGINT_AS_STRING;
         } else {
             $data = preg_replace('/:\\s*(\\-?\\d+(\\.\\d+)?([e|E][\\-|\\+]\\d+)?)/', ': "$1"', $data);
         }
     }
     $decoded = json_decode($data, $options);
     if (function_exists('json_last_error')) {
         switch (json_last_error()) {
             case JSON_ERROR_NONE:
                 return Util::objectToArray($decoded);
                 break;
             case JSON_ERROR_DEPTH:
                 $message = 'maximum stack depth exceeded';
                 break;
             case JSON_ERROR_STATE_MISMATCH:
                 $message = 'underflow or the modes mismatch';
                 break;
             case JSON_ERROR_CTRL_CHAR:
                 $message = 'unexpected control character found';
                 break;
             case JSON_ERROR_SYNTAX:
                 $message = 'malformed JSON';
                 break;
             case JSON_ERROR_UTF8:
                 $message = 'malformed UTF-8 characters, possibly ' . 'incorrectly encoded';
                 break;
             default:
                 $message = 'unknown error';
                 break;
         }
         throw new RestException(400, 'Error parsing JSON, ' . $message);
     } elseif (strlen($data) && $decoded === null || $decoded === $data) {
         throw new RestException(400, 'Error parsing JSON');
     }
     return Util::objectToArray($decoded);
 }
Ejemplo n.º 4
0
 public function encode($data, $humanReadable = false)
 {
     //      require_once 'sfyaml.php';
     return @Yaml::dump(Util::objectToArray($data));
 }
Ejemplo n.º 5
0
 public function encode($data, $humanReadable = false)
 {
     return $this->toXML(Util::objectToArray($data, false), self::$rootName, $humanReadable);
 }