Skip to content

Commit cf674c7

Browse files
committed
Merge pull request #26 from delatbabel/master
Add some more documentation
2 parents e4c54a3 + 5eb7e59 commit cf674c7

13 files changed

+1130
-8
lines changed

src/Omnipay/Common/AbstractGateway.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@
1717
* throughout the Omnipay system. It enforces implementation of
1818
* the GatewayInterface interface and defines various common attibutes
1919
* and methods that all gateways should have.
20+
*
21+
* Example:
22+
*
23+
* <code>
24+
* // Initialise the gateway
25+
* $gateway->initialize(...);
26+
*
27+
* // Get the gateway parameters.
28+
* $parameters = $gateway->getParameters();
29+
*
30+
* // Create a credit card object
31+
* $card = new CreditCard(...);
32+
*
33+
* // Do an authorisation transaction on the gateway
34+
* if ($gateway->supportsAuthorize()) {
35+
* $gateway->authorize(...);
36+
* } else {
37+
* throw new \Exception('Gateway does not support authorize()');
38+
* }
39+
* </code>
40+
*
41+
* For further code examples see the *omnipay-example* repository on github.
42+
*
43+
* @see GatewayInterface
2044
*/
2145
abstract class AbstractGateway implements GatewayInterface
2246
{
@@ -214,7 +238,34 @@ public function supportsUpdateCard()
214238
}
215239

216240
/**
217-
* Create and initialize a request object using existing parameters from this gateway
241+
* Create and initialize a request object
242+
*
243+
* This function is usually used to create objects of type
244+
* Omnipay\Common\Message\AbstractRequest (or a non-abstract subclass of it)
245+
* and initialise them with using existing parameters from this gateway.
246+
*
247+
* Example:
248+
*
249+
* <code>
250+
* class MyRequest extends \Omnipay\Common\Message\AbstractRequest {};
251+
*
252+
* class MyGateway extends \Omnipay\Common\AbstractGateway {
253+
* function myRequest($parameters) {
254+
* $this->createRequest('MyRequest', $parameters);
255+
* }
256+
* }
257+
*
258+
* // Create the gateway object
259+
* $gw = Omnipay::create('MyGateway');
260+
*
261+
* // Create the request object
262+
* $myRequest = $gw->myRequest($someParameters);
263+
* </code>
264+
*
265+
* @see \Omnipay\Common\Message\AbstractRequest
266+
* @param string $class The request class name
267+
* @param array $parameters
268+
* @return \Omnipay\Common\Message\AbstractRequest
218269
*/
219270
protected function createRequest($class, array $parameters)
220271
{
@@ -223,6 +274,11 @@ protected function createRequest($class, array $parameters)
223274
return $obj->initialize(array_replace($this->getParameters(), $parameters));
224275
}
225276

277+
/**
278+
* Get the global default HTTP client.
279+
*
280+
* @return HttpClient
281+
*/
226282
protected function getDefaultHttpClient()
227283
{
228284
return new HttpClient(
@@ -233,6 +289,11 @@ protected function getDefaultHttpClient()
233289
);
234290
}
235291

292+
/**
293+
* Get the global default HTTP request.
294+
*
295+
* @return HttpRequest
296+
*/
236297
protected function getDefaultHttpRequest()
237298
{
238299
return HttpRequest::createFromGlobals();

0 commit comments

Comments
 (0)