| 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_CheckPHPRuntimeService |  | 0.00% | 0 / 34 |  | 0.00% | 0 / 5 | 272 |  | 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 / 9 |  | 0.00% | 0 / 1 | 90 | |||
| buildComponent |  | 0.00% | 0 / 7 |  | 0.00% | 0 / 1 | 12 | |||
| buildResult |  | 0.00% | 0 / 14 |  | 0.00% | 0 / 1 | 6 | |||
| 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 version of the PHP Runtime currently running | 
| 30 | * 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_CheckPHPRuntimeService 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($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 | $runtime = self::buildComponent($this->getData()); | 
| 60 | $report = $runtime->check(); | 
| 61 | |
| 62 | $this->setResult(self::buildResult($this->getData(), $report, $runtime)); | 
| 63 | } | 
| 64 | |
| 65 | protected function checkData() | 
| 66 | { | 
| 67 | $content = json_decode($this->getData()->getContent(), true); | 
| 68 | if (!isset($content['type']) || empty($content['type']) || $content['type'] != 'CheckPHPRuntime') { | 
| 69 | throw new InvalidArgumentException("Unexpected type: 'type' must be equal to 'CheckPHPRuntime'."); | 
| 70 | } elseif (!isset($content['value']) || empty($content['value'])) { | 
| 71 | throw new InvalidArgumentException("Missing data: 'value' must be provided."); | 
| 72 | } elseif (!isset($content['value']['id']) || empty($content['value']['id'])) { | 
| 73 | throw new InvalidArgumentException("Missing data: 'id' must be provided."); | 
| 74 | } elseif (!isset($content['value']['min'])) { | 
| 75 | throw new InvalidArgumentException("Missing data: 'min' must be provided."); | 
| 76 | } | 
| 77 | } | 
| 78 | |
| 79 | public static function buildComponent(tao_install_services_Data $data) | 
| 80 | { | 
| 81 | $content = json_decode($data->getContent(), true); | 
| 82 | $min = $content['value']['min']; | 
| 83 | $max = (isset($content['value']['max'])) ? $content['value']['max'] : null; | 
| 84 | |
| 85 | if (isset($content['value']['optional'])) { | 
| 86 | $optional = $content['value']['optional']; | 
| 87 | } else { | 
| 88 | $optional = false; | 
| 89 | } | 
| 90 | |
| 91 | return common_configuration_ComponentFactory::buildPHPRuntime($min, $max, $optional); | 
| 92 | } | 
| 93 | |
| 94 | public static function buildResult( | 
| 95 | tao_install_services_Data $data, | 
| 96 | common_configuration_Report $report, | 
| 97 | common_configuration_Component $component | 
| 98 | ) { | 
| 99 | |
| 100 | $content = json_decode($data->getContent(), true); | 
| 101 | $id = $content['value']['id']; | 
| 102 | |
| 103 | $value = ['status' => $report->getStatusAsString(), | 
| 104 | 'id' => $id, | 
| 105 | 'message' => $report->getMessage(), | 
| 106 | 'min' => $component->getMin(), | 
| 107 | 'value' => $component->getValue(), | 
| 108 | 'optional' => $component->isOptional()]; | 
| 109 | |
| 110 | $max = $component->getMax(); | 
| 111 | if (!empty($max)) { | 
| 112 | $value['max'] = $component->getMax(); | 
| 113 | } | 
| 114 | |
| 115 | |
| 116 | $data = ['type' => 'PHPRuntimeReport', | 
| 117 | 'value' => $value]; | 
| 118 | |
| 119 | return new tao_install_services_Data(json_encode($data)); | 
| 120 | } | 
| 121 | } |