コード例 #1
0
ファイル: PersonAPIExample.php プロジェクト: sgoendoer/sonic
 public static function performGETPersonRequest($targetedGID)
 {
     // create an instance of PersonRequestBuilder
     $personRequest = new PersonRequestBuilder($targetedGID);
     // perform the request
     $response = $personRequest->createGETPerson()->dispatch();
     // to access contents of the response, use
     // $response->getPayload(); <-- the actual object data
     // $response->getResponseBody(); <-- the complete response body
     if ($response->getResponseStatusCode() != 200) {
         // in case the request returned something else thatn a 200
         throw new \Exception('Request failed with status code ' . $response->getResponseStatusCode());
     } else {
         // return the Person object from the responses payload
         return PersonObjectBuilder::buildFromJSON($response->getPayload());
     }
 }
コード例 #2
0
 public static function buildFromJSON($json)
 {
     // TODO parse and verify json
     $json = json_decode($json);
     $builder = new PersonObjectBuilder();
     $builder->objectID($json->objectID)->globalID($json->globalID)->displayName($json->displayName);
     if (property_exists($json, 'profilePicture')) {
         $builder->profilePicture($json->profilePicture);
     }
     if (property_exists($json, 'profilePictureThumbnail')) {
         $builder->profilePictureThumbnail($json->profilePictureThumbnail);
     }
     if (property_exists($json, 'language')) {
         $builder->language($json->language);
     }
     return $builder->build();
 }
コード例 #3
0
     $response = new ResponseBuilder(404);
     $response->init('Unknown GlobalID: ' . $targetedGID);
     $response->dispatch();
     die;
 }
 // check access permissions for the addressed interface
 if (!Sonic::getAccessControlManager()->hasInterfaceAccessPriviledges($request->getHeaderSourceGID(), $resource, $request->getMethod())) {
     throw new AccessControlException();
 }
 switch (strtolower($resource)) {
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // resource PERSON
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     case 'person':
         if ($request->getMethod() == 'GET') {
             $personObject = PersonObjectBuilder::buildFromJSON(file_get_contents(__DIR__ . '/data/AlicePerson.json'));
             // check access permissions for the content object
             if (!Sonic::getAccessControlManager()->hasContentAccessPriviledges($request->getHeaderSourceGID(), $personObject->getObjectID())) {
                 throw new AccessControlException();
             }
             $response = new ResponseBuilder(200);
             $response->init()->setBody($personObject->getJSON());
             $response->dispatch();
         } else {
             throw new MethodNotAllowedException();
         }
         break;
     case 'like':
         if ($request->getMethod() == 'POST') {
             // building LIKE object from request body data
             $likeObject = LikeObjectBuilder::buildFromJSON($request->getBody());
コード例 #4
0
ファイル: ModelUnitTest.php プロジェクト: sgoendoer/sonic
 public function testPerson()
 {
     $person = (new PersonObjectBuilder())->objectID(UOID::createUOID())->globalID(Sonic::getContextGlobalID())->displayName($this->aliceSocialRecord->getDisplayName())->build();
     $this->assertTrue($person->validate());
     $this->assertEquals($person, PersonObjectBuilder::buildFromJSON($person->getJSONString()));
 }