* @copyright 2010 Luracast * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link http://luracast.com/products/restler/ * @version 3.0.0rc5 */ class PlistFormat extends MultiFormat { /** * @var boolean set it to true binary plist is preferred */ public static $compact = null; const MIME = 'application/xml,application/x-plist'; const EXTENSION = 'plist'; public function setMIME($mime) { static::$mime = $mime; static::$compact = $mime == 'application/x-plist'; } /** * 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( Object::toArray($data) ); $plist->add($guessedStructure); return self::$compact ? $plist->toBinary() : $plist->toXML(true); } /** * Decode the given data from plist format * * @param string $data * data sent from client to * the api in the given format. * * @return array associative array of the parsed data */ public function decode($data) { //require_once 'CFPropertyList.php'; $plist = new CFPropertyList (); $plist->parse($data); return $plist->toArray(); } }