[Beeframework-svn] SF.net SVN: beeframework:[281] trunk/framework/Bee/Beans
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2015-02-12 09:08:10
|
Revision: 281
http://sourceforge.net/p/beeframework/code/281
Author: m_plomer
Date: 2015-02-12 09:08:08 +0000 (Thu, 12 Feb 2015)
Log Message:
-----------
- Beans/BeanWrapper: getters can be prefixed with 'is' as well as 'get'
- Beans/BooleanPropertyEditor: fix for empty string not being recognized as falsy when FILTER_NULL_ON_FAILURE is set
Modified Paths:
--------------
trunk/framework/Bee/Beans/BeanWrapper.php
trunk/framework/Bee/Beans/PropertyEditor/BooleanPropertyEditor.php
Modified: trunk/framework/Bee/Beans/BeanWrapper.php
===================================================================
--- trunk/framework/Bee/Beans/BeanWrapper.php 2015-02-04 14:02:28 UTC (rev 280)
+++ trunk/framework/Bee/Beans/BeanWrapper.php 2015-02-12 09:08:08 UTC (rev 281)
@@ -28,7 +28,7 @@
*/
class BeanWrapper {
- const GETTER_REGEX = '#^get[A-Z]#';
+ const GETTER_REGEX = '#^(?:get|is)[A-Z]#';
/**
* The target object
@@ -47,16 +47,22 @@
}
public final function getPropertyValue($name) {
- return call_user_func($this->findPropertyAccessor($name, 'get'));
+ return call_user_func($this->findPropertyAccessor($name, array('get', 'is')));
}
- protected function findPropertyAccessor($propertyName, $prefix) {
- $methodName = $prefix . ucfirst($propertyName);
- $method = array($this->object, $methodName);
- if (!is_callable($method)) {
- throw new InvalidPropertyException($propertyName, Types::getType($this->object), 'no such method found: ' . $methodName);
+ protected function findPropertyAccessor($propertyName, $prefixes) {
+ $propertyName = ucfirst($propertyName);
+ $prefixes = is_array($prefixes) ? $prefixes : array($prefixes);
+ $triedMethods = array();
+ foreach($prefixes as $prefix) {
+ $methodName = $prefix . $propertyName;
+ $method = array($this->object, $methodName);
+ if (is_callable($method)) {
+ return $method;
+ }
+ $triedMethods[] = $methodName;
}
- return $method;
+ throw new InvalidPropertyException($propertyName, Types::getType($this->object), 'no such method found: ' . implode('|', $triedMethods));
}
public final function setPropertyValueWithPropertyValue(PropertyValue $propertyValue) {
@@ -105,8 +111,8 @@
$publicMethods = $reflClass->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($publicMethods as $method) {
$propName = $method->getShortName();
- if (!$method->isStatic() && preg_match(self::GETTER_REGEX, $propName) && $method->getNumberOfRequiredParameters() == 0) {
- $propName = lcfirst(substr($propName, 3));
+ if (!$method->isStatic() && preg_match(self::GETTER_REGEX, $propName, $matches) && $method->getNumberOfRequiredParameters() == 0) {
+ $propName = lcfirst(substr($propName, strlen($matches[0]) - 1));
$result[$propName] = $method->invoke($this->object);
}
}
Modified: trunk/framework/Bee/Beans/PropertyEditor/BooleanPropertyEditor.php
===================================================================
--- trunk/framework/Bee/Beans/PropertyEditor/BooleanPropertyEditor.php 2015-02-04 14:02:28 UTC (rev 280)
+++ trunk/framework/Bee/Beans/PropertyEditor/BooleanPropertyEditor.php 2015-02-12 09:08:08 UTC (rev 281)
@@ -47,7 +47,7 @@
if(is_bool($value)) {
return $value;
}
- return $this->checkAndReturnIfNotNull(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), $value);
+ return $this->checkAndReturnIfNotNull(filter_var($value === '' ? 0 : $value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), $value);
}
public static function valueOf($value) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|