Repository navigation
Expand file tree
/
Copy pathApiAwareTrait.php
More file actions
48 lines (39 loc) · 1.72 KB
/
Copy pathApiAwareTrait.php
File metadata and controls
48 lines (39 loc) · 1.72 KB
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
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Payum\Core;
use Payum\Core\Exception\LogicException;
use Payum\Core\Exception\UnsupportedApiException;
use function is_object;
use function trigger_deprecation;
trigger_deprecation('payum/core', '2.0.0', 'The %s is deprecated and will be removed in 3.0. Take the api as a constructor argument instead, and let the container inject it.', ApiAwareTrait::class);
/**
* @deprecated since 2.0.0, will be removed in 3.0. Take the api as a constructor argument instead, and
* let the container inject it.
*/
trait ApiAwareTrait
{
/**
* @var mixed
* @deprecated since 2.0.0, will be removed in 3.0. Take the api as a constructor argument instead.
*/
protected $api;
/**
* @deprecated since 2.0.0, will be removed in 3.0. Take the api as a constructor argument instead.
*/
protected string|object|null $apiClass;
/**
* @deprecated since 2.0.0, will be removed in 3.0. Take the api as a constructor argument instead.
*/
public function setApi($api): void
{
if (empty($this->apiClass)) {
throw new LogicException('You must configure apiClass in __constructor method of the class the trait is applied to.');
}
if (is_string($this->apiClass) && ! (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 (! $api instanceof $this->apiClass) {
throw new UnsupportedApiException(sprintf('Not supported api given. It must be an instance of %s', is_object($this->apiClass) ? $this->apiClass::class : $this->apiClass));
}
$this->api = $api;
}
}