PFinal\Wechat\Message\News::__construct PHP Method

__construct() public method

$news1 = new News('文章标题', '描述', 'url', 'image') $news2 = new News($arr) $news3 = new News([$arr,$arr]) $news4 = new News([$news1,$news2])
public __construct ( string $title = '', string $description = '', string $url = '', string $picUrl = '' )
$title string
$description string
$url string
$picUrl string
    public function __construct($title = '', $description = '', $url = '', $picUrl = '')
    {
        if (is_array($title)) {
            $articles = $title;
            if (array_keys($articles) !== range(0, count($articles) - 1)) {
                //第一个参是关联数组
                $articles = array($articles);
            } else {
                //第一个参是索引数组
                foreach ($articles as $key => $item) {
                    if ($item instanceof News) {
                        $articles[$key] = $item->toArray();
                    } else {
                        $articles[$key] = (array) $item;
                    }
                }
            }
        } else {
            //第一个参数不是数组
            $articles = array(compact(array('title', 'description', 'url', 'picUrl')));
        }
        //将key的首字母转为大写(微信Xml格式首字大写)
        foreach ($articles as $key => $value) {
            $temp = array();
            foreach ($value as $k => $v) {
                $temp[ucfirst($k)] = $v;
            }
            $articles[$key] = $temp;
        }
        $this->attributes = array('ArticleCount' => count($articles), 'Articles' => $articles);
    }