<?php
/**
 * 客户接口
 */
class Default_CustomerApiController extends Zend_Controller_Action
{
    public function preDispatch(){
        $this->tplDirectory	= "default/views/default/";
        //关闭缓存
        ini_set("soap.wsdl_cache_enabled", "0");
    }
    public function indexAction () {
        $this->_forward('wsdl');
    }

    /**
     * [webServiceAction 注册服务]
     *
     * @return [type] [description]
     */
    public function webServiceAction () {
        $input = file_get_contents('php://input');
        if(!empty($input)){
            $server = new SoapServer(APPLICATION_PATH . "/../data/wsdl/ServiceForCustomer.wsdl");
            $server->setClass('Api_ServiceForCustomer');
            $server->handle();
        }else {
            echo 'Invalid SOAP request';
        }
        exit;
    }

    /**
     * [wsdlAction 读取WSDL]
     *
     * @return [type] [description]
     */
    public function wsdlAction () {
        $host = $this->_request->getHttpHost();
        //echo $host;exit;
        header("Content-type: text/xml; Charset=utf-8");
        $content = file_get_contents(APPLICATION_PATH . "/../data/wsdl/ServiceForCustomer.wsdl");
        $content = preg_replace('/exoms\.globex\.cn/', $host, $content);
        echo $content;
        exit();
    }

    /**
     * [wsdlFileAction description]
     *
     * @return [type] [description]
     */
    public function wsdlFileAction () {
        $host = $this->_request->getHttpHost();
        $content =  file_get_contents(APPLICATION_PATH . "/../data/wsdl/ServiceForCustomer.wsdl");
        $content = preg_replace('/exoms\.globex\.cn/', $host, $content);
        $fileName = preg_replace('/([a-zA-Z_0-9]+)\.([a-zA-Z_0-9]+)\.([a-zA-Z_0-9]+)/e', 'strtolower(\\1)', $host);
        $fileName = APPLICATION_PATH.'/../data/cache/'.$fileName.'-ServiceForCustomer.wsdl';
        if(!file_exists($fileName)){
            file_put_contents($fileName, $content);
        }
        Common_Common::downloadFile($fileName);
        exit;
    }

}
