Exemple #1
0
 public function encoder($input)
 {
     $output = $input;
     if (is_object($input)) {
         $classname = get_class($input);
         // Preserve Class information
         if ($classname != 'stdClass') {
             $output->_jsoon = new stdClass();
             $output->_jsoon->classname = $classname;
             // If parameters are advertised by the Class, cache them
             $function = $classname . '::declareJSONcalltimeparams()';
             if (is_callable($function)) {
                 $calltimeparams = $function();
                 if (isset($calltimeparams['parameters'])) {
                     $output->_jsoon->parameter = $calltimeparams['parameters'];
                 }
             }
         }
         $properties = get_object_vars($input);
         foreach ($properties as $pkey => $pvalue) {
             $output->{$pkey} = jsoonHandler::encoder($pvalue);
         }
     } elseif (is_array($input)) {
         // Check for relational array
         if (array_keys($input) !== range(0, count($input) - 1)) {
             $output = new stdClass();
             $output->_jsoon = new stdClass();
             $output->_jsoon->relational_array = true;
             foreach ($input as $key => $value) {
                 $output->{$key} = jsoonHandler::encoder($value);
             }
         } else {
             $output = array();
             foreach ($input as $key => $value) {
                 $output[$key] = jsoonHandler::encoder($value);
             }
         }
     }
     return $output;
 }