Last active
October 9, 2019 02:31
-
-
Save JWPapi/a0cfc840bf0c1dcb84616c64b158e785 to your computer and use it in GitHub Desktop.
DTO in Symfony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getUserInfo($igAccountName) | |
{ | |
$normalizers = [new ObjectNormalizer()]; | |
$encoders = [new JsonEncoder()]; | |
$serializer = new Serializer($normalizers, $encoders); | |
$ig = new Instagram(); | |
$ig->login('lifestyledotcool', 'Milano91!'); | |
$userId = $ig->people->getUserIdForName($igAccountName); | |
$igUser = $ig->people->getInfoById($userId)->getUser(); | |
$this->logger->info(json_encode($igUser)); | |
$userDto = $serializer->deserialize($igUser, igUserInfoModel::class, 'json'); | |
return $userDto; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model; | |
class igUserInfoModel { | |
public $username; | |
public $status; | |
public $following_count; | |
public $follower_count; | |
public $media_count; | |
public $storiesWatched; | |
public $profile_pic_url; | |
public $biography; | |
public $full_name; | |
public $is_private; | |
public $has_anonymous_profile_picture; | |
public function getOptimizationTips(){ | |
$resultArr = []; | |
if ($this->is_private){ | |
array_push($resultArr, | |
[ | |
'level' => 3, | |
'message' => 'We strongly suggest to keep your account public. Your account will be exposed to real | |
users. The more convincing your profile is, the more followers you‘ll get.' | |
]); | |
} | |
if ($this->has_anonymous_profile_picture) { | |
array_push($resultArr, | |
[ | |
'level' => 3, | |
'message' => 'You should add a profile picture to your account. The more vivid your account is, the more follower you‘ll get.' | |
]); | |
} | |
return $resultArr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment