forked from Payum/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiAwareTrait.php
37 lines (31 loc) · 994 Bytes
/
ApiAwareTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Payum\Core;
use Payum\Core\Exception\LogicException;
use Payum\Core\Exception\UnsupportedApiException;
trait ApiAwareTrait
{
/**
* @var mixed
*/
protected $api;
/**
* @var string
*/
protected $apiClass;
/**
* {@inheritDoc}
*/
public function setApi($api)
{
if (empty($this->apiClass)) {
throw new LogicException(sprintf('You must configure apiClass in __constructor method of the class the trait is applied to.'));
}
if (false == (class_exists($this->apiClass) || interface_exists($this->apiClass))) {
throw new LogicException(sprintf('Api class not found or invalid class. "%s", $this->apiClass', $this->apiClass));
}
if (false == $api instanceof $this->apiClass) {
throw new UnsupportedApiException(sprintf('Not supported api given. It must be an instance of %s', $this->apiClass));
}
$this->api = $api;
}
}