Agreement.php 3.88 KB
<?php

/**
 * Created by PhpStorm.
 * User: Ziy
 * Date: 14/8/31
 * Time: 下午6:16
 */
class YHMIm_Agreement {

    /**
     * @param array $messageData
     * @return YHMIm_Agreement_Abstract
     */
    static function factory(array $messageData) {
        switch ($messageData['type']) {
            case 'yhm-text':
                $agreement = new YHMIm_Agreement_Base_Text();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-image':
                $agreement = new YHMIm_Agreement_Base_Images();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-product':
                $agreement = new YHMIm_Agreement_Product_Product();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-product-change-price':
                $agreement = new YHMIm_Agreement_Product_Change();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-order-info':
                $agreement = new YHMIm_Agreement_Order_Info();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-order-close':
                $agreement = new YHMIm_Agreement_Order_Close();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-product-reduce-price':
                $agreement = new YHMIm_Agreement_Product_ReducePrice();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-message-read':
                $agreement = new YHMIm_Agreement_Message_Reader();
                $agreement->setReaderData($messageData)->make();
                break;
            case 'yhm-order-status':
                $agreement = new YHMIm_Agreement_Order_Status();
                $agreement->setQueueData($messageData)->make();
                break;
            case 'yhm-order-complain':
                $agreement = new YHMIm_Agreement_Order_Complain();
                $agreement->setQueueData($messageData)->make();
                break;
             case 'yhm-product-txt':
                $agreement = new YHMIm_Agreement_Product_Txt();
                $agreement->setQueueData($messageData)->make();
                break;
            default:
                $agreement = new YHMIm_Agreement_Default();
                $agreement->setQueueData($messageData)->make();
                break;
        }
        return $agreement;
    }

    /**
     * 格式化输出
     * @param array $messageData
     * @return YHMIm_Agreement_Abstract
     */
    static function format(array $messageData, $uid) {
        switch ($messageData['type']) {
            case 'yhm-text':
                $agreement = new YHMIm_Agreement_Base_Text();
                break;
            case 'yhm-image':
                $agreement = new YHMIm_Agreement_Base_Images();
                break;
            case 'yhm-product':
                $agreement = new YHMIm_Agreement_Product_Info();
                break;
            case 'yhm-product-change-price':
                $agreement = new YHMIm_Agreement_Product_Change();
                break;
            case 'yhm-order-info':
                $agreement = new YHMIm_Agreement_Order_Info();
                break;
            case 'yhm-order-close':
                $agreement = new YHMIm_Agreement_Order_Close();
                break;
            case 'yhm-product-reduce-price':
                $agreement = new YHMIm_Agreement_Product_ReducePrice();
                break;
            case 'yhm-message-read':
                $agreement = new YHMIm_Agreement_Message_Reader();
                break;
            default:
                $agreement = new YHMIm_Agreement_Default();
                break;
        }
        return $agreement->setMongoData($messageData, $uid);
    }

}