-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathApi.php
More file actions
84 lines (74 loc) · 2.02 KB
/
Api.php
File metadata and controls
84 lines (74 loc) · 2.02 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Executor;
/**
* This helper allows you to use Api classes in the namespace
* ProcessMaker\Client\Api\ by calling its name as a function
* on an instance of this class. The class name is lowercase first.
*
* For example, to call \ProcessMaker\Client\Api\ProcessesApi
* call $api->processes()
*/
class Api
{
/**
* Reusable instances of api objects
*
* @var array
*/
private $instances = [];
/**
* Instance of the Guzzle client
*
* @var \GuzzleHttp\Client
*/
private $client;
/**
* Instance of the client configuration object
*
* @var \ProcessMaker\Client\Configuration
*/
private $config;
/**
* Constructor
*
* @param \ProcessMaker\Client\Configuration $config
* @param bool $ssl_verify
*/
public function __construct($config, $ssl_verify)
{
$this->client = new \GuzzleHttp\Client(['verify' => $ssl_verify]);
$this->config = $config;
}
/**
* Method to catch all undefined methods
*
* @param string $name
* @param array $arguments
* @return object
*/
public function __call($name, $arguments)
{
if (count($arguments) > 0) {
throw new \BadMethodCallException('Arguments should not be passed');
}
$class_name = $this->getClassName($name);
if (array_key_exists($class_name, $this->instances)) {
return $this->instances[$class_name];
} elseif (class_exists($this->getClassName($name))) {
$this->instances[$class_name] = new $class_name($this->client, $this->config);
return $this->instances[$class_name];
} else {
throw new \BadMethodCallException("class $class_name does not exist");
}
}
/**
* Translate the called name to a real class
*
* @param string $name
* @return string
*/
private function getClassName($name)
{
return '\\ProcessMaker\\Client\Api\\' . ucfirst($name) . 'Api';
}
}