public static function encode($data, $options = 0, $depth = 512) { if ($data === false) { return 'false'; } if (AbstractApp::isDev()) { $tmp = PrettyJson::encode($data, $options = PrettyJson::JSON_PRETTY_PRINT | PrettyJson::JSON_FORCEUTF8 | PrettyJson::JSON_UNESCAPED_SLASHES | PrettyJson::JSON_UNESCAPED_UNICODE, $depth); } else { if (version_compare(PHP_VERSION, '5.4.0', '<')) { $tmp = json_encode($data, $options); } else { $tmp = json_encode($data, $options, $depth); } } if ($tmp === false) { throw new Exception('conditional: Nie powiodło się przekształcenie za pomocą json_encode' . print_r($data, true)); } return $tmp; }
protected function _index($service, $index, $type, $tdata, $id, OutputInterface $output = null) { if (!$output) { $output = new ConsoleOutput(); } $output->writeln(" Update element '{$id}' of type: '{$type}'"); // $atonce = UtilArray::cascadeGet($tdata, 'mapping.maxresults'); // $useidfrom = UtilArray::cascadeGet($tdata, 'mapping.useidfrom'); $setupquerybuilder = UtilArray::cascadeGet($tdata, 'mapping.setupquerybuilder'); $findbyid = UtilArray::cascadeGet($tdata, 'mapping.findbyid'); $transform = UtilArray::cascadeGet($tdata, 'mapping.transformermethod'); /* @var $qb QueryBuilder */ $qb = call_user_func(array($service, $findbyid), $id); $r = $this->dbal->fetchAssoc($qb->getSQL()); if ($transform) { $r = call_user_func(array($service, $transform), $r); } $row = array(); foreach ($tdata['properties'] as $name => &$f) { $row[$name] = UtilNested::get($r, $f['mapping']['field']); } $output->write(" Update: {$id}\r"); $result = $this->api('PUT', "/{$index}/{$type}/{$id}", $row); $output->writeln(PrettyJson::encode($result)); }