Esempio n. 1
0
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $i = 0;
     $output->write("[");
     foreach ($obj as $elem) {
         if ($i != 0) {
             $output->write(",");
         }
         TransformerFactory::get($elem)->transform($elem, $output, $conf);
         $i++;
     }
     $output->write("]");
 }
Esempio n. 2
0
 /**
  * @param $obj object to transform
  * @param OutputStream $output
  * @param Configuration $conf
  * @throws \Exception
  */
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $i = 0;
     $output->write("{");
     while (list($key, $value) = each($obj)) {
         if ($i != 0) {
             $output->write(",");
         }
         $output->write("\"" . JsonEscapeUtils::escapeJson($key) . "\":");
         TransformerFactory::get($value)->transform($value, $output, $conf);
         $i++;
     }
     $output->write("}");
 }
Esempio n. 3
0
 /**
  * @param $obj object to transform
  * @param OutputStream $output
  * @param Configuration $conf
  * @throws \Exception
  */
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $i = 0;
     $refClass = new \ReflectionClass($obj);
     $props = $refClass->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE);
     if (count($props) > 0) {
         $output->write("{");
         $clazz = get_class($obj);
         $excludeNull = $conf->getBoolean(Configuration::EXCLUDE_NULL_PROPERTY, false);
         $includeClass = $conf->getBoolean(Configuration::INCLUDE_CLASS_NAME_PROPERTY, false);
         $clazzName = $conf->getString(Configuration::CLASS_PROPERTY, Configuration::DEFAULT_CLASS_PROPERTY_VALUE);
         $clazzStrategy = $conf->getString(Configuration::CLASS_TYPE_PROPERTY, LanguageStrategyFactory::LANG_PHP);
         foreach ($props as $prop) {
             // check getter
             $val = null;
             try {
                 $refMethod = new \ReflectionMethod($clazz, "get" . ucfirst($prop->getName()));
                 if ($refMethod->isPublic()) {
                     $val = $refMethod->invoke($obj);
                 }
             } catch (\Exception $e) {
             }
             if (!isset($val)) {
                 $prop->setAccessible(true);
                 $val = $prop->getValue($obj);
             }
             if ($excludeNull === false || ($val !== null || $val !== "")) {
                 if ($prop->getName() != $clazzName) {
                     if ($i != 0) {
                         $output->write(",");
                     }
                     $output->write("\"" . JsonEscapeUtils::escapeJson($prop->getName()) . "\":");
                     TransformerFactory::get($val)->transform($val, $output, $conf);
                     $i++;
                 }
             }
         }
         if ($includeClass) {
             $clazz = LanguageStrategyFactory::getClassStrategy($clazzStrategy)->className($clazz);
             if ($i != 0) {
                 $output->write(",");
             }
             $output->write("\"{$clazzName}\":\"{$clazz}\"");
         }
         $output->write("}");
     } else {
         $output->write("null");
     }
 }
 /**
  * @param $obj object to transform
  * @param OutputStream $output
  * @param Configuration $conf
  * @return void
  */
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     if ($conf == null) {
         $conf = new Configuration();
     }
     $strategy = $conf->getString(Configuration::DATE_STRATEGY_PROPERTY, Configuration::DATE_STRATEGY_TIMESTAMP);
     if ($strategy == Configuration::DATE_STRATEGY_TIMESTAMP) {
         $res = $obj->getTimestamp();
         $output->write("" . $res);
     } else {
         $format = $conf->getString(Configuration::DATE_FORMAT_PROPERTY, Configuration::DEFAULT_DATE_FORMAT);
         $res = $obj->format($format);
         $output->write("\"" . $res . "\"");
     }
 }
Esempio n. 5
0
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $output->write("" . floatval($obj));
 }
Esempio n. 6
0
 /**
  * @param $obj object to transform
  * @param OutputStream $output
  * @param Configuration $conf
  */
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $output->write("null");
 }
Esempio n. 7
0
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $output->write("\"" . JsonEscapeUtils::escapeJson($obj) . "\"");
 }
 /**
  * @param $obj object to transform
  * @param OutputStream $output
  * @param Configuration $conf
  */
 public function transform($obj, OutputStream $output, Configuration $conf)
 {
     $output->write($obj === true ? "true" : "false");
 }