Author: Christian Weiske (christian.weiske@netresearch.de)
Esempio n. 1
7
 /**
  * @param Call $apiCall
  * @param $json
  * @return mixed
  */
 private function mapJsonToResponseObject(Call $apiCall, $json)
 {
     $jsonMapper = new \JsonMapper();
     $responseObject = $jsonMapper->map($json, $apiCall->getResponseObject());
     return $responseObject;
 }
 /**
  * Prepares the test
  */
 public function setUp()
 {
     $filename = __DIR__ . '/../../data/JenkinsPayloadAnalyzer/Nasqueron.json';
     $mapper = new \JsonMapper();
     $this->configuration = $mapper->map(json_decode(file_get_contents($filename)), new JenkinsPayloadAnalyzerConfiguration('Nasqueron'));
     parent::setUp();
 }
Esempio n. 3
0
 public function __construct(array $rawData = array())
 {
     //        foreach ($rawData as $_key => $_data) {
     //            $this->{$_key} = $_data;
     //        }
     $mapper = new \JsonMapper();
     $mapper->map($rawData, $this);
 }
Esempio n. 4
0
 public function testMapCustomArraObjectWithChildType()
 {
     $mapper = new \JsonMapper();
     $json = '{"users":[{"user":"******"}]}';
     $res = $mapper->map(json_decode($json), new UnitData());
     $this->assertInstanceOf('\\namespacetest\\UnitData', $res);
     $this->assertInstanceOf('\\namespacetest\\model\\UserList', $res->users);
     $this->assertInstanceOf('\\namespacetest\\model\\User', $res->users[0]);
 }
 public function testDecode()
 {
     $json = json_decode(file_get_contents('tests/push-reg-body.json'));
     $mapper = new JsonMapper();
     $push = $mapper->map($json, new Push());
     $this->assertEquals("Diaspora", $push->repository->name);
     $this->assertEquals("da1560886d4f094c3e6c9ef40349f7d38b5d27d7", $push->after);
     $this->assertEquals("fixed readme", $push->commits[1]->message);
     $this->assertEquals("GitLab dev user", $push->commits[1]->author->name);
     var_dump($push);
 }
Esempio n. 6
0
 /**
  * Gets a coderwall user
  * @param string $username The username
  * @param bool $full if your going to need all information from this user
  * @return User
  * @throws CoderWallException
  * @throws \JsonMapper_Exception
  */
 public function getUser($username, $full = true)
 {
     if (empty($username)) {
         throw new CoderWallException("Invalid username");
     }
     try {
         $json = $this->client->get($username . '.json' . ($full ? "?full=true" : ""))->json();
     } catch (ClientException $exception) {
         if ($exception->getResponse()->getStatusCode() === 404) {
             throw new CoderWallException("User doesn't exists");
         }
         throw $exception;
     }
     $mapper = new \JsonMapper();
     return $mapper->map($json, new User());
 }
Esempio n. 7
0
 protected function isFlatType($type)
 {
     if ($this->bExceptionOnFlatType && parent::isFlatType($type)) {
         throw new \JsonMapper_Exception('Invalid data type for some properties');
     }
     return false;
 }
Esempio n. 8
0
 /**
  * Create a new object of the given type.
  *
  * This method exists to be overwritten in child classes,
  * so you can do dependency injection or so.
  *
  * @param string  $class        Class name to instantiate
  * @param boolean $useParameter Pass $parameter to the constructor or not
  * @param mixed   $parameter    Constructor parameter
  *
  * @return object Freshly created object
  */
 public function createInstance($class, $useParameter = false, $parameter = null)
 {
     $object = parent::createInstance($class, $useParameter, $parameter);
     //dummy dependency injection
     $object->db = 'database';
     return $object;
 }
 public function toEntity(array $data = null)
 {
     $className = $this->getEntityClassName();
     $mapper = new \JsonMapper();
     if (null === $data) {
         $data = $this->toArrayWithoutRelations();
     }
     $data = (object) $data;
     $entity = $mapper->map($data, new $className());
     $this->mapEntityRelationships($entity);
     // entity was just hydrated
     // this means that any generated event should be removed
     if (true === method_exists($entity, 'flushEvents')) {
         $entity->flushEvents();
     }
     return $entity;
 }
Esempio n. 10
0
 protected function inspectProperty(\ReflectionClass $rc, $name)
 {
     $ret = parent::inspectProperty($rc, $name);
     if ($ret[0] === false) {
         if ($rc->hasMethod('__set')) {
             $a = $rc->getMethod('__set');
             return [true, new ReflectionContainer($a, $name), 'mixed'];
         }
     }
     return $ret;
 }
 /**
  * Deserialize the resource from the specified input stream.
  *
  * @param string $incoming The text to deserialize.
  *
  * @return mixed the resource.
  */
 public function deserialize($incoming)
 {
     $resources = null;
     $json = json_decode($incoming);
     foreach ($json as $key => $value) {
         if (JsonMapper::isKnownType($key)) {
             $class = XmlMapper::getClassName($key);
             $resources[] = new $class($value);
         }
     }
     return $resources;
 }
Esempio n. 12
0
 /**
  * Template Level Qualifying Conditions List
  * @param array List of Qualifying Conditions
  */
 public function setQcList($qcList)
 {
     $mapper = new \JsonMapper();
     $this->qcList = array();
     if (empty($qcList)) {
         return;
     }
     foreach ($qcList as $idx => $qc) {
         if (is_array($qc)) {
             $qcName = $qc['name'];
         } else {
             if (isset($qc->name)) {
                 $qcName = $qc->name;
             } else {
                 // An empty object
                 continue;
             }
         }
         if (strcasecmp($qcName, \Akzo\Scheme\Data\QualifyingCondition\Type::HISTORICAL) === 0) {
             $this->qcList[] = $mapper->map($qc, new \Akzo\Scheme\Data\QualifyingCondition\HistoricalQC());
         } else {
             if (strcasecmp($qcName, \Akzo\Scheme\Data\QualifyingCondition\Type::GROWTH) === 0) {
                 $this->qcList[] = $mapper->map($qc, new \Akzo\Scheme\Data\QualifyingCondition\GrowthQC());
             } else {
                 if (strcasecmp($qcName, \Akzo\Scheme\Data\QualifyingCondition\Type::ACTUAL) === 0) {
                     $this->qcList[] = $mapper->map($qc, new \Akzo\Scheme\Data\QualifyingCondition\ActualQC());
                 } else {
                     if (strcasecmp($qcName, \Akzo\Scheme\Data\QualifyingCondition\Type::TARGET) === 0) {
                         $this->qcList[] = $mapper->map($qc, new \Akzo\Scheme\Data\QualifyingCondition\TargetQC());
                     } else {
                         if (strcasecmp($qcName, \Akzo\Scheme\Data\QualifyingCondition\Type::TARGET_ACHIEVEMENT) === 0) {
                             $this->qcList[] = $mapper->map($qc, new \Akzo\Scheme\Data\QualifyingCondition\TargetAchievementQC());
                         } else {
                             if (strcasecmp($qcName, \Akzo\Scheme\Data\QualifyingCondition\Type::RATIO) === 0) {
                                 $this->qcList[] = $mapper->map($qc, new \Akzo\Scheme\Data\QualifyingCondition\RatioQC());
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 13
0
 /**
  * Returns the $resultSet from the $response object, or $defaultValue if 
  * the result set is not available
  * @param stdClass $response an API response object
  * @param string $resultSet the name of the result set
  * @param mixed $defaultValue the value to return if the result set is not 
  * available
  * @param mixed an instance of the class the results should be mapped to, or 
  * null to use stdClass
  * @return mixed the normalized response
  */
 private static function normalizeResponse($response, $resultSet, $defaultValue, $targetObject = null)
 {
     if (isset($response->result->{$resultSet})) {
         $result = $response->result->{$resultSet};
         if ($targetObject !== null) {
             $mapper = new JsonMapper();
             if (is_array($result)) {
                 return $mapper->mapArray($result, new ArrayObject(), $targetObject)->getArrayCopy();
             } elseif (is_object($result)) {
                 return $mapper->map($result, $targetObject);
             }
         }
         return $response->result->{$resultSet};
     } else {
         return $defaultValue;
     }
 }
Esempio n. 14
0
 public function _buildSchemeDataFromJson($jsonData, $format = 'json')
 {
     if (strcasecmp($format, 'json') === 0) {
         $jsonData = json_decode($jsonData);
     }
     if (empty($jsonData)) {
         return null;
     }
     $mapper = new \JsonMapper();
     return $mapper->map($jsonData, new \Akzo\Scheme\Data());
 }
Esempio n. 15
0
 public function testSettingValueObjects()
 {
     $valueObject = new JsonMapperTest_ValueObject('test');
     $jm = new JsonMapper();
     $sn = $jm->map((object) array('value_object' => $valueObject), new JsonMapperTest_Simple());
     $this->assertSame($valueObject, $sn->getValueObject());
 }
Esempio n. 16
0
 public function testSetterIsPreferredOverProperty()
 {
     $jm = new JsonMapper();
     $sn = $jm->map(json_decode('{"setterPreferredOverProperty":"foo"}'), new JsonMapperTest_Simple());
     $this->assertInternalType('string', $sn->setterPreferredOverProperty);
     $this->assertEquals('set via setter: foo', $sn->setterPreferredOverProperty);
 }
            "networkPrefix":"79",
            "countryPrefix":"41"
         },
         "ported":false,
         "roaming":false,
         "status":{
            "groupId":2,
            "groupName":"UNDELIVERABLE",
            "id":9,
            "name":"UNDELIVERABLE_NOT_DELIVERED",
            "description":"Message sent not delivered"
         },
         "error":{
            "groupId":1,
            "groupName":"HANDSET_ERRORS",
            "id":27,
            "name":"EC_ABSENT_SUBSCRIBER",
            "description":"Absent Subscriber",
            "permanent":false
         }
      }
   ]
}';
$mapper = new JsonMapper();
$responseObject = $mapper->map(json_decode($responseBody), new NumberContextResponse());
$numberContext = $responseObject->getResults()[0];
echo "Phone number: " . $numberContext->getTo() . "\n";
echo "MccMnc: " . $numberContext->getMccMnc() . "\n";
echo "Original country prefix: " . $numberContext->getOriginalNetwork()->getCountryPrefix() . "\n";
echo "Original network prefix: " . $numberContext->getOriginalNetwork()->getNetworkPrefix() . "\n";
echo "Status: " . $numberContext->getStatus()->getName();
Esempio n. 18
0
<?php

require_once __DIR__ . '/../src/JsonMapper.php';
require_once 'Contact.php';
require_once 'Address.php';
$json = json_decode(file_get_contents(__DIR__ . '/single.json'));
$mapper = new JsonMapper();
$contact = $mapper->map($json, new Contact());
$coords = $contact->address->getGeoCoords();
echo $contact->name . ' lives at coordinates ' . $coords['lat'] . ',' . $coords['lon'] . "\n";
Esempio n. 19
0
 public function testClassMap()
 {
     $jm = new JsonMapper();
     $jm->classMap['JsonMapperTest_PlainObject'] = 'DateTime';
     $sn = $jm->map(json_decode('{"pPlainObject":"2016-04-14T23:15:42+02:00"}'), new JsonMapperTest_Object());
     $this->assertInternalType('object', $sn->pPlainObject);
     $this->assertInstanceOf('DateTime', $sn->pPlainObject);
     $this->assertEquals('2016-04-14T23:15:42+02:00', $sn->pPlainObject->format('c'));
 }
 /**
  * Loads configuration for the analyzer
  */
 public function loadConfiguration()
 {
     $fileName = $this->getConfigurationFileName();
     $class = $this->getConfigurationClassName();
     $mapper = new \JsonMapper();
     $this->configuration = $mapper->map(json_decode(Storage::get($fileName)), new $class($this->project));
 }
Esempio n. 21
0
 /**
  * Variable with an underscore and a setter method
  */
 public function testMapSimpleUnderscoreSetter()
 {
     $jm = new JsonMapper();
     $sn = $jm->map(json_decode('{"under_score_setter":"blubb"}'), new JsonMapperTest_Simple());
     $this->assertInternalType('string', $sn->internalData['under_score_setter']);
     $this->assertEquals('blubb', $sn->internalData['under_score_setter']);
 }
Esempio n. 22
0
 /**
  * Variable with hyphen and a setter method
  */
 public function testMapSimpleHyphenSetter()
 {
     $jm = new JsonMapper();
     $sn = $jm->map(json_decode('{"hyphen-value-setter":"blubb"}'), new JsonMapperTest_Simple());
     $this->assertInternalType('string', $sn->internalData['hyphen-value-setter']);
     $this->assertEquals('blubb', $sn->internalData['hyphen-value-setter']);
 }
 private function getPhabricatorPayloadAnalyzerConfiguration()
 {
     $filename = __DIR__ . '/../../data/PhabricatorPayloadAnalyzer/Nasqueron.json';
     $mapper = new \JsonMapper();
     return $mapper->map(json_decode(file_get_contents($filename)), new PhabricatorPayloadAnalyzerConfiguration('Nasqueron'));
 }
Esempio n. 24
0
 /**
  * Test a setter method with a namespaced type hint that
  * is within another namespace than the object itself.
  */
 public function testSetterNamespacedTypeHint()
 {
     $mapper = new \JsonMapper();
     $json = '{"namespacedTypeHint":"Foo"}';
     $res = $mapper->map(json_decode($json), new UnitData());
     $this->assertInstanceOf('\\namespacetest\\UnitData', $res);
     $this->assertInstanceOf('\\othernamespace\\Foo', $res->internalData['namespacedTypeHint']);
     $this->assertEquals('Foo', $res->internalData['namespacedTypeHint']->name);
 }
Esempio n. 25
0
 /**
  * @expectedException        JsonMapper_Exception
  * @expectedExceptionMessage JSON property "privatePropertyPrivateSetter" has no public setter method in object of type PrivateWithSetter
  */
 public function testPrivatePropertyWithPrivateSetter()
 {
     $jm = new JsonMapper();
     $jm->bExceptionOnUndefinedProperty = true;
     $logger = new JsonMapperTest_Logger();
     $jm->setLogger($logger);
     $json = '{"privatePropertyPrivateSetter" : 1}';
     $result = $jm->map(json_decode($json), new PrivateWithSetter());
 }
Esempio n. 26
0
 public function testCaseInsensitivePropertyMatching()
 {
     $jm = new JsonMapper();
     $sn = $jm->map((object) array('PINT' => 2), new JsonMapperTest_Simple());
     $this->assertSame(2, $sn->pint);
 }
Esempio n. 27
0
        $this->lol = $val;
    }
    public function getLol()
    {
        return $this->lol;
    }
}
class Serializator implements JsonSerializable
{
    public $label = "label", $data = null, $field = null;
    public function __construct()
    {
        $this->data = new DateTime();
        $this->field = new Test(42);
    }
    function jsonSerialize()
    {
        return ['type' => $this->label, 'date' => $this->data->format(DateTime::ISO8601), 'field' => $this->field];
    }
}
$my_json = json_encode(new Serializator());
$decoded_json = json_decode($my_json);
$mapper = new JsonMapper();
$serialization = $mapper->map($decoded_json, new Serializator());
$test = new Test(42);
$test->getLol();
var_dump($serialization->field->lol);
#$lol = $serialization->field->getLol();
echo json_encode(new Serializator()) . "\n";
#echo "\n";
var_dump(json_decode(json_encode(new Serializator())));
Esempio n. 28
0
 /**
  * The TYPO3 autoloader breaks if we autoload a class with a [ or ]
  * in its name.
  *
  * @runInSeparateProcess
  */
 public function testMapTypedArrayObjectDoesNotExist()
 {
     $this->assertTrue(spl_autoload_register(array($this, 'mapTypedArrayObjectDoesNotExistAutoloader')));
     $jm = new JsonMapper();
     $sn = $jm->map(json_decode('{"pTypedArrayObjectNoClass":[{"str":"stringvalue"}]}'), new JsonMapperTest_Broken());
     $this->assertInstanceOf('ArrayObject', $sn->pTypedArrayObjectNoClass);
     $this->assertEquals(1, count($sn->pTypedArrayObjectNoClass));
     $this->assertInstanceOf('ThisClassDoesNotExist', $sn->pTypedArrayObjectNoClass[0]);
 }
 * User: nmenkovic
 * Date: 9/10/15
 * Time: 4:44 PM
 */
use infobip\api\model\sms\mo\reports\MOReportResponse;
require_once __DIR__ . '/../../vendor/autoload.php';
$responseBody = '{
   "results":[
      {
         "messageId":"ff4804ef-6ab6-4abd-984d-ab3b1387e823",
         "from":"38598111",
         "to":"41793026727",
         "text":"KEY Test message",
         "cleanText":"Test message",
         "keyword":"KEY",
         "receivedAt":"2015-02-15T11:43:20.254+0100",
         "smsCount":1
      }
   ]
}';
$mapper = new JsonMapper();
$responseObject = $mapper->map(json_decode($responseBody), new MOReportResponse());
$result = $responseObject->getResults()[0];
echo "Message ID: " . $result->getMessageId() . "\n";
echo "Received at: " . $result->getReceivedAt()->format('Y-m-d H:i:s P') . "\n";
echo "Sender: " . $result->getFrom() . "\n";
echo "Receiver: " . $result->getTo() . "\n";
echo "Message text: " . $result->getText() . "\n";
echo "Keyword: " . $result->getKeyword() . "\n";
echo "Clean text: " . $result->getCleanText() . "\n";
echo "Sms count: " . $result->getSmsCount();
Esempio n. 30
-1
 private function _collateExecutionResults($result, $existingResult, $code)
 {
     $mapper = new \JsonMapper();
     $resultsData = $mapper->map($result, new \Akzo\Scheme\ResultData());
     // Initialize the result arrays
     $collatedResult = $this->_initializeResult(array());
     // Add the code to this data
     $collatedResult['code'] = $code;
     $existingResult = $this->_initializeResult($existingResult);
     // Collate the results
     list($collatedResult['inBills'], $existingResult['inBills']) = $this->_collateOutputs($resultsData->inBills, $existingResult['inBills']);
     list($collatedResult['ppiOutputs'], $existingResult['ppiOutputs']) = $this->_collateOutputs($resultsData->ppiOutputs, $existingResult['ppiOutputs']);
     list($collatedResult['priOutputs'], $existingResult['priOutputs']) = $this->_collateOutputs($resultsData->priOutputs, $existingResult['priOutputs']);
     list($collatedResult['slabOutputs'], $existingResult['slabOutputs']) = $this->_collateOutputs($resultsData->slabOutputs, $existingResult['slabOutputs']);
     list($collatedResult['slabV2Outputs'], $existingResult['slabV2Outputs']) = $this->_collateOutputs($resultsData->slabV2Outputs, $existingResult['slabV2Outputs']);
     return array($collatedResult, $existingResult);
 }