[vz-dev] Code Review Controler/DataControler.php

Sven Anders sven at anders-hamburg.de
Sun Dec 4 10:21:06 CET 2011


Kann mir jemand die Stelle in: Controller/DataController.php

51           * Sporadic test/demo implemenation
52           *
53           * @todo replace by pluggable api parser
54           */
55          public function add(Model\Channel $channel) {
56                  try { /* to parse new submission protocol */
57                          $rawPost = file_get_contents('php://input');
58                          $json = Util\JSON::decode($rawPost);
59                          foreach ($json as $tuple) {
60                                  $channel->addData(new 
Model\Data($channel, (double) round($tuple[0]), $tuple[1]));
61                          }
62                  } catch (Util\JSONException $e) { /* fallback to old 
method */
63                          $timestamp = 
$this->view->request->getParameter('ts');
64                          $value = 
$this->view->request->getParameter('value');
65
66                          if (is_null($timestamp)) {
67                                  $timestamp = (double) 
round(microtime(TRUE) * 1000);
68                          }
69
70                          if (is_null($value)) {
71                                  $value = 1;
72                          }
73
74                          $channel->addData(new Model\Data($channel, 
$timestamp, $value));
75                  }
76
77                  $this->em->flush();
78          }

genauer erklären. Ich vestehe folgendes nicht/habe Anmerkungen:

1. Was ist mit dem ToDo in Zeile 53 gemeint? Wie soll das in Zukunft 
aussehen?

2. In dem try Block (Zeile 56 bis 61) wird json gelesen und verarbeitet.
Von wo kommt der JSON String? Wie ruft man das in der API auf?
  Dabei wird mit tuple gearbeitet. Ist das nicht gefährlich?

Ein korreter JSON String wäre für mich eher sowas:
{
  "timestamp":"1322989829"
  "data":"42"
}

als sowas:

["1322989829","42"]

Nachteil vom zweiten, ich kann dem JSON String nicht asehen, was 
"1322989829" ist.

Wenn man das mit Tuple löst, macht es aber einen Unterschied ob man den 
Timestamp oder data zuerst schickt.


Gruß
Sven


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2321 bytes
Desc: S/MIME Kryptografische Unterschrift
URL: <http://volkszaehler.org/pipermail/volkszaehler-dev/attachments/20111204/7e29c9cf/attachment.bin>


More information about the volkszaehler-dev mailing list