[Beeframework-svn] SF.net SVN: beeframework:[291] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2015-02-26 16:35:41
|
Revision: 291 http://sourceforge.net/p/beeframework/code/291 Author: m_plomer Date: 2015-02-26 16:35:33 +0000 (Thu, 26 Feb 2015) Log Message: ----------- - various refactorings Modified Paths: -------------- trunk/framework/Bee/Beans/BeanWrapper.php trunk/framework/Bee/Beans/PropertyEditor/TPropertyEditorRegistryHolder.php trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Beans/BeanWrapper.php =================================================================== --- trunk/framework/Bee/Beans/BeanWrapper.php 2015-02-25 11:08:06 UTC (rev 290) +++ trunk/framework/Bee/Beans/BeanWrapper.php 2015-02-26 16:35:33 UTC (rev 291) @@ -51,6 +51,18 @@ } protected function findPropertyAccessor($propertyName, $prefixes) { + if(($dotpos = strpos($propertyName, '.')) !== false) { + $pathElem = substr($propertyName, 0, $dotpos); + $subProp = substr($propertyName, $dotpos + 1); + + $subValue = call_user_func($this->findPropertyAccessor($pathElem, 'get')); + if(is_null($subValue)) { + return null; + } + $subBw = new BeanWrapper($subValue); + return $subBw->findPropertyAccessor($subProp, $prefixes); + } + $propertyName = ucfirst($propertyName); $prefixes = is_array($prefixes) ? $prefixes : array($prefixes); $triedMethods = array(); Modified: trunk/framework/Bee/Beans/PropertyEditor/TPropertyEditorRegistryHolder.php =================================================================== --- trunk/framework/Bee/Beans/PropertyEditor/TPropertyEditorRegistryHolder.php 2015-02-25 11:08:06 UTC (rev 290) +++ trunk/framework/Bee/Beans/PropertyEditor/TPropertyEditorRegistryHolder.php 2015-02-26 16:35:33 UTC (rev 291) @@ -16,6 +16,7 @@ */ namespace Bee\Beans\PropertyEditor; +use Bee\Beans\IPropertyEditor; use Bee\IContext; /** @@ -42,4 +43,12 @@ public function getPropertyEditorRegistry() { return $this->propertyEditorRegistry; } + + /** + * @param string $type + * @return IPropertyEditor + */ + public function getPropertyEditorForType($type) { + return $this->propertyEditorRegistry->getEditor($type); + } } \ No newline at end of file Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2015-02-25 11:08:06 UTC (rev 290) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2015-02-26 16:35:33 UTC (rev 291) @@ -107,7 +107,7 @@ } else if (array_key_exists($type, $fixedParams)) { $args[$pos] = $fixedParams[$type]; } else { - $propEditor = $this->propertyEditorRegistry->getEditor($type); + $propEditor = $this->getPropertyEditorForType($type); $posMap = $resolvedMethod->getUrlParameterPositions(); $value = array_key_exists($pos, $posMap) ? $resolvedMethod->getParamValue($posMap[$pos]) : (array_key_exists($parameter->getName(), $_REQUEST) ? $_REQUEST[$parameter->getName()] : null); Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-25 11:08:06 UTC (rev 290) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-26 16:35:33 UTC (rev 291) @@ -3,6 +3,7 @@ use Bee\Persistence\IOrderAndLimitHolder; use Bee\Persistence\IRestrictionHolder; +use Bee\Utils\Assert; use Bee\Utils\Strings; use Doctrine\ORM\QueryBuilder; use UnexpectedValueException; @@ -25,6 +26,11 @@ */ private $aliases; + /** + * @var array + */ + private $reverseAliases; + /** * @var array * @@ -154,9 +160,27 @@ if(!is_null($orderAndLimitHolder)) { if(count($orderAndLimitHolder->getOrderMapping()) > 0) { + $internalMapping = array(); foreach($orderAndLimitHolder->getOrderMapping() as $field => $dir) { + + + $tokens = explode('.', $field); + $currentAlias = $this->getEntityAlias(); + do { + $field = $currentAlias . '.' . array_shift($tokens); + if(array_key_exists($field, $this->reverseAliases)) { + // this is an association, there must be an actual field token left in the array + Assert::isTrue(count($tokens) > 0); + $currentAlias = $this->reverseAliases[$field]; + } + + } while(count($tokens) > 0); + $this->addAliasForExpression($queryBuilder, $field); + $internalMapping[$field] = $dir; } + + $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); } } @@ -253,6 +277,7 @@ */ public function setAliases(array $aliases) { $this->aliases = $aliases; + $this->reverseAliases = array_flip($aliases); } /** @@ -289,4 +314,65 @@ public function setDefaultOrderMapping(array $defaultOrderMapping) { $this->defaultOrderMapping = $defaultOrderMapping; } +} + +class GenericDaoBase_OrderAndLimitWrapper implements IOrderAndLimitHolder { + + /** + * @var IOrderAndLimitHolder + */ + private $wrappedOrderAndLimitHolder; + + /** + * @var array + */ + private $internalOrderMapping; + + function __construct(IOrderAndLimitHolder $wrappedOrderAndLimitHolder, $internalOrderMapping) { + $this->wrappedOrderAndLimitHolder = $wrappedOrderAndLimitHolder; + $this->internalOrderMapping = $internalOrderMapping; + } + + + /** + * @return array + */ + public function getOrderMapping() { + return $this->internalOrderMapping; + } + + /** + * @return int + */ + public function getPageSize() { + return $this->wrappedOrderAndLimitHolder->getPageSize(); + } + + /** + * @return int + */ + public function getPageCount() { + return $this->wrappedOrderAndLimitHolder->getPageCount(); + } + + /** + * @return int + */ + public function getCurrentPage() { + return $this->wrappedOrderAndLimitHolder->getCurrentPage(); + } + + /** + * @param $currentPage + */ + public function setCurrentPage($currentPage) { + $this->wrappedOrderAndLimitHolder->setCurrentPage($currentPage); + } + + /** + * @param int $resultCount + */ + public function setResultCount($resultCount) { + $this->wrappedOrderAndLimitHolder->setResultCount($resultCount); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |