[Beeframework-svn] SF.net SVN: beeframework:[280] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2015-02-04 14:02:36
|
Revision: 280 http://sourceforge.net/p/beeframework/code/280 Author: m_plomer Date: 2015-02-04 14:02:28 +0000 (Wed, 04 Feb 2015) Log Message: ----------- - Security/UserDetails: refactored UserManagerBase for better extensibility through subclassing - BeanWrapper: added getPropertyValues() / setWritablePropertyValues() Modified Paths: -------------- trunk/framework/Bee/Beans/BeanWrapper.php trunk/framework/Bee/Framework.php Added Paths: ----------- trunk/framework/Bee/Security/UserDetails/PasswordConfirmationMismatchException.php Modified: trunk/framework/Bee/Beans/BeanWrapper.php =================================================================== --- trunk/framework/Bee/Beans/BeanWrapper.php 2015-01-29 11:24:41 UTC (rev 279) +++ trunk/framework/Bee/Beans/BeanWrapper.php 2015-02-04 14:02:28 UTC (rev 280) @@ -1,5 +1,6 @@ <?php namespace Bee\Beans; + /* * Copyright 2008-2014 the original author or authors. * @@ -17,6 +18,8 @@ */ use Bee\Context\InvalidPropertyException; use Bee\Utils\Types; +use ReflectionClass; +use ReflectionMethod; /** * Enter description here... @@ -24,47 +27,89 @@ * @author Benjamin Hartmann */ class BeanWrapper { - - /** - * The target object - * - * @var object - */ - private $object; - - - public function __construct($object) { - $this->object = $object; - } - - public final function setPropertyValue($name, $value) { - call_user_func($this->findPropertyAccessor($name, 'set'), $value); - } - public final function getPropertyValue($name) { - return call_user_func($this->findPropertyAccessor($name, 'get')); - } - - 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); - } - return $method; - } - - public final function setPropertyValueWithPropertyValue(PropertyValue $propertyValue) { - $this->setPropertyValue($propertyValue->getName(), $propertyValue->getValue()); - } + const GETTER_REGEX = '#^get[A-Z]#'; - public final function setPropertyValues(array $propertyValues) { - foreach ($propertyValues as $name => $propertyValue) { - if (!is_string($propertyValue) && Types::isAssignable($propertyValue, 'Bee\Beans\PropertyValue')) { - $this->setPropertyValueWithPropertyValue($propertyValue); - } else { - $this->setPropertyValue($name, $propertyValue); - } - } - } + /** + * The target object + * + * @var object + */ + private $object; + + + public function __construct($object) { + $this->object = $object; + } + + public final function setPropertyValue($name, $value) { + call_user_func($this->findPropertyAccessor($name, 'set'), $value); + } + + public final function getPropertyValue($name) { + return call_user_func($this->findPropertyAccessor($name, 'get')); + } + + 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); + } + return $method; + } + + public final function setPropertyValueWithPropertyValue(PropertyValue $propertyValue) { + $this->setPropertyValue($propertyValue->getName(), $propertyValue->getValue()); + } + + /** + * @param array $propertyValues + */ + public final function setPropertyValues(array $propertyValues) { + foreach ($propertyValues as $name => $propertyValue) { + if (!is_string($propertyValue) && Types::isAssignable($propertyValue, 'Bee\Beans\PropertyValue')) { + $this->setPropertyValueWithPropertyValue($propertyValue); + } else { + $this->setPropertyValue($name, $propertyValue); + } + } + } + + /** + * @param array $propertyValues + */ + public final function setWritablePropertyValues(array $propertyValues) { + foreach ($propertyValues as $name => $propertyValue) { + try { + if (!is_string($propertyValue) && Types::isAssignable($propertyValue, 'Bee\Beans\PropertyValue')) { + $this->setPropertyValueWithPropertyValue($propertyValue); + } else { + $this->setPropertyValue($name, $propertyValue); + } + } catch (InvalidPropertyException $e) { + // ignored + } + } + } + + /** + * @return array|null + */ + public final function getPropertyValues() { + if (is_null($this->object)) { + return null; + } + $result = array(); + $reflClass = new ReflectionClass($this->object); + $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)); + $result[$propName] = $method->invoke($this->object); + } + } + return $result; + } } \ No newline at end of file Modified: trunk/framework/Bee/Framework.php =================================================================== --- trunk/framework/Bee/Framework.php 2015-01-29 11:24:41 UTC (rev 279) +++ trunk/framework/Bee/Framework.php 2015-02-04 14:02:28 UTC (rev 280) @@ -375,9 +375,11 @@ * @deprecated replaced by Bee\Framework */ class Bee_Framework extends Framework { + } interface TYPES extends ITypeDefinitions { + } } Added: trunk/framework/Bee/Security/UserDetails/PasswordConfirmationMismatchException.php =================================================================== --- trunk/framework/Bee/Security/UserDetails/PasswordConfirmationMismatchException.php (rev 0) +++ trunk/framework/Bee/Security/UserDetails/PasswordConfirmationMismatchException.php 2015-02-04 14:02:28 UTC (rev 280) @@ -0,0 +1,12 @@ +<?php +namespace Bee\Security\UserDetails; + +use Exception; + +/** + * Class PasswordConfirmationMismatchException + * @package Bee\Security\UserDetails + */ +class PasswordConfirmationMismatchException extends Exception { + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |