<commit_before><?php
/**
 * Plist Format for Restler Framework.
 * Plist is the native data exchange format for Apple iOS and Mac platform.
 * Use this format to talk to mac applications and iOS devices.
 * This class is capable of serving both xml plist and binary plist.
 * @category   Framework
 * @package    restler
 * @subpackage format
 * @author     <NAME> <<EMAIL>>
 * @copyright  2010 Luracast
 * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link       http://luracast.com/products/restler/
 */
class PlistFormat implements IFormat {
    public static $binary_mode = false;
    const MIME_BINARY = 'application/x-plist';
    const EXTENSION_BINARY = 'bplist';
    const MIME_XML = 'application/xml';
    const EXTENSION_XML = 'plist';

    public function getMIMEMap()
    {
        return array (
                self::EXTENSION_BINARY => self::MIME_BINARY,
                self::EXTENSION_XML => self::MIME_XML 
        );
    }

    public function getMIME()
    {
        return self::$binary_mode ? self::MIME_BINARY : self::MIME_XML;
    }

    public function getExtension()
    {
        return self::$binary_mode ? self::EXTENSION_BINARY : self::EXTENSION_XML;
    }

    public function setMIME($mime)
    {
        self::$binary_mode = $mime == self::MIME_BINARY;
    }

    public function setExtension($extension)
    {
        self::$binary_mode = $extension == self::EXTENSION_BINARY;
    }

    /**
     * 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 (! self::$binary_mode) {
            self::$binary_mode = ! $humanReadable;
        }
        /**
         *
         * @var CFPropertyList
         */
        $plist = new CFPropertyList ();
        $td = new CFTypeDetector ();
        $guessedStructure = $td->toCFType ( 
                RestlerHelper::objectToArray ( $data ) );
        $plist->add ( $guessedStructure );
        return self::$binary_mode ? $plist->toBinary () : 
            $plist->toXML ( true );
    }

    /**
     * Decode the given data from plist format<commit_msg>improved styling<commit_after><?php
/**
 * Plist Format for Restler Framework.
 * Plist is the native data exchange format for Apple iOS and Mac platform.
 * Use this format to talk to mac applications and iOS devices.
 * This class is capable of serving both xml plist and binary plist.
 * @category   Framework
 * @package    restler
 * @subpackage format
 * @author     <NAME> <<EMAIL>>
 * @copyright  2010 Luracast
 * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link       http://luracast.com/products/restler/
 */
class PlistFormat implements IFormat {
    public static $binary_mode = false;
    const MIME_BINARY = 'application/x-plist';
    const EXTENSION_BINARY = 'bplist';
    const MIME_XML = 'application/xml';
    const EXTENSION_XML = 'plist';

    public function getMIMEMap()
    {
        return array (
                self::EXTENSION_BINARY => self::MIME_BINARY,
                self::EXTENSION_XML => self::MIME_XML 
        );
    }

    public function getMIME()
    {
        return self::$binary_mode ? 
            self::MIME_BINARY : self::MIME_XML;
    }

    public function getExtension()
    {
        return self::$binary_mode ? 
            self::EXTENSION_BINARY : self::EXTENSION_XML;
    }

    public function setMIME($mime)
    {
        self::$binary_mode = $mime == self::MIME_BINARY;
    }

    public function setExtension($extension)
    {
        self::$binary_mode = $extension == self::EXTENSION_BINARY;
    }

    /**
     * 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 (! self::$binary_mode) {
            self::$binary_mode = ! $humanReadable;
        }
        /**
         *
         * @var CFPropertyList
         */
        $plist = new CFPropertyList ();
        $td = new CFTypeDetector ();
        $guessedStructure = 
            $td->toCFType ( RestlerHelper::objectToArray ( $data ) );
        $plist->add ( $guessedStructure );
        return self::$binary_mode ? 
            $plist->toBinary () : $plist->toXML ( true );
    }

    /**
     * Decode the given data from plist format
{'fraction_non_alphanumeric': 0.10221264930487566, 'fraction_numerical': 0.0015664773839827687, 'mean_word_length': 2.1845386533665834, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4721193', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1464, 'n_words': 398}