Esempio n. 1
0
 public function test()
 {
     $Contact1 = Contact::initializeByObject(json_decode('{"phone_number":"111","first_name":"09 \\u041c\\u043e\\u0431.","last_name":"\\u041f\\u043e\\u0440\\u0442\\u0430\\u043b"}'));
     $this->assertInstanceOf(Contact::class, $Contact1);
     $this->assertEquals('111', $Contact1->getPhoneNumber());
     $this->assertEquals('09 Моб.', $Contact1->getFirstName());
     $this->assertEquals('Портал', $Contact1->getLastName());
     $this->assertEmpty($Contact1->getUserId());
     $Contact2 = Contact::initializeByObject(json_decode('{"phone_number":"111","first_name":"09 \\u041c\\u043e\\u0431.","last_name":"\\u041f\\u043e\\u0440\\u0442\\u0430\\u043b","user_id":12345}'));
     $this->assertInstanceOf(Contact::class, $Contact2);
     $this->assertEquals('111', $Contact2->getPhoneNumber());
     $this->assertEquals('09 Моб.', $Contact2->getFirstName());
     $this->assertEquals('Портал', $Contact2->getLastName());
     $this->assertEquals(12345, $Contact2->getUserId());
     $Contact3 = Contact::initializeByObject(json_decode('{"phone_number":"111"}'));
     $this->assertInstanceOf(Contact::class, $Contact3);
     $this->assertEquals('111', $Contact3->getPhoneNumber());
     $this->assertEmpty($Contact3->getFirstName());
     $this->assertEmpty($Contact3->getLastName());
     $this->assertEmpty($Contact3->getUserId());
     $Contact4 = Contact::initializeByObject(json_decode('{"phone_number":"111","first_name":"09 \\u041c\\u043e\\u0431."}'));
     $this->assertInstanceOf(Contact::class, $Contact4);
     $this->assertEquals('111', $Contact4->getPhoneNumber());
     $this->assertEquals('09 Моб.', $Contact4->getFirstName());
     $this->assertEmpty($Contact4->getLastName());
     $this->assertEmpty($Contact4->getUserId());
     $Contact5 = Contact::initializeByObject(json_decode('{"phone_number":"111","last_name":"\\u041f\\u043e\\u0440\\u0442\\u0430\\u043b"}'));
     $this->assertInstanceOf(Contact::class, $Contact5);
     $this->assertEquals('111', $Contact5->getPhoneNumber());
     $this->assertEmpty($Contact5->getFirstName());
     $this->assertEquals('Портал', $Contact5->getLastName());
     $this->assertEmpty($Contact5->getUserId());
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public static function initializeByObject(stdClass $Object)
 {
     $Contact = new Contact();
     $Contact->setPhoneNumber($Object->phone_number);
     if (isset($Object->first_name)) {
         $Contact->setFirstName($Object->first_name);
     }
     if (isset($Object->last_name)) {
         $Contact->setLastName($Object->last_name);
     }
     if (isset($Object->user_id)) {
         $Contact->setUserId($Object->user_id);
     }
     return $Contact;
 }
Esempio n. 3
0
 /**
  * @param stdClass $Object message data object
  * @return $this self instance
  */
 private function trySetContact(stdClass $Object)
 {
     if (isset($Object->contact)) {
         $this->Contact = Contact::initializeByObject($Object->contact);
     }
     return $this;
 }