<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 2017/8/1
 * Time: 下午3:06
 */

namespace ugc;


class category
{
    private $mCategories;
    private $mResult;

    private static $stInstance;
    private function __construct()
    {
        $i = 0;
        $data[$i++] = "生活";
        $data[$i++] = "投票";
        $data[$i++] = "问答";
        $data[$i++] = "护肤";
        $data[$i++] = "彩妆";
        $data[$i++] = "个护";
        $data[$i++] = "推荐";
        $data[$i++] = "晒货";
        $data[$i++] = "发现达人";
        $data[$i++] = "发现专家";
        $data[$i]   = "美妆教程";

        $this->mCategories = $data;
        $this->format();
    }

    public static function instance()
    {
        if(self::$stInstance == null) {
            self::$stInstance = new category();
        }
        return self::$stInstance;
    }
    private function format()
    {
        $result = [];
        foreach ($this->mCategories as $key => $val)
        {
            $item['category_id'] = $key;
            $item['title'] = $val;
            $result[] = $item;
        }
        $this->mResult = $result;
    }
    public function categories() {
        return $this->mResult;
    }

    public function title($category_id)
    {
        if(array_key_exists($category_id,$this->mCategories)) {
            return $this->mCategories[$category_id];
        } else {
            return '';
        }
    }
}