86 lines
No EOL
1.6 KiB
PHP
86 lines
No EOL
1.6 KiB
PHP
<?php
|
|
|
|
class BlogPost
|
|
{
|
|
|
|
protected $_title;
|
|
protected $_content;
|
|
protected $_author;
|
|
protected $_pubDate;
|
|
protected $_isPublished = false;
|
|
|
|
|
|
public function setTitle($title)
|
|
{
|
|
if (is_string($title) && null == $title[30]) {
|
|
|
|
$this->_title = $title;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public function setContent($content)
|
|
{
|
|
if (is_string($content)) {
|
|
|
|
$this->_content = $content;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public function setAuthor($author)
|
|
{
|
|
if ($author instanceof User) {
|
|
|
|
$this->_author = $author;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public function setPubDate($date)
|
|
{
|
|
if (is_string($date) && preg_match('/^(?:(?:19[0-9]{2})|(?:20[0-9]{2}))\-' .
|
|
'(?:(?:0[1-9])|(?:1[012]))\-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/', $date)) {
|
|
|
|
$this->_pubDate = $date;
|
|
} else if ($date instanceof Zend_Date) {
|
|
|
|
$this->_pubDate = $date->toString('yyyy-MM-dd');
|
|
} else {
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public function isPublished($flag = null)
|
|
{
|
|
if (null === $flag) {
|
|
return $this->_isPublished;
|
|
}
|
|
|
|
$this->_isPublished = (boolean)$flag;
|
|
}
|
|
|
|
public function __call($name,$args) {
|
|
|
|
// getX methods
|
|
if ('get' == substr($name,0,3)) {
|
|
$dataPart = '_'.lcfirst(substr($name,3));
|
|
if (isset($this->$dataPart))
|
|
return $this->$dataPart;
|
|
}
|
|
|
|
}
|
|
} |