diff --git a/Model/Decorator/MethodDecorator.php b/Model/Decorator/MethodDecorator.php index f66ca54acf7f1908ad97074ca4dd64b3cd13ce31..f2b2e5a420bb2f03092ed2c027e11baedacee18c 100644 --- a/Model/Decorator/MethodDecorator.php +++ b/Model/Decorator/MethodDecorator.php @@ -28,7 +28,7 @@ class MethodDecorator implements DecoratorInterface foreach($class->getMethods() as $method) { /* @var $method ReflectionMethod */ - if ($method->getDeclaringClass() != $class) { + if ($method->getDeclaringClass() != $class || $this->isAccessor($method, $class)) { continue; } @@ -44,4 +44,28 @@ class MethodDecorator implements DecoratorInterface ); } } + + /** + * @param ReflectionMethod $method + * @param ReflectionClass $class + * @return boolean + */ + protected function isAccessor(ReflectionMethod $method, ReflectionClass $class) + { + if (!$method->isPublic() || $method->isAbstract() || $method->getDeclaringClass()->isInterface()) { + return false; + } + if ($method->getNumberOfParameters() === 0 && preg_match('/(?:get|is)(\w+)/', $method->getName(), $groups)) { + $name = lcfirst($groups[1]); + } elseif ($method->getNumberOfParameters() === 1 && preg_match('/(?:set|add|remove)(\w+)/', $method->getName(), $groups)) { + $name = lcfirst($groups[1]); + } else { + return false; + } + if (!$class->hasProperty($name)) { + return false; + } + $property = $class->getProperty($name); + return $property->isStatic() == $method->isStatic(); + } }