/**
  * Format the response into the right content type.
  *
  * @param string $type
  * @return string
  */
 protected function _format($type)
 {
     $response = array('success' => $this->_success, 'data' => $this->_data);
     if ($this->_code) {
         $response['code'] = $this->_code;
     }
     switch (strtolower($type)) {
         case 'json':
             $format = TypeConverter::toJson($response);
             break;
         case 'xml':
             $format = TypeConverter::toXml($response);
             break;
         case 'html':
         case 'text':
         default:
             $format = (string) $this->_data;
             break;
     }
     return $format;
 }
Example #2
0
    debug('TypeConverter::' . $method . '()');
    dump('array', TypeConverter::$method($array));
    dump('object', TypeConverter::$method($object));
    dump('json', TypeConverter::$method($json));
    dump('serialize', TypeConverter::$method($ser));
    dump('xml', TypeConverter::$method($xml));
}
// Convert all the types
foreach (array('toArray', 'toObject', 'toJson', 'toSerialize', 'toXml') as $method) {
    debug('TypeConverter::' . $method . '()');
    if ($method == 'toXml') {
        debug(htmlentities(TypeConverter::toXml($array)));
        debug(htmlentities(TypeConverter::toXml($object)));
        debug(htmlentities(TypeConverter::toXml($json)));
        debug(htmlentities(TypeConverter::toXml($ser)));
        debug(htmlentities(TypeConverter::toXml($xml)));
    } else {
        debug(TypeConverter::$method($array));
        debug(TypeConverter::$method($object));
        debug(TypeConverter::$method($json));
        debug(TypeConverter::$method($ser));
        debug(TypeConverter::$method($xml));
    }
}
// Convert a complicated XML file to an array
$xml = file_get_contents('test.xml');
foreach (array('none', 'merge', 'group', 'overwrite') as $format) {
    debug('TypeConverter::xmlToArray(' . $format . ')');
    switch ($format) {
        case 'none':
            debug(TypeConverter::xmlToArray($xml, TypeConverter::XML_NONE));
 public function convert(array $data)
 {
     return str_replace(PHP_EOL, '', TypeConverter::toXml($data));
 }