|
1
|
|
|
<?php |
|
2
|
|
|
namespace EventEspresso\core\libraries\rest_api\controllers\model; |
|
3
|
|
|
use EventEspresso\core\libraries\rest_api\controllers\Base as Controller_Base; |
|
4
|
|
|
use EventEspresso\core\libraries\rest_api\Model_Version_Info; |
|
5
|
|
|
|
|
6
|
|
|
if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7
|
|
|
exit( 'No direct script access allowed' ); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* Base |
|
13
|
|
|
* |
|
14
|
|
|
* Base controller which also has something to do with models |
|
15
|
|
|
* |
|
16
|
|
|
* @package Event Espresso |
|
17
|
|
|
* @subpackage |
|
18
|
|
|
* @author Mike Nelson |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
class Base extends Controller_Base { |
|
22
|
|
|
/** |
|
23
|
|
|
* Holds reference to the model version info, which knows the requested version |
|
24
|
|
|
* @var Model_Version_Info |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $_model_version_info; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Sets the version the user requested |
|
30
|
|
|
* @param string $version eg '4.8' |
|
31
|
|
|
*/ |
|
32
|
|
|
public function set_requested_version( $version ) { |
|
33
|
|
|
parent::set_requested_version( $version ); |
|
34
|
|
|
$this->_model_version_info = new Model_Version_Info( $version ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Gets the object that should be used for getting any info from the models, |
|
41
|
|
|
* because it's takes the requested and current core version into account |
|
42
|
|
|
* |
|
43
|
|
|
* @return \EventEspresso\core\libraries\rest_api\Model_Version_Info |
|
44
|
|
|
* @throws \EE_Error |
|
45
|
|
|
*/ |
|
46
|
|
|
public function get_model_version_info(){ |
|
47
|
|
|
if( ! $this->_model_version_info ) { |
|
48
|
|
|
throw new \EE_Error( |
|
49
|
|
|
sprintf( |
|
50
|
|
|
__( |
|
51
|
|
|
'Cannot use model version info before setting the requested version in the controller', |
|
52
|
|
|
'event_espresso' |
|
53
|
|
|
) |
|
54
|
|
|
) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
return $this->_model_version_info; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Determines if $object is of one of the classes of $classes. Similar to |
|
62
|
|
|
* in_array(), except this checks if $object is a subclass of the classnames provided |
|
63
|
|
|
* in $classnames |
|
64
|
|
|
* |
|
65
|
|
|
* @param object $object |
|
66
|
|
|
* @param array $classnames |
|
67
|
|
|
* @return boolean |
|
68
|
|
|
*/ |
|
69
|
|
|
public function is_subclass_of_one( $object, $classnames ) { |
|
70
|
|
|
foreach( $classnames as $classname ) { |
|
71
|
|
|
if( is_a( $object, $classname ) ) { |
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
return false; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// End of file Base.php |