Skip to content

Commit

Permalink
Merge pull request #3 from janvernieuwe/event-expose-client
Browse files Browse the repository at this point in the history
Expose client in Events
  • Loading branch information
veewee committed Oct 5, 2015
2 parents 8fa2314 + df99d31 commit d97c910
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 17 deletions.
10 changes: 8 additions & 2 deletions spec/Phpro/SoapClient/Event/FaultEventSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace spec\Phpro\SoapClient\Event;

use Phpro\SoapClient\Client;
use Phpro\SoapClient\Event\FaultEvent;
use Phpro\SoapClient\Event\RequestEvent;
use PhpSpec\ObjectBehavior;
Expand All @@ -10,9 +11,9 @@

class FaultEventSpec extends ObjectBehavior
{
function let(\SoapFault $soapFault, RequestEvent $requestEvent)
function let(Client $client,\SoapFault $soapFault, RequestEvent $requestEvent)
{
$this->beConstructedWith($soapFault, $requestEvent);
$this->beConstructedWith($client, $soapFault, $requestEvent);
}

function it_is_initializable()
Expand All @@ -34,4 +35,9 @@ function it_should_know_the_fault(\SoapFault $soapFault)
{
$this->getSoapFault()->shouldReturn($soapFault);
}

function it_should_know_the_client(Client $client)
{
$this->getClient()->shouldReturn($client);
}
}
10 changes: 8 additions & 2 deletions spec/Phpro/SoapClient/Event/RequestEventSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace spec\Phpro\SoapClient\Event;

use Phpro\SoapClient\Client;
use Phpro\SoapClient\Type\RequestInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\Event;

class RequestEventSpec extends ObjectBehavior
{
function let(RequestInterface $request)
function let(Client $client, RequestInterface $request)
{
$this->beConstructedWith('method', $request);
$this->beConstructedWith($client, 'method', $request);
}

function it_is_initializable()
Expand All @@ -33,4 +34,9 @@ function it_should_know_the_request(RequestInterface $request)
{
$this->getRequest()->shouldReturn($request);
}

function it_should_know_the_client(Client $client)
{
$this->getClient()->shouldReturn($client);
}
}
5 changes: 3 additions & 2 deletions spec/Phpro/SoapClient/Event/ResponseEventSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace spec\Phpro\SoapClient\Event;

use Phpro\SoapClient\Client;
use Phpro\SoapClient\Event\RequestEvent;
use Phpro\SoapClient\Event\ResponseEvent;
use Phpro\SoapClient\Type\ResultInterface;
Expand All @@ -11,9 +12,9 @@

class ResponseEventSpec extends ObjectBehavior
{
function let(RequestEvent $requestEvent, ResultInterface $response)
function let(Client $client, RequestEvent $requestEvent, ResultInterface $response)
{
$this->beConstructedWith($requestEvent, $response);
$this->beConstructedWith($client, $requestEvent, $response);
}

function it_is_initializable()
Expand Down
6 changes: 3 additions & 3 deletions src/Phpro/SoapClient/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function changeSoapLocation($location)
*/
protected function call($method, RequestInterface $request)
{
$requestEvent = new Event\RequestEvent($method, $request);
$requestEvent = new Event\RequestEvent($this, $method, $request);
$this->dispatcher->dispatch(Events::REQUEST, $requestEvent);

try {
Expand All @@ -93,11 +93,11 @@ protected function call($method, RequestInterface $request)
$result = $result->getResult();
}
} catch (SoapFault $soapFault) {
$this->dispatcher->dispatch(Events::FAULT, new Event\FaultEvent($soapFault, $requestEvent));
$this->dispatcher->dispatch(Events::FAULT, new Event\FaultEvent($this, $soapFault, $requestEvent));
throw $soapFault;
}

$this->dispatcher->dispatch(Events::RESPONSE, new Event\ResponseEvent($requestEvent, $result));
$this->dispatcher->dispatch(Events::RESPONSE, new Event\ResponseEvent($this, $requestEvent, $result));
return $result;
}
}
22 changes: 19 additions & 3 deletions src/Phpro/SoapClient/Event/FaultEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Phpro\SoapClient\Event;

use Phpro\SoapClient\Client;
use SoapFault;
use Symfony\Component\EventDispatcher\Event;

Expand All @@ -24,11 +25,18 @@ class FaultEvent extends Event
protected $requestEvent;

/**
* @param SoapFault $soapFault
* @var Client
*/
protected $client;

/**
* @param Client $client
* @param SoapFault $soapFault
* @param RequestEvent $requestEvent
*/
public function __construct(SoapFault $soapFault, RequestEvent $requestEvent)
public function __construct(Client $client, SoapFault $soapFault, RequestEvent $requestEvent)
{
$this->client = $client;
$this->soapFault = $soapFault;
$this->requestEvent = $requestEvent;
}
Expand All @@ -48,4 +56,12 @@ public function getRequestEvent()
{
return $this->requestEvent;
}
}

/**
* @return Client
*/
public function getClient()
{
return $this->client;
}
}
21 changes: 18 additions & 3 deletions src/Phpro/SoapClient/Event/RequestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Phpro\SoapClient\Event;

use Phpro\SoapClient\Client;
use Phpro\SoapClient\Type\RequestInterface;
use Symfony\Component\EventDispatcher\Event;

Expand All @@ -17,17 +18,24 @@ class RequestEvent extends Event
*/
protected $method;

/**
* @var Client
*/
protected $client;

/**
* @var RequestInterface
*/
private $request;

/**
* @param string $method
* @param Client $client
* @param string $method
* @param RequestInterface $request
*/
public function __construct($method, RequestInterface $request)
public function __construct(Client $client, $method, RequestInterface $request)
{
$this->client = $client;
$this->method = $method;
$this->request = $request;
}
Expand All @@ -47,5 +55,12 @@ public function getRequest()
{
return $this->request;
}
}

/**
* @return Client
*/
public function getClient()
{
return $this->client;
}
}
19 changes: 17 additions & 2 deletions src/Phpro/SoapClient/Event/ResponseEvent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Phpro\SoapClient\Event;

use Phpro\SoapClient\Client;
use Phpro\SoapClient\Type\ResultInterface;
use Symfony\Component\EventDispatcher\Event;

Expand All @@ -22,11 +23,18 @@ class ResponseEvent extends Event
protected $response;

/**
* @var Client
*/
protected $client;

/**
* @param Client $client
* @param RequestEvent $requestEvent
* @param ResultInterface $response
*/
public function __construct(RequestEvent $requestEvent, ResultInterface $response)
public function __construct(Client $client, RequestEvent $requestEvent, ResultInterface $response)
{
$this->client = $client;
$this->requestEvent = $requestEvent;
$this->response = $response;
}
Expand All @@ -46,5 +54,12 @@ public function getResponse()
{
return $this->response;
}
}

/**
* @return Client
*/
public function getClient()
{
return $this->client;
}
}

0 comments on commit d97c910

Please sign in to comment.