1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\libraries\rest_api\calculations; |
4
|
|
|
|
5
|
|
|
use EventEspresso\core\domain\services\factories\FactoryInterface; |
6
|
|
|
use EventEspresso\core\exceptions\UnexpectedEntityException; |
7
|
|
|
use EventEspresso\core\services\loaders\LoaderInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class CalculatedModelFieldsFactory |
11
|
|
|
* |
12
|
|
|
* Loads classes for calculating fields for the REST API |
13
|
|
|
* |
14
|
|
|
* @package Event Espresso |
15
|
|
|
* @author Mike Nelson |
16
|
|
|
* @since $VID:$ |
17
|
|
|
* |
18
|
|
|
*/ |
19
|
|
|
class CalculatedModelFieldsFactory |
20
|
|
|
{ |
21
|
|
|
private $loader; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* CalculatedModelFieldsFactory constructor. |
25
|
|
|
* @param LoaderInterface $loader |
26
|
|
|
*/ |
27
|
|
|
public function __construct(LoaderInterface $loader) |
28
|
|
|
{ |
29
|
|
|
$this->loader = $loader; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates the calculator class that corresponds to that particular model |
34
|
|
|
* @since $VID:$ |
35
|
|
|
* @param string $model_name |
36
|
|
|
* @return Base |
37
|
|
|
* @throws UnexpectedEntityException |
38
|
|
|
*/ |
39
|
|
|
public function createFromModel($model_name) |
40
|
|
|
{ |
41
|
|
|
return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates the calculator class that corresponds to that classname and verifies it's of the correct type |
46
|
|
|
* @param string $calculator_classname |
47
|
|
|
* @return Base |
48
|
|
|
* @throws UnexpectedEntityException |
49
|
|
|
*/ |
50
|
|
|
public function createFromClassname($calculator_classname) |
51
|
|
|
{ |
52
|
|
|
$calculator = $this->loader->getShared($calculator_classname); |
53
|
|
|
if (!$calculator instanceof Base) { |
54
|
|
|
throw new UnexpectedEntityException( |
55
|
|
|
$calculator_classname, |
56
|
|
|
'EventEspresso\core\libraries\rest_api\calculations\Base' |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
return $calculator; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
// End of file CalculationsFactory.php |
63
|
|
|
// Location: EventEspresso\core\libraries\rest_api\calculations/CalculationsFactory.php |
64
|
|
|
|