1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\converters\spoofers; |
4
|
|
|
|
5
|
|
|
use EE_Error; |
6
|
|
|
use EEM_Base; |
7
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
8
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
9
|
|
|
use EventEspresso\core\exceptions\ModelConfigurationException; |
10
|
|
|
use EventEspresso\core\exceptions\RestPasswordIncorrectException; |
11
|
|
|
use EventEspresso\core\exceptions\RestPasswordRequiredException; |
12
|
|
|
use EventEspresso\core\exceptions\UnexpectedEntityException; |
13
|
|
|
use EventEspresso\core\libraries\rest_api\controllers\model\Read; |
14
|
|
|
use EventEspresso\core\libraries\rest_api\RestException; |
15
|
|
|
use InvalidArgumentException; |
16
|
|
|
use ReflectionException; |
17
|
|
|
use WP_REST_Request; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class RestApiSpoofer |
21
|
|
|
* Description |
22
|
|
|
* |
23
|
|
|
* @package EventEspresso\core\domain\services\converters\spoofers |
24
|
|
|
* @author Brent Christensen |
25
|
|
|
* @since $VID:$ |
26
|
|
|
*/ |
27
|
|
|
class RestApiSpoofer |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Read |
32
|
|
|
*/ |
33
|
|
|
protected $rest_api; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* RestApiSpoofer constructor. |
38
|
|
|
* |
39
|
|
|
* @param Read $rest_api |
40
|
|
|
* @param string $api_version |
41
|
|
|
*/ |
42
|
|
|
public function __construct(Read $rest_api, $api_version = '4.8.36') |
43
|
|
|
{ |
44
|
|
|
$this->rest_api = $rest_api; |
45
|
|
|
$this->rest_api->setRequestedVersion($api_version); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param EEM_Base $model |
51
|
|
|
* @param array $query_params |
52
|
|
|
* @param string $include |
53
|
|
|
* @return array |
54
|
|
|
* @throws EE_Error |
55
|
|
|
* @throws InvalidArgumentException |
56
|
|
|
* @throws InvalidDataTypeException |
57
|
|
|
* @throws InvalidInterfaceException |
58
|
|
|
* @throws ModelConfigurationException |
59
|
|
|
* @throws ReflectionException |
60
|
|
|
* @throws RestException |
61
|
|
|
* @throws RestPasswordIncorrectException |
62
|
|
|
* @throws RestPasswordRequiredException |
63
|
|
|
* @throws UnexpectedEntityException |
64
|
|
|
* @since $VID:$ |
65
|
|
|
*/ |
66
|
|
|
public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
67
|
|
|
{ |
68
|
|
|
/** @type array $results */ |
69
|
|
|
$results = $model->get_all_wpdb_results($query_params); |
70
|
|
|
$rest_request = new WP_REST_Request(); |
71
|
|
|
$rest_request->set_param('include', $include); |
72
|
|
|
$rest_request->set_param('caps', 'edit'); |
73
|
|
|
$nice_results = array(); |
74
|
|
|
foreach ($results as $result) { |
75
|
|
|
$nice_results[] = $this->rest_api->createEntityFromWpdbResult( |
76
|
|
|
$model, |
77
|
|
|
$result, |
78
|
|
|
$rest_request |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
return $nice_results; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |