コード例 #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
     $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());
コード例 #3
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()));
 }