Skip to content

Instantly share code, notes, and snippets.

@jmoz
Created May 16, 2011 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmoz/974602 to your computer and use it in GitHub Desktop.
Save jmoz/974602 to your computer and use it in GitHub Desktop.
Client refactored 1
<?php
class ServiceClient {
private $service;
private $http;
private $logger;
public function __construct(Service $service, Http $http, sfLogger $logger) {
$this->service = $service;
$this->http = $http;
$this->logger = $logger;
}
public function getService() {
return $this->service;
}
public function setService(Service $service) {
$this->service = $service;
}
public function call() {
$this->logger->info("Calling service " . get_class($this->service) . " with url {$this->service->getUrl()}");
$this->http->setUrl($this->service->getUrl());
$this->http->setMethod($this->service->getMethod());
$this->http->setBody($this->service->getBody());
$this->http->send();
return $this->http->getResponseBody();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment