Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.29% |
33 / 35 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| common_configuration_PHPExtension | |
94.29% |
33 / 35 |
|
50.00% |
1 / 2 |
13.03 | |
0.00% |
0 / 1 |
| check | |
93.75% |
30 / 32 |
|
0.00% |
0 / 1 |
12.04 | |||
| getValue | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | * Short description of class common_configuration_PHPExtension |
| 29 | * |
| 30 | * @access public |
| 31 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 32 | * @package generis |
| 33 | |
| 34 | */ |
| 35 | class common_configuration_PHPExtension extends common_configuration_BoundableComponent |
| 36 | { |
| 37 | // --- ASSOCIATIONS --- |
| 38 | |
| 39 | |
| 40 | // --- ATTRIBUTES --- |
| 41 | |
| 42 | // --- OPERATIONS --- |
| 43 | |
| 44 | /** |
| 45 | * Short description of method check |
| 46 | * |
| 47 | * @access public |
| 48 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 49 | * @return common_configuration_Report |
| 50 | */ |
| 51 | public function check() |
| 52 | { |
| 53 | $returnValue = null; |
| 54 | |
| 55 | |
| 56 | $name = $this->getName(); |
| 57 | $min = $this->getMin(); |
| 58 | $max = $this->getMax(); |
| 59 | $validity = null; |
| 60 | $message = null; |
| 61 | |
| 62 | if (extension_loaded($name)) { |
| 63 | $current = $this->getValue(); |
| 64 | |
| 65 | if (!empty($min) && !empty($max)) { |
| 66 | // Both min and max are specified. |
| 67 | if (version_compare($current, $min, '>=') && version_compare($current, $max, '<=')) { |
| 68 | $validity = common_configuration_Report::VALID; |
| 69 | $message = "PHP Extension '${name}' version (${current}) is between ${min} and ${max}."; |
| 70 | } else { |
| 71 | $validity = common_configuration_Report::INVALID; |
| 72 | $message = "PHP Extension '${name}' version (${current}) is not between ${min} and ${max}."; |
| 73 | } |
| 74 | } elseif (!empty($min) && empty($max)) { |
| 75 | // Only min is specified. |
| 76 | if (version_compare($current, $min, '>=')) { |
| 77 | $validity = common_configuration_Report::VALID; |
| 78 | $message = "PHP Extension '${name}' version (${current}) is greater or equal to ${min}."; |
| 79 | } else { |
| 80 | $validity = common_configuration_Report::INVALID; |
| 81 | $message = "PHP Extension '${name}' version (${current}) is lesser than ${min}."; |
| 82 | } |
| 83 | } elseif (empty($min) && !empty($max)) { |
| 84 | // Only max is specified. |
| 85 | if (version_compare($current, $max, '<=')) { |
| 86 | $validity = common_configuration_Report::VALID; |
| 87 | $message = "PHP Extension '${name}' version (${current}) is lesser or equal to ${max}."; |
| 88 | } else { |
| 89 | $validity = common_configuration_Report::INVALID; |
| 90 | $message = "PHP Extension '${name}' version (${current}) is greater than ${max}."; |
| 91 | } |
| 92 | } else { |
| 93 | // No min and max are provided, we just check the |
| 94 | // existence of the extension (already done). |
| 95 | $validity = common_configuration_Report::VALID; |
| 96 | $message = "PHP Extension '${name}' is loaded."; |
| 97 | } |
| 98 | } else { |
| 99 | $validity = common_configuration_Report::UNKNOWN; |
| 100 | $message = "PHP Extension '${name}' could not be found."; |
| 101 | } |
| 102 | |
| 103 | $returnValue = new common_configuration_Report($validity, $message, $this); |
| 104 | |
| 105 | |
| 106 | return $returnValue; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Short description of method getValue |
| 111 | * |
| 112 | * @access public |
| 113 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 114 | * @return string |
| 115 | */ |
| 116 | public function getValue() |
| 117 | { |
| 118 | $returnValue = (string) ''; |
| 119 | |
| 120 | |
| 121 | $returnValue = phpversion($this->getName()); |
| 122 | |
| 123 | |
| 124 | return (string) $returnValue; |
| 125 | } |
| 126 | } |