Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_services_CheckPHPINIValueService | |
0.00% |
0 / 34 |
|
0.00% |
0 / 5 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| checkData | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
110 | |||
| buildComponent | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| buildResult | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * A Service implementation aiming at checking the existence and the validity of a PHP |
| 30 | * INI value on the host system. |
| 31 | * |
| 32 | * Please refer to tao/install/api.php for more information about how to call this service. |
| 33 | * |
| 34 | * @access public |
| 35 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 36 | * @package tao |
| 37 | |
| 38 | */ |
| 39 | class tao_install_services_CheckPHPINIValueService extends tao_install_services_Service implements |
| 40 | tao_install_services_CheckService |
| 41 | { |
| 42 | /** |
| 43 | * Creates a new instance of the service. |
| 44 | * @param tao_install_services_Data $data The input data to be handled by the service. |
| 45 | * @throws InvalidArgumentException If the input data structured is malformed or is missing data. |
| 46 | */ |
| 47 | public function __construct(tao_install_services_Data $data) |
| 48 | { |
| 49 | parent::__construct($data); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Executes the main logic of the service. |
| 54 | * @return tao_install_services_Data The result of the service execution. |
| 55 | */ |
| 56 | public function execute() |
| 57 | { |
| 58 | |
| 59 | $ini = self::buildComponent($this->getData()); |
| 60 | $report = $ini->check(); |
| 61 | $this->setResult(self::buildResult($this->getData(), $report, $ini)); |
| 62 | } |
| 63 | |
| 64 | protected function checkData() |
| 65 | { |
| 66 | // Check input data. |
| 67 | $content = json_decode($this->getData()->getContent(), true); |
| 68 | if (!isset($content['type']) || empty($content['type']) || $content['type'] !== 'CheckPHPINIValue') { |
| 69 | throw new InvalidArgumentException("Unexpected type: 'type' must be equal to 'CheckPHPINIValue'."); |
| 70 | } elseif (!isset($content['value']) || empty($content['value'])) { |
| 71 | throw new InvalidArgumentException("Missing data: 'value' must be provided."); |
| 72 | } |
| 73 | if (!isset($content['value']['id']) || empty($content['value']['id'])) { |
| 74 | throw new InvalidArgumentException("Missing data: 'id' must be provided."); |
| 75 | } |
| 76 | if (!isset($content['value']['name'])) { |
| 77 | throw new InvalidArgumentException("Missing data: 'name' must be provided."); |
| 78 | } elseif (!isset($content['value']['value'])) { |
| 79 | throw new InvalidArgumentException("Missing data: 'value' must be provided."); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public static function buildComponent(tao_install_services_Data $data) |
| 84 | { |
| 85 | $content = json_decode($data->getContent(), true); |
| 86 | $value = $content['value']['value']; |
| 87 | $name = $content['value']['name']; |
| 88 | if (isset($content['value']['optional'])) { |
| 89 | $optional = $content['value']['optional']; |
| 90 | } else { |
| 91 | $optional = false; |
| 92 | } |
| 93 | |
| 94 | return common_configuration_ComponentFactory::buildPHPINIValue($name, $value, $optional); |
| 95 | } |
| 96 | |
| 97 | public static function buildResult( |
| 98 | tao_install_services_Data $data, |
| 99 | common_configuration_Report $report, |
| 100 | common_configuration_Component $component |
| 101 | ) { |
| 102 | |
| 103 | $content = json_decode($data->getContent(), true); |
| 104 | $value = $content['value']['value']; |
| 105 | $id = $content['value']['id']; |
| 106 | |
| 107 | $data = ['type' => 'PHPINIValueReport', |
| 108 | 'value' => ['status' => $report->getStatusAsString(), |
| 109 | 'id' => $id, |
| 110 | 'message' => $report->getMessage(), |
| 111 | 'expectedValue' => $value, |
| 112 | 'value' => $component->getValue(), |
| 113 | 'optional' => $component->isOptional(), |
| 114 | 'name' => $component->getName()]]; |
| 115 | |
| 116 | return new tao_install_services_Data(json_encode($data)); |
| 117 | } |
| 118 | } |