Exemple #1
0
 /**
  * Decodes the given request body, depending on the given content type.
  *
  * Currently JSON, XML and encoded forms are supported. The media types accepted
  * for choosing the respective decoding algorithm are rather broad. This method
  * does, for example, accept "text/x-json" although "application/json" is the
  * only valid (that is, IANA registered) media type for JSON.
  *
  * In future versions of FLOW3, this part maybe extensible by third-party code.
  * For the time being, only the mentioned media types are supported.
  *
  * Errors are silently ignored and result in an empty array.
  *
  * @param string $body The request body
  * @param string $mediaType The IANA Media Type
  * @return array The decoded body
  */
 protected function decodeBodyArguments($body, $mediaType)
 {
     switch (self::trimMediaType($mediaType)) {
         case 'application/json':
         case 'application/x-javascript':
         case 'text/javascript':
         case 'text/x-javascript':
         case 'text/x-json':
             $arguments = json_decode($body, TRUE);
             if ($arguments === NULL) {
                 return array();
             }
             break;
         case 'text/xml':
         case 'application/xml':
             try {
                 $xmlElement = new \SimpleXMLElement(urldecode($body), LIBXML_NOERROR);
             } catch (\Exception $e) {
                 return array();
             }
             $arguments = Arrays::convertObjectToArray($xmlElement);
             break;
         case 'application/x-www-form-urlencoded':
         default:
             parse_str($body, $arguments);
             break;
     }
     return $arguments;
 }
Exemple #2
0
 /**
  * @test
  */
 public function convertObjectToArrayConvertsNestedObjectsToArray()
 {
     $object = new \stdClass();
     $object->a = 'v';
     $object->b = new \stdClass();
     $object->b->c = 'w';
     $object->d = array('i' => 'foo', 'j' => 12, 'k' => TRUE, 'l' => new \stdClass());
     $array = \TYPO3\FLOW3\Utility\Arrays::convertObjectToArray($object);
     $expected = array('a' => 'v', 'b' => array('c' => 'w'), 'd' => array('i' => 'foo', 'j' => 12, 'k' => TRUE, 'l' => array()));
     $this->assertEquals($expected, $array);
 }
 /**
  * Process MongoDB results, add metadata and process object
  * values by loading objects. This method processes documents
  * batched for loading nested entities.
  *
  * @param array $documents Documents as objects
  * @param array &$knownObjects
  * @return array
  * @author Christopher Hlubek <*****@*****.**>
  */
 protected function documentsToObjectData(array $documents, array &$knownObjects = array())
 {
     $identifiersToFetch = array();
     $data = array();
     foreach ($documents as $document) {
         $objectData = \TYPO3\FLOW3\Utility\Arrays::convertObjectToArray($document);
         $objectData['identifier'] = $objectData['_id'];
         unset($objectData['_id']);
         $knownObjects[$objectData['identifier']] = TRUE;
         if (!isset($objectData['classname'])) {
             throw new \TYPO3\MongoDB\InvalidResultException('Expected property "classname" in document', 1310221818, NULL, $document);
         }
         if (!isset($this->classSchemata[$objectData['classname']])) {
             throw new \TYPO3\MongoDB\InvalidResultException('Class "' . $objectData['classname'] . '" was not registered', 1310221905, NULL, $document);
         }
         $this->processResultProperties($objectData['properties'], $identifiersToFetch, $knownObjects, $this->classSchemata[$objectData['classname']]);
         $data[] = $objectData;
     }
     if (count($identifiersToFetch) > 0) {
         // TODO Implement eager loading of additional documents
         $documents = array();
         $fetchedObjectsData = $this->documentsToObjectData($documents, $knownObjects);
         foreach ($fetchedObjectsData as $fetchedObjectData) {
             $identifiersToFetch[$fetchedObjectData['identifier']] = $fetchedObjectData;
         }
     }
     return $data;
 }