예제 #1
0
 /**
  * @test
  */
 public function itShouldSerializeWithLegalObject()
 {
     $this->givenSerializerWillSerializeIndices();
     $serialized = $this->serviceUnderTest->serialize($this->getValidObject());
     $this->assertEquals($this->text, $serialized->text);
     $this->assertEquals($this->indicesObj, $serialized->indices);
 }
 /**
  * @param  TwitterSerializable $object
  * @return \stdClass
  */
 public function serialize(TwitterSerializable $object)
 {
     /* @var TwitterEntities $object */
     Assertion::true($this->canSerialize($object), 'object must be an instance of TwitterEntities');
     $entities = new \stdClass();
     // Hashtags
     if ($object->getHashtags()) {
         $entities->hashtags = [];
         foreach ($object->getHashtags() as $hashtag) {
             $entities->hashtags[] = $this->hashtagSerializer->serialize($hashtag);
         }
     }
     // Symbols
     if ($object->getSymbols()) {
         $entities->symbols = [];
         foreach ($object->getSymbols() as $symbol) {
             $entities->symbols[] = $this->symbolSerializer->serialize($symbol);
         }
     }
     // Urls
     if ($object->getUrls()) {
         $entities->urls = [];
         foreach ($object->getUrls() as $url) {
             $entities->urls[] = $this->urlSerializer->serialize($url);
         }
     }
     // User mentions
     if ($object->getUserMentions()) {
         $entities->user_mentions = [];
         foreach ($object->getUserMentions() as $userMention) {
             $entities->user_mentions[] = $this->userMentionSerializer->serialize($userMention);
         }
     }
     // Media
     if ($object->getMedia()) {
         $entities->media = [];
         foreach ($object->getMedia() as $media) {
             $entities->media[] = $this->mediaSerializer->serialize($media);
         }
     }
     // Extended entities
     if ($object->getExtendedEntities()) {
         $entities->extended_entities = [];
         foreach ($object->getExtendedEntities() as $extendedEntity) {
             $entities->extended_entities[] = $this->extendedEntitySerializer->serialize($extendedEntity);
         }
     }
     return $entities;
 }