Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
30.56% |
11 / 36 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| tao_models_classes_service_Parameter | |
30.56% |
11 / 36 |
|
50.00% |
2 / 4 |
29.43 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDefinition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toOntology | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| jsonSerialize | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| fromJson | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| fromResource | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\tao\model\WfEngineOntology; |
| 23 | use oat\generis\model\data\Ontology; |
| 24 | |
| 25 | /** |
| 26 | * Represents tao service parameter |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Joel Bout, <joel@taotesting.com> |
| 30 | * @package tao |
| 31 | * phpcs:disable Squiz.Classes.ValidClassName |
| 32 | */ |
| 33 | abstract class tao_models_classes_service_Parameter implements JsonSerializable |
| 34 | { |
| 35 | /** |
| 36 | * @var core_kernel_classes_Resource |
| 37 | */ |
| 38 | private $definition; |
| 39 | |
| 40 | /** |
| 41 | * Base constructor of abstract parameter |
| 42 | * |
| 43 | * @param core_kernel_classes_Resource $definition |
| 44 | */ |
| 45 | public function __construct(core_kernel_classes_Resource $definition) |
| 46 | { |
| 47 | $this->definition = $definition; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the formal definition of this parameter |
| 52 | * |
| 53 | * @return core_kernel_classes_Resource |
| 54 | */ |
| 55 | public function getDefinition() |
| 56 | { |
| 57 | return $this->definition; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return core_kernel_classes_Resource |
| 62 | */ |
| 63 | abstract public function toOntology(Ontology $model); |
| 64 | |
| 65 | abstract public function jsonSerialize(); |
| 66 | |
| 67 | public static function fromJson($data) |
| 68 | { |
| 69 | if (isset($data['const'])) { |
| 70 | $param = new tao_models_classes_service_ConstantParameter( |
| 71 | new core_kernel_classes_Resource($data['def']), |
| 72 | $data['const'] |
| 73 | ); |
| 74 | } else { |
| 75 | $param = new tao_models_classes_service_VariableParameter( |
| 76 | new core_kernel_classes_Resource($data['def']), |
| 77 | new core_kernel_classes_Resource($data['proc']) |
| 78 | ); |
| 79 | } |
| 80 | return $param; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Builds a service call parameter from it's serialized form |
| 85 | * |
| 86 | * @param core_kernel_classes_Resource $resource |
| 87 | * @return tao_models_classes_service_Parameter |
| 88 | */ |
| 89 | public static function fromResource(core_kernel_classes_Resource $resource) |
| 90 | { |
| 91 | $values = $resource->getPropertiesValues([ |
| 92 | WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_FORMAL_PARAMETER, |
| 93 | WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_CONSTANT_VALUE, |
| 94 | WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_PROCESS_VARIABLE |
| 95 | ]); |
| 96 | if (count($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_FORMAL_PARAMETER]) != 1) { |
| 97 | throw new common_exception_InconsistentData( |
| 98 | 'Actual variable ' . $resource->getUri() . ' missing formal parameter' |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | if ( |
| 103 | count($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_CONSTANT_VALUE]) |
| 104 | + count($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_PROCESS_VARIABLE]) != 1 |
| 105 | ) { |
| 106 | throw new common_exception_InconsistentData('Actual variable ' . $resource->getUri() . ' invalid, ' |
| 107 | . count($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_CONSTANT_VALUE]) . ' constant values and ' |
| 108 | . count($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_PROCESS_VARIABLE]) . ' process variables'); |
| 109 | } |
| 110 | if (count($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_CONSTANT_VALUE]) > 0) { |
| 111 | $param = new tao_models_classes_service_ConstantParameter( |
| 112 | current($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_FORMAL_PARAMETER]), |
| 113 | current($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_CONSTANT_VALUE]) |
| 114 | ); |
| 115 | } else { |
| 116 | $param = new tao_models_classes_service_VariableParameter( |
| 117 | current($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_FORMAL_PARAMETER]), |
| 118 | current($values[WfEngineOntology::PROPERTY_ACTUAL_PARAMETER_PROCESS_VARIABLE]) |
| 119 | ); |
| 120 | } |
| 121 | return $param; |
| 122 | } |
| 123 | } |