<?php
/**
 * Created by PhpStorm.
 * User: srecko
 * Date: 3.5.2017.
 * Time: 12:42
 */

namespace AuthStack\Driver\SOAP\Lib;


class SoapClient extends \SoapClient
{
    protected $logCallback;

    public function setLogMethod($callable)
    {
        $this->logCallback = $callable;
    }

    /**
     * @param string $message
     * @param int $level
     */
    public function log( $message, $level = 4 )
    {
        if ( is_callable( $this->logCallback ) )
        {
            call_user_func( $this->logCallback,$message, $level );
        }
    }

    /**
     * Performs a SOAP request
     * @link http://php.net/manual/en/soapclient.dorequest.php
     * @param string $request  The XML SOAP request.
     * @param string $location The URL to request.
     * @param string $action   The SOAP action.
     * @param int    $version  The SOAP version.
     * @param int    $one_way  [optional] If one_way is set to 1, this method returns nothing. Use this where a response is not expected.
     * @return string The XML SOAP response.
     * @since 5.0.1
     */
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $this->log('SOAP Request');
        $this->log( $request );
        $this->log( $location );
        $this->log( $action );
        $this->log( $version );
        $this->log( $one_way );

        $response = parent::__doRequest($request, $location, $action, $version, $one_way);

        $this->log('SOAP Response');
        $this->log( $response );

        return $response;
    }


}