From b4f41b167b62bb628d0809fc0e9438e11dce2bb5 Mon Sep 17 00:00:00 2001 From: alex <> Date: Thu, 17 Nov 2005 11:47:30 +0000 Subject: Updated TPropertyValue so ensureArray parses a string like "(aaa,bbb,ccc)" into array("aaa","bbb","ccc"). Also added PradoUnitTestCase which is to be finalized shortly. --- framework/TComponent.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'framework') diff --git a/framework/TComponent.php b/framework/TComponent.php index 8df1f235..04c99f2a 100644 --- a/framework/TComponent.php +++ b/framework/TComponent.php @@ -490,13 +490,29 @@ class TPropertyValue } /** - * Converts a value to array type. + * Converts a value to array type. If the value is a string and it is + * in the form (a,b,c) then an array consisting of each of the elements + * will be returned. If the value is a string and it is not in this form + * then an array consisting of just the string will be returned. If the value + * is not a string then * @param mixed the value to be converted. * @return array */ public static function ensureArray($value) { - return (array)$value; + if (is_string($value)) { + $trimmed = trim($value); + $len = strlen($value); + if ($len >= 2 && $trimmed{0} == '(' && $trimmed{$len-1} == ')') { + return explode(",", substr($trimmed,1,$len-2)); + } else if ($len > 0) { + return array($value); + } else { + return array(); + } + } else { + return (array)$value; + } } /** -- cgit v1.2.3