Channel.php 1.33 KB
<?php

namespace WebPlugin\DataProcess;

use WebPlugin\Helpers;
class Channel
{

    public static $formatChannel = array(
        'boys' => '\WebPlugin\DataProcess\Channel\Boys',
        'girls' => '\WebPlugin\DataProcess\Channel\Girls',
        'kids' => '\WebPlugin\DataProcess\Channel\Kids',
        'lifestyle' => '\WebPlugin\DataProcess\Channel\Lifestyle',
        'plusstarIndex' => '\WebPlugin\DataProcess\Channel\PlusstarIndex'
    );
    
    /**
     * 获取格式数据
     * 
     * @param string $channel
     * @param array $data
     */
    public static function getFormat($channel, array $data)
    {
        if (empty($data)) {
            return array();
        }
        $type = '';
        if(in_array($channel, array('boys','girls','kids','lifestyle'))){
            $type = $channel;
        } else {
            $type = Helpers::getChannelNameByCookie();
        }
        // 通用处理器
        $result = Process::getContent($data, $type);
        $channelResult = array();
        if (isset(self::$formatChannel[$channel])) {
            $class = self::$formatChannel[$channel];
            $channelResult = $class::format($data);
        }
        // 组合数据
        $result = $result + $channelResult;
        ksort($result);
        return array_values($result);
    }

}