Last active
August 14, 2017 16:01
-
-
Save joeainsworth/21ca1c039af2540ac0b4c008f27e7705 to your computer and use it in GitHub Desktop.
Example
This file contains hidden or 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 Aiir\SocialPublisher; | |
class FacebookPost extends Post | |
{ | |
public function publish() | |
{ | |
// Specific implementation to publish post to Facebook | |
} | |
public function unpublish() | |
{ | |
// Specific implementation to delete post from Facebook | |
} | |
} |
This file contains hidden or 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 | |
$db = new Database(); | |
$manager = new SocialPublisherDAO($db); | |
$post = $manager->createPost([ | |
'type' => 'FacebookPost', | |
'message' => 'Testing', | |
'draft' => true, | |
'scheduled_dt' => '2017-14-10 12:00:00', | |
'created_user_id' => $myInfo['userId'], | |
'created_dt' => dateUTCtoLocal('Y-m-d H:i:s'), | |
'modified_user_id' => $myInfo['userId'], | |
'modified_dt' => dateUTCtoLocal('Y-m-d H:i:s'), | |
]); | |
$post->setMessage('New message text'); | |
$post->setDraft(false); | |
$post->setModifiedUserId($myInfo['userId']); | |
$post->setModifiedDt(dateUTCtoLocal('Y-m-d H:i:s')); | |
$manager->updatePost($post); |
This file contains hidden or 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 Aiir\SocialPublisher; | |
abstract class Post | |
{ | |
private $id; | |
private $message; | |
private $draft; | |
private $scheduledDt; | |
private $createdUserId; | |
private $createdDt; | |
private $modifiedUserId; | |
private $modifiedDt; | |
public function __construct($data) | |
{ | |
$this->id = $data['id']; | |
$this->message = $data['message']; | |
$this->draft = $data['draft']; | |
$this->scheduledDt = $data['scheduled_dt']; | |
$this->createdUserId = $data['created_user_id']; | |
$this->createdDt = $data['created_dt']; | |
$this->modifiedUserId = $data['modified_user_id']; | |
$this->modifiedDt = $data['modified_dt']; | |
} | |
abstract public function publish(); | |
abstract public function unpublish(); | |
abstract public function delete(); | |
public function setMessage($message) | |
{ | |
$this->message = (string) $message; | |
} | |
public function getMessage() | |
{ | |
return $this->message; | |
} | |
public function setDraft($draft) | |
{ | |
$this->draft = (bool) $draft; | |
} | |
public function getDraft() | |
{ | |
return $this->draft; | |
} | |
public function setScheduledDt(DateTime $date) | |
{ | |
$this->scheduledDt = $date; | |
} | |
public function getScheduledDt() | |
{ | |
return $this->scheduledDt; | |
} | |
public function setCreatedUserId($id) | |
{ | |
$this->createdUserId = (int) $id; | |
} | |
public function getCreatedUserID() | |
{ | |
return $this->createdUserId; | |
} | |
public function setCreatedDt(DateTime $date) | |
{ | |
$this->createdDt = $date; | |
} | |
public function getCreatedDt() | |
{ | |
return $this->createdDt; | |
} | |
public function getModifiedUserId() | |
{ | |
return $this->modifiedUserId; | |
} | |
public function setModifiedUserId($id) | |
{ | |
$this->modifiedUserId = (int) $id; | |
} | |
public function setModifiedDt($date) | |
{ | |
$this->modifiedDt = $date; | |
} | |
public function getModifiedDt() | |
{ | |
return $this->modifiedDt; | |
} | |
} |
This file contains hidden or 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 Aiir\SocialPublisher; | |
class TwitterPost extends Post | |
{ | |
public function publish() | |
{ | |
// Specific implementation to publish post to Twitter | |
} | |
public function unpublish() | |
{ | |
// Specific implementation to delete post from Twitter | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment