beeframework-svn Mailing List for Bee Framework
Brought to you by:
b_hartmann,
m_plomer
You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(6) |
2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(12) |
Jun
(5) |
Jul
(6) |
Aug
(25) |
Sep
(25) |
Oct
(6) |
Nov
(29) |
Dec
|
2014 |
Jan
(2) |
Feb
(10) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(5) |
Jul
(35) |
Aug
(9) |
Sep
(33) |
Oct
(30) |
Nov
(4) |
Dec
(1) |
2015 |
Jan
(3) |
Feb
(13) |
Mar
(13) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <m_p...@us...> - 2015-03-13 08:41:13
|
Revision: 306 http://sourceforge.net/p/beeframework/code/306 Author: m_plomer Date: 2015-03-13 08:41:05 +0000 (Fri, 13 Mar 2015) Log Message: ----------- - regression fix in PaginationBase Modified Paths: -------------- trunk/framework/Bee/Persistence/PaginationBase.php Modified: trunk/framework/Bee/Persistence/PaginationBase.php =================================================================== --- trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-13 03:51:46 UTC (rev 305) +++ trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-13 08:41:05 UTC (rev 306) @@ -122,6 +122,6 @@ } private function getIndexSave($idx, $defaultVal = 0) { - return array_key_exists($idx, $this->state) ? $this->state[$idx] : $defaultVal; + return isset($this->state[$idx]) ? $this->state[$idx] : $defaultVal; } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-13 03:51:53
|
Revision: 305 http://sourceforge.net/p/beeframework/code/305 Author: m_plomer Date: 2015-03-13 03:51:46 +0000 (Fri, 13 Mar 2015) Log Message: ----------- - automatic parameter numbering for scalar restrictions Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-12 22:31:33 UTC (rev 304) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-13 03:51:46 UTC (rev 305) @@ -79,6 +79,11 @@ private $addedAliases = array(); /** + * @var int + */ + private $scalarParamCount = 0; + + /** * @param mixed $id * @throws UnexpectedValueException * @return mixed @@ -426,7 +431,8 @@ protected final function addScalarRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '', $comp = self::SCALAR_RESTRICTION_EQUAL) { $filterKey = $filterKey ?: $fieldExpr; if (array_key_exists($filterKey, $filters) && $value = $filters[$filterKey]) { - $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . $comp . ':val')->setParameter('val', $value); + $paramName = 'sclr' . $this->scalarParamCount++; + $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . $comp . ':' . $paramName)->setParameter($paramName, $value); } return $queryBuilder; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-12 22:31:40
|
Revision: 304 http://sourceforge.net/p/beeframework/code/304 Author: m_plomer Date: 2015-03-12 22:31:33 +0000 (Thu, 12 Mar 2015) Log Message: ----------- - regression fix Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-12 21:19:32 UTC (rev 303) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-12 22:31:33 UTC (rev 304) @@ -16,6 +16,12 @@ const FILTER_STRING = 'filterString'; const FILTER_STRING_FIELDS = 'filterStringFields'; + const SCALAR_RESTRICTION_EQUAL = ' = '; + const SCALAR_RESTRICTION_LESS = ' < '; + const SCALAR_RESTRICTION_LESS_OR_EQUAL = ' <= '; + const SCALAR_RESTRICTION_GREATER = ' > '; + const SCALAR_RESTRICTION_GREATER_OR_EQUAL = ' >= '; + /** * @var callable */ @@ -414,34 +420,17 @@ * @param array $filters * @param string $fieldExpr * @param string $filterKey + * @param string $comp * @return QueryBuilder for chaining */ - protected final function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '') { + protected final function addScalarRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '', $comp = self::SCALAR_RESTRICTION_EQUAL) { $filterKey = $filterKey ?: $fieldExpr; if (array_key_exists($filterKey, $filters) && $value = $filters[$filterKey]) { - $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . ' = :val')->setParameter('val', $value); + $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . $comp . ':val')->setParameter('val', $value); } return $queryBuilder; } - /** - * @param QueryBuilder $queryBuilder - * @param $filters - * @param $fldExpr - * @param bool $filterKeyFrom - * @param bool $filterKeyUntil - */ - protected function addDateRestriction(QueryBuilder $queryBuilder, $filters, $fldExpr, $filterKeyFrom = false, $filterKeyUntil = false) { - $filterKeyFrom = $filterKeyFrom ?: $fldExpr . 'From'; - if (array_key_exists($filterKeyFrom, $filters) && $date = DateTimeHelper::parseDate($filters[$filterKeyFrom])) { - $queryBuilder->andWhere($this->internalizeFieldExpression($fldExpr, $queryBuilder) . ' >= :dateFrom')->setParameter('dateFrom', $date); - } - $filterKeyUntil = $filterKeyUntil ?: $fldExpr . 'Until'; - if (array_key_exists($filterKeyUntil, $filters) && $date = DateTimeHelper::parseDate($filters[$filterKeyUntil])) { - $queryBuilder->andWhere($this->internalizeFieldExpression($fldExpr, $queryBuilder) . ' <= :dateUntil')->setParameter('dateUntil', $date); - } - } - // ================================================================================================================= // == GETTERS & SETTERS ============================================================================================ // ================================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-12 21:19:39
|
Revision: 303 http://sourceforge.net/p/beeframework/code/303 Author: m_plomer Date: 2015-03-12 21:19:32 +0000 (Thu, 12 Mar 2015) Log Message: ----------- - removed superfluous IJsonSerializable interface Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/JsonSerializablePaginator.php Removed Paths: ------------- trunk/framework/Bee/Utils/IJsonSerializable.php Modified: trunk/framework/Bee/Persistence/Doctrine2/JsonSerializablePaginator.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/JsonSerializablePaginator.php 2015-03-12 20:06:26 UTC (rev 302) +++ trunk/framework/Bee/Persistence/Doctrine2/JsonSerializablePaginator.php 2015-03-12 21:19:32 UTC (rev 303) @@ -2,15 +2,18 @@ namespace Bee\Persistence\Doctrine2; use Doctrine\ORM\Tools\Pagination\Paginator; -use Bee\Utils\IJsonSerializable; +use JsonSerializable; /** * Class JsonSerializablePaginator * @package Bee\Tools\Entities */ -class JsonSerializablePaginator extends Paginator implements IJsonSerializable { +class JsonSerializablePaginator extends Paginator implements JsonSerializable { - public function jsonSerialize() { + /** + * @return array + */ + function jsonSerialize() { return $this->getIterator()->getArrayCopy(); } } \ No newline at end of file Deleted: trunk/framework/Bee/Utils/IJsonSerializable.php =================================================================== --- trunk/framework/Bee/Utils/IJsonSerializable.php 2015-03-12 20:06:26 UTC (rev 302) +++ trunk/framework/Bee/Utils/IJsonSerializable.php 2015-03-12 21:19:32 UTC (rev 303) @@ -1,13 +0,0 @@ -<?php -namespace Bee\Utils; - -/** - * Interface IJsonSerializable - * @package Iter8\Utils - */ -interface IJsonSerializable { - /** - * @return mixed - */ - function jsonSerialize(); -} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-12 20:06:29
|
Revision: 302 http://sourceforge.net/p/beeframework/code/302 Author: m_plomer Date: 2015-03-12 20:06:26 +0000 (Thu, 12 Mar 2015) Log Message: ----------- - default page size set in PaginationBase Modified Paths: -------------- trunk/framework/Bee/MVC/ModelAndView.php trunk/framework/Bee/MVC/View/AbstractView.php trunk/framework/Bee/Persistence/PaginationBase.php Modified: trunk/framework/Bee/MVC/ModelAndView.php =================================================================== --- trunk/framework/Bee/MVC/ModelAndView.php 2015-03-12 19:49:28 UTC (rev 301) +++ trunk/framework/Bee/MVC/ModelAndView.php 2015-03-12 20:06:26 UTC (rev 302) @@ -153,6 +153,6 @@ */ public function renderModelInView() { // @todo: assert a resolvedView is set - $this->resolvedView->render($this->getModel()); + $this->resolvedView->render($this->getModel()); } } \ No newline at end of file Modified: trunk/framework/Bee/MVC/View/AbstractView.php =================================================================== --- trunk/framework/Bee/MVC/View/AbstractView.php 2015-03-12 19:49:28 UTC (rev 301) +++ trunk/framework/Bee/MVC/View/AbstractView.php 2015-03-12 20:06:26 UTC (rev 302) @@ -60,17 +60,17 @@ */ public final function render(array $model = null) { // Consolidate static and dynamic model attributes. - - $oldModelValues = Model::getModelValues(); + + $oldModelValues = Model::getModelValues(); Model::clear(); // Model::addValuesToModel($this->staticAttributes); Model::addValuesToModel($model); - $this->prepareResponse(); + $this->prepareResponse(); $this->outputStatusHeader(); - $this->renderMergedOutputModel(); + $this->renderMergedOutputModel(); Model::clear(); Model::addValuesToModel($oldModelValues); Modified: trunk/framework/Bee/Persistence/PaginationBase.php =================================================================== --- trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-12 19:49:28 UTC (rev 301) +++ trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-12 20:06:26 UTC (rev 302) @@ -31,11 +31,19 @@ */ private $state = array(); - /** + /** + * + */ + function __construct() { + $this->setPageSize(50); + } + + + /** * @return int */ public function getPageSize() { - return $this->state['pageSize']; + return $this->getIndexSave('pageSize'); } /** @@ -56,7 +64,7 @@ * @return int */ public function getCurrentPage() { - return $this->state['currentPage']; + return $this->getIndexSave('currentPage'); } /** @@ -81,7 +89,7 @@ * @return int */ public function getResultCount() { - return $this->state['resultCount']; + return $this->getIndexSave('resultCount'); } /** @@ -112,4 +120,8 @@ function jsonSerialize() { return array('pageCount' => $this->getPageCount(), 'pageSize' => $this->getPageSize(), 'currentPage' => $this->getCurrentPage(), 'resultCount' => $this->getResultCount()); } + + private function getIndexSave($idx, $defaultVal = 0) { + return array_key_exists($idx, $this->state) ? $this->state[$idx] : $defaultVal; + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-12 19:49:35
|
Revision: 301 http://sourceforge.net/p/beeframework/code/301 Author: m_plomer Date: 2015-03-12 19:49:28 +0000 (Thu, 12 Mar 2015) Log Message: ----------- - default page size set in PaginationBase Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-12 18:01:07 UTC (rev 300) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-12 19:49:28 UTC (rev 301) @@ -229,9 +229,9 @@ */ protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, QueryBuilder $queryBuilder, array &$internalFieldValueMapping = array()) { foreach ($externalFieldValueMapping as $field => $value) { - array_walk($this->getFieldDisaggregation($field), function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { + array_map(function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { $internalFieldValueMapping[$this->internalizeFieldExpression($field, $queryBuilder)] = $value; - }); + }, $this->getFieldDisaggregation($field)); } return $internalFieldValueMapping; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-12 18:01:15
|
Revision: 300 http://sourceforge.net/p/beeframework/code/300 Author: m_plomer Date: 2015-03-12 18:01:07 +0000 (Thu, 12 Mar 2015) Log Message: ----------- - various bugfixes, fixes for PHP 5.4-5.6 compatibility Modified Paths: -------------- trunk/framework/Bee/Context/AbstractContext.php trunk/framework/Bee/Context/Config/IBeanReference.php trunk/framework/Bee/Context/Config/IScope.php trunk/framework/Bee/Context/Config/RuntimeBeanNameReference.php trunk/framework/Bee/Context/Config/RuntimeBeanReference.php trunk/framework/Bee/Context/Config/Scope/CacheScope.php trunk/framework/Bee/Context/Config/Scope/PrototypeScope.php trunk/framework/Bee/Context/Config/Scope/RequestScope.php trunk/framework/Bee/MVC/Session/DispatcherAdapter.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Context/AbstractContext.php =================================================================== --- trunk/framework/Bee/Context/AbstractContext.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/AbstractContext.php 2015-03-12 18:01:07 UTC (rev 300) @@ -47,7 +47,9 @@ * @author Michael Plomer <mic...@it...> */ abstract class AbstractContext extends BasicBeanDefinitionRegistry implements IContext, IContextAware { - use TPropertyEditorRegistryHolder; + use TPropertyEditorRegistryHolder { + TPropertyEditorRegistryHolder::setBeeContext as setPropertyEditorContext; + } /** * @var IContext[] @@ -886,6 +888,14 @@ public function getModificationTimestamp() { return 0; } + + /** + * @param IContext $context + */ + public function setBeeContext(IContext $context) { + $this->setPropertyEditorContext($context); + $this->setParent($context); + } } Modified: trunk/framework/Bee/Context/Config/IBeanReference.php =================================================================== --- trunk/framework/Bee/Context/Config/IBeanReference.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/IBeanReference.php 2015-03-12 18:01:07 UTC (rev 300) @@ -27,7 +27,7 @@ /** * Return the target bean name that this reference points to (never <code>null</code>). * @abstract - * @return string + * @return array */ function getBeanNames(); } \ No newline at end of file Modified: trunk/framework/Bee/Context/Config/IScope.php =================================================================== --- trunk/framework/Bee/Context/Config/IScope.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/IScope.php 2015-03-12 18:01:07 UTC (rev 300) @@ -31,7 +31,7 @@ * @param IObjectFactory $objectFactory * @return Object */ - public function get($beanName, IObjectFactory $objectFactory); + public function &get($beanName, IObjectFactory $objectFactory); /** * Enter description here... Modified: trunk/framework/Bee/Context/Config/RuntimeBeanNameReference.php =================================================================== --- trunk/framework/Bee/Context/Config/RuntimeBeanNameReference.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/RuntimeBeanNameReference.php 2015-03-12 18:01:07 UTC (rev 300) @@ -44,7 +44,7 @@ /** * Enter description here... * - * @return String + * @return array */ public function getBeanNames() { return $this->beanNames; Modified: trunk/framework/Bee/Context/Config/RuntimeBeanReference.php =================================================================== --- trunk/framework/Bee/Context/Config/RuntimeBeanReference.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/RuntimeBeanReference.php 2015-03-12 18:01:07 UTC (rev 300) @@ -55,7 +55,7 @@ /** * Enter description here... * - * @return String + * @return array */ public function getBeanNames() { return $this->beanNames; Modified: trunk/framework/Bee/Context/Config/Scope/CacheScope.php =================================================================== --- trunk/framework/Bee/Context/Config/Scope/CacheScope.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/Scope/CacheScope.php 2015-03-12 18:01:07 UTC (rev 300) @@ -34,7 +34,7 @@ $this->id = $id; } - public function get($beanName, IObjectFactory $objectFactory) { + public function &get($beanName, IObjectFactory $objectFactory) { return Manager::retrieveCachable(new CachableConfig($this->getCacheKey($beanName), $objectFactory)); } Modified: trunk/framework/Bee/Context/Config/Scope/PrototypeScope.php =================================================================== --- trunk/framework/Bee/Context/Config/Scope/PrototypeScope.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/Scope/PrototypeScope.php 2015-03-12 18:01:07 UTC (rev 300) @@ -38,7 +38,7 @@ * @param IObjectFactory $objectFactory * @return mixed|Object */ - public function get($beanName, IObjectFactory $objectFactory) { + public function &get($beanName, IObjectFactory $objectFactory) { return $objectFactory->getObject(); } Modified: trunk/framework/Bee/Context/Config/Scope/RequestScope.php =================================================================== --- trunk/framework/Bee/Context/Config/Scope/RequestScope.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Context/Config/Scope/RequestScope.php 2015-03-12 18:01:07 UTC (rev 300) @@ -43,7 +43,7 @@ * @param IObjectFactory $objectFactory * @return mixed|Object */ - public function get($beanName, IObjectFactory $objectFactory) { + public function &get($beanName, IObjectFactory $objectFactory) { $scopedObject =& $this->beans[$beanName]; if(is_null($scopedObject)) { $scopedObject = $objectFactory->getObject(); Modified: trunk/framework/Bee/MVC/Session/DispatcherAdapter.php =================================================================== --- trunk/framework/Bee/MVC/Session/DispatcherAdapter.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/MVC/Session/DispatcherAdapter.php 2015-03-12 18:01:07 UTC (rev 300) @@ -19,7 +19,7 @@ use Bee\IContext; use Exception; -class DispatcherAdapter { +class DispatcherAdapter /*implements SessionHandlerInterface*/ { const SESSION_HANDLER_NAME = '__sessionHandler'; Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-07 00:52:12 UTC (rev 299) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-12 18:01:07 UTC (rev 300) @@ -396,9 +396,10 @@ * @param string $fieldPath * @return QueryBuilder for chaining */ - protected final function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $fieldPath) { - if (array_key_exists($fieldPath, $filters)) { - if (!is_array($catIds = $filters[$fieldPath])) { + protected final function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $fieldPath, $filterName = false) { + $filterName = $filterName ?: $fieldPath; + if (array_key_exists($filterName, $filters)) { + if (!is_array($catIds = $filters[$filterName])) { $catIds = array_filter(explode(',', $catIds)); } if (count($catIds) > 0) { @@ -423,6 +424,24 @@ return $queryBuilder; } + /** + * @param QueryBuilder $queryBuilder + * @param $filters + * @param $fldExpr + * @param bool $filterKeyFrom + * @param bool $filterKeyUntil + */ + protected function addDateRestriction(QueryBuilder $queryBuilder, $filters, $fldExpr, $filterKeyFrom = false, $filterKeyUntil = false) { + $filterKeyFrom = $filterKeyFrom ?: $fldExpr . 'From'; + if (array_key_exists($filterKeyFrom, $filters) && $date = DateTimeHelper::parseDate($filters[$filterKeyFrom])) { + $queryBuilder->andWhere($this->internalizeFieldExpression($fldExpr, $queryBuilder) . ' >= :dateFrom')->setParameter('dateFrom', $date); + } + $filterKeyUntil = $filterKeyUntil ?: $fldExpr . 'Until'; + if (array_key_exists($filterKeyUntil, $filters) && $date = DateTimeHelper::parseDate($filters[$filterKeyUntil])) { + $queryBuilder->andWhere($this->internalizeFieldExpression($fldExpr, $queryBuilder) . ' <= :dateUntil')->setParameter('dateUntil', $date); + } + } + // ================================================================================================================= // == GETTERS & SETTERS ============================================================================================ // ================================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-07 00:52:15
|
Revision: 299 http://sourceforge.net/p/beeframework/code/299 Author: m_plomer Date: 2015-03-07 00:52:12 +0000 (Sat, 07 Mar 2015) Log Message: ----------- Persistence: - DaoBase: rework Modified Paths: -------------- trunk/framework/Bee/Context/AbstractContext.php trunk/framework/Bee/Context/Config/Scope/SessionScope.php trunk/framework/Bee/MVC/HttpRequest.php trunk/framework/Bee/MVC/IHttpRequest.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php trunk/framework/Bee/Persistence/PaginationBase.php Added Paths: ----------- trunk/framework/Bee/Persistence/Doctrine2/PaginatingDao.php Removed Paths: ------------- trunk/framework/Bee/Persistence/Doctrine/ trunk/framework/Bee/Persistence/Doctrine2/AbstractGenericDao.php trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php Modified: trunk/framework/Bee/Context/AbstractContext.php =================================================================== --- trunk/framework/Bee/Context/AbstractContext.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/Context/AbstractContext.php 2015-03-07 00:52:12 UTC (rev 299) @@ -649,7 +649,7 @@ * @throws BeanNotOfRequiredTypeException * @throws Exception */ - public function getBean($name, $requiredType = null) { + public function &getBean($name, $requiredType = null) { $beanName = $this->transformedBeanName($name); @@ -684,7 +684,7 @@ // @todo: catch IllegalStateException in case scope is not active (e.g. no session started...) // not needed for session, request, prototype scopes but maybe for fancy new scope implementations... - $scopedInstance = $scope->get($beanName, new AbstractContext_ObjectFactoryImpl($beanName, $localBeanDefinition, $this)); + $scopedInstance =& $scope->get($beanName, new AbstractContext_ObjectFactoryImpl($beanName, $localBeanDefinition, $this)); $bean = $this->getObjectForBeanInstance($scopedInstance, $name, $beanName, $localBeanDefinition); @@ -706,8 +706,8 @@ * @throws BeanIsNotAFactoryException * @return object the object to expose for the bean */ - protected function getObjectForBeanInstance( - $beanInstance, $name, $beanName, IBeanDefinition $mbd) { + protected function &getObjectForBeanInstance( + &$beanInstance, $name, $beanName, IBeanDefinition $mbd) { // Don't let calling code try to dereference the factory if the bean isn't a factory. if (ContextUtils::isFactoryDereference($name) && !($beanInstance instanceof IFactoryBean)) { Modified: trunk/framework/Bee/Context/Config/Scope/SessionScope.php =================================================================== --- trunk/framework/Bee/Context/Config/Scope/SessionScope.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/Context/Config/Scope/SessionScope.php 2015-03-07 00:52:12 UTC (rev 299) @@ -45,7 +45,7 @@ * @param IObjectFactory $objectFactory * @return mixed|Object */ - public function get($beanName, IObjectFactory $objectFactory) { + public function &get($beanName, IObjectFactory $objectFactory) { $beans =& $_SESSION[$this->id.self::SESSION_SCOPE_PREFIX]; $scopedObject =& $beans[$beanName]; if(is_null($scopedObject)) { Modified: trunk/framework/Bee/MVC/HttpRequest.php =================================================================== --- trunk/framework/Bee/MVC/HttpRequest.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/MVC/HttpRequest.php 2015-03-07 00:52:12 UTC (rev 299) @@ -223,4 +223,8 @@ public function getAjax() { return $this->ajax; } + + function __toString() { + return 'HttpRequest{' . $this->getMethod() . '|' . $this->getPathInfo() . '|ajax:' . $this->getAjax() . '}'; + } } Modified: trunk/framework/Bee/MVC/IHttpRequest.php =================================================================== --- trunk/framework/Bee/MVC/IHttpRequest.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/MVC/IHttpRequest.php 2015-03-07 00:52:12 UTC (rev 299) @@ -107,4 +107,9 @@ * @return bool */ public function getAjax(); + + /** + * @return string + */ + public function __toString(); } \ No newline at end of file Deleted: trunk/framework/Bee/Persistence/Doctrine2/AbstractGenericDao.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/AbstractGenericDao.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/Persistence/Doctrine2/AbstractGenericDao.php 2015-03-07 00:52:12 UTC (rev 299) @@ -1,130 +0,0 @@ -<?php -namespace Bee\Persistence\Doctrine2; -/* - * Copyright 2008-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use Doctrine\ORM\Query; -use Doctrine\ORM\QueryBuilder; -use UnexpectedValueException; - -/** - * User: mp - * Date: 02.09.13 - * Time: 20:35 - */ - -abstract class AbstractGenericDao extends DaoBase { - - /** - * @param mixed $id - * @throws UnexpectedValueException - * @return mixed - */ - public function getById($id) { - $qb = $this->getBaseQuery(); - $this->applyWhereId($id, $qb); - return $this->getSingleResult($qb); - } - - /** - * @param QueryBuilder $qb - * @return mixed - */ - protected function getSingleResult(QueryBuilder $qb) { - $q = $qb->getQuery(); - $this->decorateQuery($q); - return $q->getSingleResult($this->getHydrationMode()); - } - - /** - * @param Query $q - */ - protected function decorateQuery(Query $q) { - } - - /** - * @return QueryBuilder - */ - protected function getBaseQuery() { - $baseEntityAlias = $this->getEntityAlias(); - $indexBy = count($this->getIdFieldName()) > 1 ? null : $baseEntityAlias . '.' . $this->getIdFieldName(); - return $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias) - ->from($this->getEntity(), $baseEntityAlias, $indexBy); - } - - /** - * @return string - */ - protected function getEntityAlias() { - return 'e'; - } - - /** - * @return null - */ - protected function getHydrationMode() { - return null; - } - - /** - * @return string - */ - public abstract function getEntity(); - - /** - * @return string|array - */ - protected function getIdFieldName() { - $classMetadata = $this->getEntityManager()->getClassMetadata($this->getEntity()); - $idFields = $classMetadata->getIdentifierFieldNames(); - return count($idFields) > 1 ? $idFields : $idFields[0]; - } - - /** - * @param mixed $id - * @param QueryBuilder $qb - * @throws \UnexpectedValueException - */ - protected function applyWhereId($id, QueryBuilder $qb) { - $idFields = $this->getIdFieldName(); - - $expectedDim = count($idFields); - $actualDim = count($id); - - // unpack single-valued id if necessary - if (is_array($id) && $actualDim === 1) { - $id = $id[0]; - } - - $baseEntityAlias = $this->getEntityAlias(); - if ($expectedDim > 1) { - // composite key - if ($actualDim === 1) { - $id = DaoUtils::explodeScalarId($id, $idFields); - } else if ($actualDim !== $expectedDim) { - throw new UnexpectedValueException('Dimension of given ID (' . count($id) . ') does not match expected dimension (' . count($idFields) . ').'); - } - - // here we can be sure that the dimensions match - both branches above would have thrown otherwise - $whereParts = array(); - array_walk($id, function ($value, $key) use ($baseEntityAlias, &$whereParts) { - $whereParts[] = $baseEntityAlias . '.' . $key . ' = ' . ':' . $key; - }); - $qb->where(implode(' AND ', $whereParts))->setParameters($id); - } else { - $qb->where($baseEntityAlias . '.' . $idFields . ' = :id')->setParameter('id', $id); - } - } -} Deleted: trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-03-07 00:52:12 UTC (rev 299) @@ -1,171 +0,0 @@ -<?php -namespace Bee\Persistence\Doctrine2; - -/* - * Copyright 2008-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use Bee\Persistence\IOrderAndLimitHolder; -use Bee\Persistence\IRestrictionHolder; -use Bee\Utils\Strings; -use Doctrine\ORM\Query; -use Doctrine\ORM\QueryBuilder; -use Doctrine\ORM\Tools\Pagination\Paginator; -use Exception; - -/** - * User: mp - * Date: 05.05.13 - * Time: 17:26 - */ -class DaoBase extends EntityManagerHolder { - - /** - * @param QueryBuilder $queryBuilder - * @param IRestrictionHolder $restrictionHolder - * @param IOrderAndLimitHolder $orderAndLimitHolder - * @param array $defaultOrderMapping - * @param null $hydrationMode - * @return array - */ - public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { - $this->applyFilterRestrictions($queryBuilder, $restrictionHolder); - $this->applyOrderMapping($queryBuilder, $orderAndLimitHolder, $defaultOrderMapping); - $q = $this->getQueryFromBuilder($queryBuilder); - if(!is_null($hydrationMode)) { - $q->setHydrationMode($hydrationMode); - } - return $this->getPaginatedOrderedResultFromQuery($q, $orderAndLimitHolder); - } - - /** - * @param QueryBuilder $qb - * @return Query - */ - protected function getQueryFromBuilder(QueryBuilder $qb) { - return $qb->getQuery(); - } - - /** - * todo: give this a proper name. This method ONLY applies the text filter (and is only ever intended to do so). All - * todo: other filters are use-case- (or at least entity-) specific. - * @param QueryBuilder $queryBuilder - * @param IRestrictionHolder $restrictionHolder - */ - protected final function applyFilterRestrictions(QueryBuilder &$queryBuilder, IRestrictionHolder $restrictionHolder = null) { - if (is_null($restrictionHolder)) { - return; - } - - if (!Strings::hasText($restrictionHolder->getFilterString())) { - return; - } - - $filterTokens = Strings::tokenizeToArray($restrictionHolder->getFilterString(), ' '); - foreach ($filterTokens as $no => $token) { - $andWhereString = ''; - $params = array(); - - $tokenName = 'filtertoken' . $no; - $params[$tokenName] = '%' . $token . '%'; - foreach ($restrictionHolder->getFilterableFields() as $fieldName) { - // $fieldName MUST BE A DOCTRINE NAME - if (Strings::hasText($andWhereString)) { - $andWhereString .= ' OR '; - } - - $andWhereString .= $fieldName . ' LIKE :' . $tokenName; - } - if (Strings::hasText($andWhereString)) { - $queryBuilder->andWhere($andWhereString); - - foreach ($params as $key => $value) { - $queryBuilder->setParameter($key, $value); - } - } - } - } - - /** - * @param QueryBuilder $queryBuilder - * @param IOrderAndLimitHolder $orderAndLimitHolder - * @param array $defaultOrderMapping - */ - protected final function applyOrderMapping(QueryBuilder &$queryBuilder, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null) { - if (is_null($defaultOrderMapping)) { - $defaultOrderMapping = array(); - } - if (is_null($orderAndLimitHolder)) { - $orderMapping = $defaultOrderMapping; - } else { - $orderMapping = count($orderAndLimitHolder->getOrderMapping()) > 0 ? $orderAndLimitHolder->getOrderMapping() : $defaultOrderMapping; - } - - foreach ($orderMapping as $orderField => $orderDir) { - $queryBuilder->addOrderBy($orderField, $orderDir); - } - } - - /** - * @param callback $func - * @throws Exception - * @return mixed - * - * @deprecated use EntityManagerHolder::transactional() instead - */ - public function doInTransaction($func) { - $this->getLog()->info('Begin transaction.'); - $this->getEntityManager()->beginTransaction(); - try { - $result = $func($this, $this->getLog()); - - $this->getLog()->info('Transaction committing...'); - - $this->getEntityManager()->commit(); - $this->getEntityManager()->flush(); - - $this->getLog()->info('Transaction committed!'); - return $result; - } catch (Exception $e) { - $this->getLog()->warn('Exception caught, rolling back!', $e); - $this->getEntityManager()->rollBack(); - throw $e; - } - } - - /** - * @param Query $q - * @param IOrderAndLimitHolder $orderAndLimitHolder - * @return array|Paginator - */ - protected function getPaginatedOrderedResultFromQuery(Query $q, IOrderAndLimitHolder $orderAndLimitHolder = null) { - if (!is_null($orderAndLimitHolder) && $orderAndLimitHolder->getPageSize() > 0) { - $q->setFirstResult($orderAndLimitHolder->getCurrentPage() * $orderAndLimitHolder->getPageSize()); - $q->setMaxResults($orderAndLimitHolder->getPageSize()); - $paginator = new JsonSerializablePaginator($q, $this->useWhereInPagination()); - $paginator->setUseOutputWalkers(false); - $orderAndLimitHolder->setResultCount(count($paginator)); - return $paginator; - } else { - return $q->getResult($q->getHydrationMode()); - } - } - - /** - * @return bool - */ - protected function useWhereInPagination() { - return true; - } -} Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-07 00:52:12 UTC (rev 299) @@ -2,7 +2,6 @@ namespace Bee\Persistence\Doctrine2; use Bee\Persistence\IOrderAndLimitHolder; -use Bee\Persistence\IRestrictionHolder; use Bee\Utils\Assert; use Bee\Utils\Strings; use Doctrine\ORM\QueryBuilder; @@ -12,8 +11,11 @@ * Class GenericDaoBase * @package Bee\Persistence\Doctrine2 */ -abstract class GenericDaoBase extends DaoBase { +abstract class GenericDaoBase extends PaginatingDao { + const FILTER_STRING = 'filterString'; + const FILTER_STRING_FIELDS = 'filterStringFields'; + /** * @var callable */ @@ -121,71 +123,132 @@ } /** - * @param IRestrictionHolder $restrictionHolder + * @param mixed $filters * @param IOrderAndLimitHolder $orderAndLimitHolder * @param array $defaultOrderMapping * @return array */ - public function getList(IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null) { - return $this->executeListQuery($this->getBaseQuery(), $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping, null); + public function getList($filters = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { + $qb = $this->getBaseQuery(); + $this->applyFilterRestrictions($qb, $filters); + return $this->executeListQuery($qb, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); } /** - * @param QueryBuilder $queryBuilder - * @param IRestrictionHolder $restrictionHolder - * @param IOrderAndLimitHolder $orderAndLimitHolder - * @param array $defaultOrderMapping - * @param null $hydrationMode - * @return array + * @param null $entity + * @return QueryBuilder */ - public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { - if (!is_null($restrictionHolder)) { - $internalFilterableFields = array(); - if (Strings::hasText($restrictionHolder->getFilterString())) { - $this->disaggregateAndInternalizeFieldList($restrictionHolder->getFilterableFields(), $internalFilterableFields, $queryBuilder); - } -// $internalFilters = array(); -// if (count($restrictionHolder->getFilters()) > 0) { -// $this->internalizeFieldValueMapping($restrictionHolder->getFilters(), $internalFilters, $queryBuilder); -// } - $restrictionHolder = new GenericDaoBase_RestrictionWrapper($restrictionHolder, $internalFilterableFields); + protected function getBaseQuery($entity = null) { + $baseEntityAlias = $this->getEntityAlias(); + $entity = $entity ?: $this->getEntity(); +// $indexBy = count($this->getIdFieldName()) > 1 ? null : $baseEntityAlias . '.' . $this->getIdFieldName(); +// return $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias) +// ->from($this->getEntity(), $baseEntityAlias, $indexBy); + $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); + $this->addJoinsToBaseQuery($qb); + $this->addRestrictionsToBaseQuery($qb); + return $qb; + } + + /** + * @param QueryBuilder $q + */ + protected function addJoinsToBaseQuery(QueryBuilder $q) { + foreach ($this->joins as $join) { + $this->internalizePathExpression($join, $q, true); } + } - if (!is_null($orderAndLimitHolder)) { - if (count($orderAndLimitHolder->getOrderMapping()) > 0) { - $internalMapping = array(); - $this->disaggregateAndInternalizeFieldValueMapping($orderAndLimitHolder->getOrderMapping(), $internalMapping, $queryBuilder); - $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); - } + /** + * @param QueryBuilder $q + */ + protected function addRestrictionsToBaseQuery(QueryBuilder $q) { + foreach ($this->restrictions as $restriction) { + $q->andWhere($restriction); } + } - return parent::executeListQuery($queryBuilder, $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); + /** + * @param QueryBuilder $qb + * @return mixed + */ + protected function getSingleResult(QueryBuilder $qb) { + $q = $this->getQueryFromBuilder($qb); + return $q->getSingleResult($this->getHydrationMode()); } /** + * @return null|string + */ + protected function getHydrationMode() { + return null; + } + + /** + * @return string + */ + protected function getEntityAlias() { + return 'e'; + } + + /** + * @return mixed + */ + abstract protected function getIdFieldName(); + + /** + * @return string + */ + public abstract function getEntity(); + + /** + * @return null + */ + protected function getIndexBy() { + return null; + } + + // ================================================================================================================= + // == Field disaggregation and canonicalization ==================================================================== + // ================================================================================================================= + + /** + * @param QueryBuilder $queryBuilder + * @param array $orderMapping + * @return QueryBuilder + */ + protected function applyOrderMapping(QueryBuilder $queryBuilder, array $orderMapping = array()) { + return parent::applyOrderMapping($queryBuilder, $this->disaggregateAndInternalizeFieldValueMapping($orderMapping, $queryBuilder)); + } + + /** * @param array $externalFieldValueMapping * @param array $internalFieldValueMapping * @param QueryBuilder $queryBuilder + * @return array */ - protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, array &$internalFieldValueMapping, QueryBuilder $queryBuilder) { + protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, QueryBuilder $queryBuilder, array &$internalFieldValueMapping = array()) { foreach ($externalFieldValueMapping as $field => $value) { array_walk($this->getFieldDisaggregation($field), function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { $internalFieldValueMapping[$this->internalizeFieldExpression($field, $queryBuilder)] = $value; }); } + return $internalFieldValueMapping; } /** * @param array $externalFieldList + * @param QueryBuilder $queryBuilder * @param array $internalFieldList - * @param QueryBuilder $queryBuilder + * @return array */ - protected final function disaggregateAndInternalizeFieldList(array $externalFieldList, array &$internalFieldList, QueryBuilder $queryBuilder) { + protected final function disaggregateAndInternalizeFieldList(array $externalFieldList, QueryBuilder $queryBuilder, array &$internalFieldList = array()) { foreach ($externalFieldList as $field) { $internalFieldList = array_merge($internalFieldList, array_map(function ($field) use (&$queryBuilder) { return $this->internalizeFieldExpression($field, $queryBuilder); }, $this->getFieldDisaggregation($field))); } + return $internalFieldList; } /** @@ -268,86 +331,72 @@ return $pathExpr; } - /** - * @param null $entity - * @return QueryBuilder - */ - protected function getBaseQuery($entity = null) { - $baseEntityAlias = $this->getEntityAlias(); - $entity = $entity ?: $this->getEntity(); -// $indexBy = count($this->getIdFieldName()) > 1 ? null : $baseEntityAlias . '.' . $this->getIdFieldName(); -// return $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias) -// ->from($this->getEntity(), $baseEntityAlias, $indexBy); - $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); - $this->addJoinsToBaseQuery($qb); - $this->addRestrictionsToBaseQuery($qb); - return $qb; - } + // ================================================================================================================= + // == Filtering helpers ============================================================================================ + // ================================================================================================================= /** - * @param QueryBuilder $q + * Apply the filter restrictions defined by the filters array to the given QueryBuilder. + * + * Intended to be overridden by subclasses. The default implementation only applies a string filter if defined. + * + * @param QueryBuilder $queryBuilder + * @param mixed $filters + * @return QueryBuilder for chaining */ - protected function addJoinsToBaseQuery(QueryBuilder $q) { - foreach ($this->joins as $join) { - $this->internalizePathExpression($join, $q, true); + protected function applyFilterRestrictions(QueryBuilder &$queryBuilder, $filters = null) { + if (!is_null($filters)) { + if(array_key_exists(self::FILTER_STRING, $filters) && Strings::hasText($filterString = $filters[self::FILTER_STRING])) { + $this->addStringFilterRestrictions($queryBuilder, $filterString, $filters[self::FILTER_STRING_FIELDS]); + } } + return $queryBuilder; } /** - * @param QueryBuilder $q + * @param QueryBuilder $queryBuilder + * @param string $filterString + * @param array $filterableFields + * @return QueryBuilder */ - protected function addRestrictionsToBaseQuery(QueryBuilder $q) { - foreach ($this->restrictions as $restriction) { - $q->andWhere($restriction); - } - } + protected function addStringFilterRestrictions(QueryBuilder $queryBuilder, $filterString, array $filterableFields = array()) { + if (Strings::hasText($filterString)) { + $filterableFields = $this->disaggregateAndInternalizeFieldList($filterableFields, $queryBuilder); - /** - * @param QueryBuilder $qb - * @return mixed - */ - protected function getSingleResult(QueryBuilder $qb) { - $q = $this->getQueryFromBuilder($qb); - return $q->getSingleResult($this->getHydrationMode()); - } + $filterTokens = Strings::tokenizeToArray($filterString, ' '); + foreach ($filterTokens as $no => $token) { + $andWhereString = ''; + $params = array(); - /** - * @return null|string - */ - protected function getHydrationMode() { - return null; - } + $tokenName = 'filtertoken' . $no; + $params[$tokenName] = '%' . $token . '%'; + foreach ($filterableFields as $fieldName) { + // $fieldName MUST BE A DOCTRINE NAME + if (Strings::hasText($andWhereString)) { + $andWhereString .= ' OR '; + } - /** - * @return string - */ - protected function getEntityAlias() { - return 'e'; - } + $andWhereString .= $fieldName . ' LIKE :' . $tokenName; + } + if (Strings::hasText($andWhereString)) { + $queryBuilder->andWhere($andWhereString); - /** - * @return mixed - */ - abstract protected function getIdFieldName(); - - /** - * @return string - */ - public abstract function getEntity(); - - /** - * @return null - */ - protected function getIndexBy() { - return null; + foreach ($params as $key => $value) { + $queryBuilder->setParameter($key, $value); + } + } + } + } + return $queryBuilder; } /** * @param QueryBuilder $queryBuilder * @param $filters * @param string $fieldPath + * @return QueryBuilder for chaining */ - protected function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $fieldPath) { + protected final function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $fieldPath) { if (array_key_exists($fieldPath, $filters)) { if (!is_array($catIds = $filters[$fieldPath])) { $catIds = array_filter(explode(',', $catIds)); @@ -356,6 +405,7 @@ $queryBuilder->andWhere($queryBuilder->expr()->in('IDENTITY(' . $this->internalizeFieldExpression($fieldPath, $queryBuilder) . ')', $catIds)); } } + return $queryBuilder; } /** @@ -363,12 +413,14 @@ * @param array $filters * @param string $fieldExpr * @param string $filterKey + * @return QueryBuilder for chaining */ - protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '') { + protected final function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '') { $filterKey = $filterKey ?: $fieldExpr; if (array_key_exists($filterKey, $filters) && $value = $filters[$filterKey]) { $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . ' = :val')->setParameter('val', $value); } + return $queryBuilder; } // ================================================================================================================= @@ -456,107 +508,4 @@ } return array($aggregateFieldName); } -} - -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); - } -} - -class GenericDaoBase_RestrictionWrapper implements IRestrictionHolder { - - /** - * @var IRestrictionHolder - */ - private $wrappedRestrictionHolder; - - /** - * @var array - */ - private $internalFilterableFields; - - /** - * @param $wrappedRestrictionHolder - * @param $internalFilterableFields - */ - function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields/*, array $internalFilters*/) { - $this->wrappedRestrictionHolder = $wrappedRestrictionHolder; - $this->internalFilterableFields = $internalFilterableFields; - } - - /** - * @return array - */ - public function getFilterableFields() { - return $this->internalFilterableFields; - } - - /** - * @return array - */ - public function getFilterString() { - return $this->wrappedRestrictionHolder->getFilterString(); - } - - /** - * @return array - */ - public function getFilters() { - return $this->wrappedRestrictionHolder->getFilters(); - } } \ No newline at end of file Added: trunk/framework/Bee/Persistence/Doctrine2/PaginatingDao.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/PaginatingDao.php (rev 0) +++ trunk/framework/Bee/Persistence/Doctrine2/PaginatingDao.php 2015-03-07 00:52:12 UTC (rev 299) @@ -0,0 +1,124 @@ +<?php +namespace Bee\Persistence\Doctrine2; + +/* + * Copyright 2008-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +use Bee\Persistence\IOrderAndLimitHolder; +use Doctrine\ORM\Query; +use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\Tools\Pagination\Paginator; +use Exception; + +/** + * User: mp + * Date: 05.05.13 + * Time: 17:26 + */ +class PaginatingDao extends EntityManagerHolder { + + /** + * @param QueryBuilder $queryBuilder + * @param IOrderAndLimitHolder $orderAndLimitHolder + * @param array $defaultOrderMapping + * @param null $hydrationMode + * @return array + */ + protected final function executeListQuery(QueryBuilder $queryBuilder, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = array(), $hydrationMode = null) { + if (is_null($orderAndLimitHolder)) { + $orderMapping = $defaultOrderMapping; + } else { + $orderMapping = count($orderAndLimitHolder->getOrderMapping()) > 0 ? $orderAndLimitHolder->getOrderMapping() : $defaultOrderMapping; + } + $this->applyOrderMapping($queryBuilder, $orderMapping); + $q = $this->getQueryFromBuilder($queryBuilder); + if(!is_null($hydrationMode)) { + $q->setHydrationMode($hydrationMode); + } + return $this->getPaginatedOrderedResultFromQuery($q, $orderAndLimitHolder); + } + + /** + * @param QueryBuilder $qb + * @return Query + */ + protected function getQueryFromBuilder(QueryBuilder $qb) { + return $qb->getQuery(); + } + + /** + * @param QueryBuilder $queryBuilder + * @param array $orderMapping + * @return QueryBuilder + */ + protected function applyOrderMapping(QueryBuilder $queryBuilder, array $orderMapping = array()) { + foreach ($orderMapping as $orderField => $orderDir) { + $queryBuilder->addOrderBy($orderField, $orderDir); + } + return $queryBuilder; + } + + /** + * @param callback $func + * @throws Exception + * @return mixed + * + * @deprecated use EntityManagerHolder::transactional() instead + */ + public function doInTransaction($func) { + $this->getLog()->info('Begin transaction.'); + $this->getEntityManager()->beginTransaction(); + try { + $result = $func($this, $this->getLog()); + + $this->getLog()->info('Transaction committing...'); + + $this->getEntityManager()->commit(); + $this->getEntityManager()->flush(); + + $this->getLog()->info('Transaction committed!'); + return $result; + } catch (Exception $e) { + $this->getLog()->warn('Exception caught, rolling back!', $e); + $this->getEntityManager()->rollBack(); + throw $e; + } + } + + /** + * @param Query $q + * @param IOrderAndLimitHolder $orderAndLimitHolder + * @return array|Paginator + */ + protected function getPaginatedOrderedResultFromQuery(Query $q, IOrderAndLimitHolder $orderAndLimitHolder = null) { + if (!is_null($orderAndLimitHolder) && $orderAndLimitHolder->getPageSize() > 0) { + $q->setFirstResult($orderAndLimitHolder->getCurrentPage() * $orderAndLimitHolder->getPageSize()); + $q->setMaxResults($orderAndLimitHolder->getPageSize()); + $paginator = new JsonSerializablePaginator($q, $this->useWhereInPagination()); + $paginator->setUseOutputWalkers(false); + $orderAndLimitHolder->setResultCount(count($paginator)); + return $paginator; + } else { + return $q->getResult($q->getHydrationMode()); + } + } + + /** + * @return bool + */ + protected function useWhereInPagination() { + return true; + } +} Modified: trunk/framework/Bee/Persistence/PaginationBase.php =================================================================== --- trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-05 17:00:03 UTC (rev 298) +++ trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-07 00:52:12 UTC (rev 299) @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use ArrayAccess; use JsonSerializable; /** @@ -25,33 +26,23 @@ */ abstract class PaginationBase implements IOrderAndLimitHolder, JsonSerializable { - /** - * @var int - */ - private $pageSize = 50; + /** + * @var ArrayAccess | array + */ + private $state = array(); /** - * @var int - */ - private $currentPage = 0; - - /** - * @var int - */ - private $resultCount; - - /** * @return int */ public function getPageSize() { - return $this->pageSize; + return $this->state['pageSize']; } /** * @param int $pageSize */ public function setPageSize($pageSize) { - $this->pageSize = intval($pageSize); + $this->state['pageSize'] = intval($pageSize); } /** @@ -65,7 +56,7 @@ * @return int */ public function getCurrentPage() { - return $this->currentPage; + return $this->state['currentPage']; } /** @@ -73,14 +64,14 @@ */ public function setCurrentPage($currentPage) { $currentPage = intval($currentPage); - $this->currentPage = $currentPage < 0 ? 0 : $currentPage; + $this->state['currentPage'] = $currentPage < 0 ? 0 : $currentPage; } /** * @param int $resultCount */ public function setResultCount($resultCount) { - $this->resultCount = intval($resultCount); + $this->state['resultCount'] = intval($resultCount); if($this->getCurrentPage() >= $this->getPageCount()) { $this->adjustCurrentPageOnOverflow(); } @@ -90,7 +81,7 @@ * @return int */ public function getResultCount() { - return $this->resultCount; + return $this->state['resultCount']; } /** @@ -102,6 +93,20 @@ } /** + * @return array|ArrayAccess + */ + public function getState() { + return $this->state; + } + + /** + * @param array|ArrayAccess $state + */ + public function setState($state) { + $this->state = $state; + } + + /** * @return array */ function jsonSerialize() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-05 17:00:10
|
Revision: 298 http://sourceforge.net/p/beeframework/code/298 Author: m_plomer Date: 2015-03-05 17:00:03 +0000 (Thu, 05 Mar 2015) Log Message: ----------- Tagged last PHP5.3 compatible version Added Paths: ----------- tags/0.10.2-beta/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-04 11:42:02
|
Revision: 297 http://sourceforge.net/p/beeframework/code/297 Author: m_plomer Date: 2015-03-04 11:41:59 +0000 (Wed, 04 Mar 2015) Log Message: ----------- Persistence: - GenericDaoBase: fixed handling of already-prefixed fields / function expressions during field disaggregation / canonicalization Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-04 11:14:17 UTC (rev 296) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-04 11:41:59 UTC (rev 297) @@ -196,18 +196,18 @@ */ protected final function internalizeFieldExpression($fieldExpr, QueryBuilder $queryBuilder, $join = false) { // ex: $fieldExpr = 'e.hochschultyp.kategorie.promotionsrecht' - $dotPos = strrpos($fieldExpr, '.'); // 24 - $fieldName = substr($fieldExpr, $dotPos + 1); // 'promotionsrecht' - $pathExpr = substr($fieldExpr, 0, $dotPos); // 'e.hochschultyp.kategorie' + preg_match('#^(?:([\w.]*)\.)?(.*?)$#', $fieldExpr, $matches); + $pathExpr = $matches[1]; // 'e.hochschultyp.kategorie' + $fieldName = $matches[2]; // 'promotionsrecht' - if($pathExpr != $this->getEntityAlias()) { + if ($pathExpr && $pathExpr != $this->getEntityAlias()) { Assert::isTrue(array_key_exists($pathExpr, $this->reverseAliases), 'Unknown path expression "' . $pathExpr . '"'); $this->internalizePathExpression($pathExpr, $queryBuilder, $join); $pathExpr = $this->reverseAliases[$pathExpr]; } // ex: return e4.promotionsrecht - return $pathExpr . '.' . $fieldName; + return ($pathExpr ? $pathExpr . '.' : '') . $fieldName; } /** @@ -221,10 +221,10 @@ // ex (Rc2): $pathExpr = 'e.hochschultyp' // ex (Rc3): $pathExpr = 'e' - if(($dotPos = strrpos($pathExpr, '.')) !== false) { + if (($dotPos = strrpos($pathExpr, '.')) !== false) { $currentAlias = $this->reverseAliases[$pathExpr]; - if(!array_key_exists($currentAlias, $this->addedAliases)) { + if (!array_key_exists($currentAlias, $this->addedAliases)) { $currentAssociation = substr($pathExpr, $dotPos + 1); $pathExpr = substr($pathExpr, 0, $dotPos); @@ -250,7 +250,7 @@ // ex (Rc1): $currentAssociation = 'e1.kategorie' $queryBuilder->leftJoin($currentAssociation, $currentAlias); - if($fetchJoin) { + if ($fetchJoin) { $queryBuilder->addSelect($currentAlias); } $this->addedAliases[$currentAlias] = $currentAssociation; @@ -448,7 +448,7 @@ */ protected function getFieldDisaggregation($aggregateFieldName) { // prefix only if simple path expression not prefixed with entity alias and not a function expression - if(!preg_match('#^(?:' . $this->getEntityAlias() . '\.|\w+\()#', $aggregateFieldName)) { + if (!preg_match('#^(?:' . $this->getEntityAlias() . '\.|\w+\()#', $aggregateFieldName)) { $aggregateFieldName = $this->getEntityAlias() . '.' . $aggregateFieldName; } if (array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-04 11:14:19
|
Revision: 296 http://sourceforge.net/p/beeframework/code/296 Author: m_plomer Date: 2015-03-04 11:14:17 +0000 (Wed, 04 Mar 2015) Log Message: ----------- Persistence: - GenericDaoBase: fixed handling of already-prefixed fields / function expressions during field disaggregation / canonicalization Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-03 07:12:13 UTC (rev 295) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-04 11:14:17 UTC (rev 296) @@ -166,11 +166,10 @@ * @param array $externalFieldValueMapping * @param array $internalFieldValueMapping * @param QueryBuilder $queryBuilder - * @param string $prefix */ - protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, array &$internalFieldValueMapping, QueryBuilder $queryBuilder, $prefix = '') { + protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, array &$internalFieldValueMapping, QueryBuilder $queryBuilder) { foreach ($externalFieldValueMapping as $field => $value) { - array_walk($this->getFieldDisaggregation($field, $prefix), function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { + array_walk($this->getFieldDisaggregation($field), function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { $internalFieldValueMapping[$this->internalizeFieldExpression($field, $queryBuilder)] = $value; }); } @@ -180,14 +179,12 @@ * @param array $externalFieldList * @param array $internalFieldList * @param QueryBuilder $queryBuilder - * @param string $prefix */ - protected final function disaggregateAndInternalizeFieldList(array $externalFieldList, array &$internalFieldList, QueryBuilder $queryBuilder, $prefix = '') { - $prefix = $prefix ?: $this->getEntityAlias() . '.'; + protected final function disaggregateAndInternalizeFieldList(array $externalFieldList, array &$internalFieldList, QueryBuilder $queryBuilder) { foreach ($externalFieldList as $field) { - $internalFieldList = array_merge($internalFieldList, array_map(function ($field) use (&$queryBuilder, $prefix) { + $internalFieldList = array_merge($internalFieldList, array_map(function ($field) use (&$queryBuilder) { return $this->internalizeFieldExpression($field, $queryBuilder); - }, $this->getFieldDisaggregation($field, $prefix))); + }, $this->getFieldDisaggregation($field))); } } @@ -447,11 +444,13 @@ /** * @param $aggregateFieldName - * @param string $prefix * @return array */ - protected function getFieldDisaggregation($aggregateFieldName, $prefix = '') { - $aggregateFieldName = ($prefix ?: $this->getEntityAlias() . '.') . $aggregateFieldName; + protected function getFieldDisaggregation($aggregateFieldName) { + // prefix only if simple path expression not prefixed with entity alias and not a function expression + if(!preg_match('#^(?:' . $this->getEntityAlias() . '\.|\w+\()#', $aggregateFieldName)) { + $aggregateFieldName = $this->getEntityAlias() . '.' . $aggregateFieldName; + } if (array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { return $this->fieldDisaggregations[$aggregateFieldName]; } @@ -531,11 +530,6 @@ */ private $internalFilterableFields; -// /** -// * @var array -// */ -// private $internalFilters; - /** * @param $wrappedRestrictionHolder * @param $internalFilterableFields @@ -543,7 +537,6 @@ function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields/*, array $internalFilters*/) { $this->wrappedRestrictionHolder = $wrappedRestrictionHolder; $this->internalFilterableFields = $internalFilterableFields; -// $this->internalFilters = $internalFilters; } /** @@ -564,7 +557,6 @@ * @return array */ public function getFilters() { -// return $this->internalFilters; return $this->wrappedRestrictionHolder->getFilters(); } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-03 07:12:21
|
Revision: 295 http://sourceforge.net/p/beeframework/code/295 Author: m_plomer Date: 2015-03-03 07:12:13 +0000 (Tue, 03 Mar 2015) Log Message: ----------- Context: TContextAware: made interface method final Persistence: - GenericDaoBase: revamped alias handling - PaginationBase: now implements JsonSerializable interface - DaoBase: phpdoc update Modified Paths: -------------- trunk/framework/Bee/Context/Config/TContextAware.php trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php trunk/framework/Bee/Persistence/PaginationBase.php Modified: trunk/framework/Bee/Context/Config/TContextAware.php =================================================================== --- trunk/framework/Bee/Context/Config/TContextAware.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Context/Config/TContextAware.php 2015-03-03 07:12:13 UTC (rev 295) @@ -17,7 +17,7 @@ /** * @param IContext $context */ - public function setBeeContext(IContext $context) { + public final function setBeeContext(IContext $context) { $this->context = $context; } Modified: trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-03-03 07:12:13 UTC (rev 295) @@ -2,7 +2,7 @@ namespace Bee\Persistence\Doctrine2; /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,9 +58,10 @@ } /** + * todo: give this a proper name. This method ONLY applies the text filter (and is only ever intended to do so). All + * todo: other filters are use-case- (or at least entity-) specific. * @param QueryBuilder $queryBuilder * @param IRestrictionHolder $restrictionHolder - * @internal param QueryBuilder $query */ protected final function applyFilterRestrictions(QueryBuilder &$queryBuilder, IRestrictionHolder $restrictionHolder = null) { if (is_null($restrictionHolder)) { Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-03 07:12:13 UTC (rev 295) @@ -14,355 +14,422 @@ */ abstract class GenericDaoBase extends DaoBase { - const ALIAS_MATCHER = '#^([a-zA-Z0-9_]{2,})\.#'; + /** + * @var callable + */ + private $idRestrictor; - /** - * @var callable - */ - private $idRestrictor; + /** + * @var array + * + * ex: + * e0 => 'e.adresse', + * e1 => 'e.hochschultyp', + * e2 => 'e.adresse.land', + * e3 => 'e.adresse.verwaltungseinheit', + * e4 => 'e.hochschultyp.kategorie', + * e5 => 'e.adresse.land.regionen' + */ + private $aliases; - /** - * @var array - */ - private $aliases; - /** * @var array + * + * ex: + * 'e.adresse' => e0 + * 'e.hochschultyp' => e1 + * 'e.adresse.land', => e2 + * 'e.adresse.verwaltungseinheit' => e3 + * 'e.hochschultyp.kategorie' => e4 + * 'e.adresse.land.regionen' => e5 */ private $reverseAliases; - /** - * @var array - * - * todo: this is only for one-time use during a request. should be ok for MOST cases... - */ - private $addedAliases = array(); + /** + * @var array + */ + private $joins = array(); - /** - * @var array - */ - private $joins = array(); + /** + * @var array + */ + private $restrictions = array(); - /** - * @var array - */ - private $restrictions = array(); + /** + * @var array + */ + private $defaultOrderMapping = array(); - /** - * @var array - */ - private $defaultOrderMapping = array(); - /** * @var array */ private $fieldDisaggregations = array(); - /** - * @param mixed $id - * @throws UnexpectedValueException - * @return mixed - */ - public function getById($id) { - if(!is_callable($this->idRestrictor)) { - $idFields = $this->getIdFieldName(); + /** + * @var array + */ + private $addedAliases = array(); - $expectedDim = count($idFields); - $actualDim = count($id); + /** + * @param mixed $id + * @throws UnexpectedValueException + * @return mixed + */ + public function getById($id) { + if (!is_callable($this->idRestrictor)) { + $idFields = $this->getIdFieldName(); - // unpack single-valued id if necessary - if (is_array($id) && $actualDim === 1) { - $id = $id[0]; - } + $expectedDim = count($idFields); + $actualDim = count($id); - $baseEntityAlias = $this->getEntityAlias(); - if ($expectedDim > 1) { - // composite key - if ($actualDim === 1) { - $id = DaoUtils::explodeScalarId($id, $idFields); - } else if ($actualDim !== $expectedDim) { - throw new UnexpectedValueException('Dimension of given ID (' . count($id) . ') does not match expected dimension (' . count($idFields) . ').'); - } + // unpack single-valued id if necessary + if (is_array($id) && $actualDim === 1) { + $id = $id[0]; + } - // here we can be sure that the dimensions match - both branches above would have thrown otherwise - $whereParts = array(); - array_walk($id, function ($value, $key) use ($baseEntityAlias, &$whereParts) { - $whereParts[] = $baseEntityAlias . '.' . $key . ' = ' . ':' . $key; - }); + $baseEntityAlias = $this->getEntityAlias(); + if ($expectedDim > 1) { + // composite key + if ($actualDim === 1) { + $id = DaoUtils::explodeScalarId($id, $idFields); + } else if ($actualDim !== $expectedDim) { + throw new UnexpectedValueException('Dimension of given ID (' . count($id) . ') does not match expected dimension (' . count($idFields) . ').'); + } - $where = implode(' AND ', $whereParts); - $this->idRestrictor = function(QueryBuilder $qb, $id) use ($where) { - $qb->where($where)->setParameters($id); - }; - } else { - $where = $baseEntityAlias . '.' . $idFields . ' = :id'; - $this->idRestrictor = function(QueryBuilder $qb, $id) use ($where) { - $qb->where($where)->setParameter('id', $id); - }; - } - } + // here we can be sure that the dimensions match - both branches above would have thrown otherwise + $whereParts = array(); + /** @noinspection PhpUnusedParameterInspection */ + array_walk($id, function ($value, $key) use ($baseEntityAlias, &$whereParts) { + $whereParts[] = $baseEntityAlias . '.' . $key . ' = ' . ':' . $key; + }); - $setter = $this->idRestrictor; - $setter($qb = $this->getBaseQuery(), $id); - return $this->getSingleResult($qb); - } + $where = implode(' AND ', $whereParts); + $this->idRestrictor = function (QueryBuilder $qb, $id) use ($where) { + $qb->where($where)->setParameters($id); + }; + } else { + $where = $baseEntityAlias . '.' . $idFields . ' = :id'; + $this->idRestrictor = function (QueryBuilder $qb, $id) use ($where) { + $qb->where($where)->setParameter('id', $id); + }; + } + } - /** - * @param IRestrictionHolder $restrictionHolder - * @param IOrderAndLimitHolder $orderAndLimitHolder - * @param array $defaultOrderMapping - * @return array - */ - public function getList(IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null) { - return $this->executeListQuery($this->getBaseQuery(), $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping, null); - } + $setter = $this->idRestrictor; + $setter($qb = $this->getBaseQuery(), $id); + return $this->getSingleResult($qb); + } /** + * @param IRestrictionHolder $restrictionHolder + * @param IOrderAndLimitHolder $orderAndLimitHolder + * @param array $defaultOrderMapping + * @return array + */ + public function getList(IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null) { + return $this->executeListQuery($this->getBaseQuery(), $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping, null); + } + + /** * @param QueryBuilder $queryBuilder - * @param string $expr - * @return string + * @param IRestrictionHolder $restrictionHolder + * @param IOrderAndLimitHolder $orderAndLimitHolder + * @param array $defaultOrderMapping + * @param null $hydrationMode + * @return array */ - protected function transformAndAddAliasForPathExpression(QueryBuilder $queryBuilder, $expr) { - $tokens = explode('.', $expr); - $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, 'No more property path tokens - check your listConfiguration for invalid property paths!'); - $currentAlias = $this->reverseAliases[$field]; + public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { + if (!is_null($restrictionHolder)) { + $internalFilterableFields = array(); + if (Strings::hasText($restrictionHolder->getFilterString())) { + $this->disaggregateAndInternalizeFieldList($restrictionHolder->getFilterableFields(), $internalFilterableFields, $queryBuilder); } +// $internalFilters = array(); +// if (count($restrictionHolder->getFilters()) > 0) { +// $this->internalizeFieldValueMapping($restrictionHolder->getFilters(), $internalFilters, $queryBuilder); +// } + $restrictionHolder = new GenericDaoBase_RestrictionWrapper($restrictionHolder, $internalFilterableFields); + } - } while(count($tokens) > 0); + if (!is_null($orderAndLimitHolder)) { + if (count($orderAndLimitHolder->getOrderMapping()) > 0) { + $internalMapping = array(); + $this->disaggregateAndInternalizeFieldValueMapping($orderAndLimitHolder->getOrderMapping(), $internalMapping, $queryBuilder); + $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); + } + } - $this->addAliasForExpression($queryBuilder, $field); - return $field; - } + return parent::executeListQuery($queryBuilder, $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); + } /** + * @param array $externalFieldValueMapping + * @param array $internalFieldValueMapping * @param QueryBuilder $queryBuilder - * @param string $expr + * @param string $prefix */ - protected function addAliasForExpression(QueryBuilder $queryBuilder, $expr) { - if(preg_match(self::ALIAS_MATCHER, $expr, $matches)) { - $this->addAlias($queryBuilder, $matches[1]); - } - } + protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, array &$internalFieldValueMapping, QueryBuilder $queryBuilder, $prefix = '') { + foreach ($externalFieldValueMapping as $field => $value) { + array_walk($this->getFieldDisaggregation($field, $prefix), function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { + $internalFieldValueMapping[$this->internalizeFieldExpression($field, $queryBuilder)] = $value; + }); + } + } - /** - * @param QueryBuilder $queryBuilder - * @param string $alias - */ - protected function addAlias(QueryBuilder $queryBuilder, $alias) { - if(!$this->containsAlias($alias)) { - $this->addedAliases[$alias] = true; - $this->addAliasForExpression($queryBuilder, $this->aliases[$alias]); - $queryBuilder->leftJoin($this->aliases[$alias], $alias); - } - } + /** + * @param array $externalFieldList + * @param array $internalFieldList + * @param QueryBuilder $queryBuilder + * @param string $prefix + */ + protected final function disaggregateAndInternalizeFieldList(array $externalFieldList, array &$internalFieldList, QueryBuilder $queryBuilder, $prefix = '') { + $prefix = $prefix ?: $this->getEntityAlias() . '.'; + foreach ($externalFieldList as $field) { + $internalFieldList = array_merge($internalFieldList, array_map(function ($field) use (&$queryBuilder, $prefix) { + return $this->internalizeFieldExpression($field, $queryBuilder); + }, $this->getFieldDisaggregation($field, $prefix))); + } + } - /** - * @param $alias - * @return boolean - */ - protected function containsAlias($alias) { - // todo: Alias presence could in theory also be detected by examining the query builders DQL parts. Feasibility / performance? - // pros: more thorough and consistent - // cons: more overhead? - return $alias == $this->getEntityAlias() || array_key_exists($alias, $this->addedAliases) || array_key_exists($alias, $this->getJoins()); - } + /** + * @param string $fieldExpr + * @param QueryBuilder $queryBuilder + * @param bool $join + * @return string + */ + protected final function internalizeFieldExpression($fieldExpr, QueryBuilder $queryBuilder, $join = false) { + // ex: $fieldExpr = 'e.hochschultyp.kategorie.promotionsrecht' + $dotPos = strrpos($fieldExpr, '.'); // 24 + $fieldName = substr($fieldExpr, $dotPos + 1); // 'promotionsrecht' + $pathExpr = substr($fieldExpr, 0, $dotPos); // 'e.hochschultyp.kategorie' - public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { - // todo: there is no particular reason to do the path-to-alias transformations in every request... - if(!is_null($restrictionHolder)) { - $internalFilterableFields = array(); - if(Strings::hasText($restrictionHolder->getFilterString())) { - foreach($restrictionHolder->getFilterableFields() as $field) { - $internalFilterableFields = array_merge($internalFilterableFields, $this->getFieldDisaggregation($this->transformAndAddAliasForPathExpression($queryBuilder, $field))); - } - } - $internalFilters = array(); - if(count($restrictionHolder->getFilters()) > 0) { - foreach($restrictionHolder->getFilters() as $field => $value) { - $internalFilters[$this->transformAndAddAliasForPathExpression($queryBuilder, $field)] = $value; - } - } - $restrictionHolder = new GenericDaoBase_RestrictionWrapper($restrictionHolder, $internalFilterableFields, $internalFilters); - } + if($pathExpr != $this->getEntityAlias()) { + Assert::isTrue(array_key_exists($pathExpr, $this->reverseAliases), 'Unknown path expression "' . $pathExpr . '"'); + $this->internalizePathExpression($pathExpr, $queryBuilder, $join); + $pathExpr = $this->reverseAliases[$pathExpr]; + } - if(!is_null($orderAndLimitHolder)) { - if(count($orderAndLimitHolder->getOrderMapping()) > 0) { - $internalMapping = array(); - foreach($orderAndLimitHolder->getOrderMapping() as $field => $dir) { - $internalMapping = array_merge($internalMapping, array_fill_keys($this->getFieldDisaggregation($this->transformAndAddAliasForPathExpression($queryBuilder, $field)), $dir)); - } + // ex: return e4.promotionsrecht + return $pathExpr . '.' . $fieldName; + } - $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); - } - } + /** + * @param string $pathExpr + * @param QueryBuilder $queryBuilder + * @param bool $fetchJoin + * @return string + */ + protected final function internalizePathExpression($pathExpr, QueryBuilder $queryBuilder, $fetchJoin = false) { + // ex (Rc1): $pathExpr = 'e.hochschultyp.kategorie' + // ex (Rc2): $pathExpr = 'e.hochschultyp' + // ex (Rc3): $pathExpr = 'e' - return parent::executeListQuery($queryBuilder, $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); - } + if(($dotPos = strrpos($pathExpr, '.')) !== false) { + $currentAlias = $this->reverseAliases[$pathExpr]; + if(!array_key_exists($currentAlias, $this->addedAliases)) { + + $currentAssociation = substr($pathExpr, $dotPos + 1); + $pathExpr = substr($pathExpr, 0, $dotPos); + + // ex (Rc1): + // $currentAlias = 'e4' + // $currentAssociation = 'kategorie' + // $pathExpr = 'e.hochschultyp' + + // ex (Rc2): + // $currentAlias = 'e1' + // $currentAssociation = 'hochschultyp' + // $pathExpr = 'e' + + $parentAlias = $this->internalizePathExpression($pathExpr, $queryBuilder, $fetchJoin); + + // ex (Rc2): $parentAlias = 'e' + // ex (Rc1): $parentAlias = 'e1' + + $currentAssociation = $parentAlias . '.' . $currentAssociation; + + // ex (Rc2): $currentAssociation = 'e.hochschultyp' + // ex (Rc1): $currentAssociation = 'e1.kategorie' + + $queryBuilder->leftJoin($currentAssociation, $currentAlias); + if($fetchJoin) { + $queryBuilder->addSelect($currentAlias); + } + $this->addedAliases[$currentAlias] = $currentAssociation; + + // ex (Rc2): $this->addedAliases = array('e1' => 'e.hochschultyp') + // ex (Rc1): $this->addedAliases = array('e1' => 'e.hochschultyp', 'e4' => 'e1.kategorie') + } + $pathExpr = $currentAlias; + } + + // ex (Rc3): $pathExpr = 'e' + // ex (Rc2): $pathExpr = 'e1' + // ex (Rc1): $pathExpr = 'e4' + + return $pathExpr; + } + /** * @param null $entity * @return QueryBuilder */ - protected function getBaseQuery($entity = null) { - $baseEntityAlias = $this->getEntityAlias(); + protected function getBaseQuery($entity = null) { + $baseEntityAlias = $this->getEntityAlias(); $entity = $entity ?: $this->getEntity(); // $indexBy = count($this->getIdFieldName()) > 1 ? null : $baseEntityAlias . '.' . $this->getIdFieldName(); // return $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias) // ->from($this->getEntity(), $baseEntityAlias, $indexBy); - $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); - $this->addJoinsToBaseQuery($qb); - $this->addRestrictionsToBaseQuery($qb); - return $qb; - } + $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); + $this->addJoinsToBaseQuery($qb); + $this->addRestrictionsToBaseQuery($qb); + return $qb; + } - /** - * @param QueryBuilder $q - */ - protected function addJoinsToBaseQuery(QueryBuilder $q) { - foreach($this->joins as $alias => $relation) { - $q->addSelect($alias)->leftJoin($relation, $alias); - } - } + /** + * @param QueryBuilder $q + */ + protected function addJoinsToBaseQuery(QueryBuilder $q) { + foreach ($this->joins as $join) { + $this->internalizePathExpression($join, $q, true); + } + } - /** - * @param QueryBuilder $q - */ - protected function addRestrictionsToBaseQuery(QueryBuilder $q) { - foreach($this->restrictions as $restriction) { - $q->andWhere($restriction); - } - } + /** + * @param QueryBuilder $q + */ + protected function addRestrictionsToBaseQuery(QueryBuilder $q) { + foreach ($this->restrictions as $restriction) { + $q->andWhere($restriction); + } + } - /** - * @param QueryBuilder $qb - * @return mixed - */ - protected function getSingleResult(QueryBuilder $qb) { - $q = $this->getQueryFromBuilder($qb); - return $q->getSingleResult($this->getHydrationMode()); - } + /** + * @param QueryBuilder $qb + * @return mixed + */ + protected function getSingleResult(QueryBuilder $qb) { + $q = $this->getQueryFromBuilder($qb); + return $q->getSingleResult($this->getHydrationMode()); + } - /** - * @return null|string - */ - protected function getHydrationMode() { - return null; - } + /** + * @return null|string + */ + protected function getHydrationMode() { + return null; + } - /** - * @return string - */ - protected function getEntityAlias() { - return 'e'; - } + /** + * @return string + */ + protected function getEntityAlias() { + return 'e'; + } - /** - * @return mixed - */ - abstract protected function getIdFieldName(); + /** + * @return mixed + */ + abstract protected function getIdFieldName(); - /** - * @return string - */ - public abstract function getEntity(); + /** + * @return string + */ + public abstract function getEntity(); - /** - * @return null - */ - protected function getIndexBy() { - return null; - } + /** + * @return null + */ + protected function getIndexBy() { + return null; + } /** * @param QueryBuilder $queryBuilder * @param $filters - * @param $categoryName - * @param string $baseAlias - * @param null $property + * @param string $fieldPath */ - protected function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $categoryName, $baseAlias = 'e', $property = null) { - $property = $property ?: $categoryName; - if (array_key_exists($categoryName, $filters)) { - if(!is_array($catIds = $filters[$categoryName])) { + protected function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $fieldPath) { + if (array_key_exists($fieldPath, $filters)) { + if (!is_array($catIds = $filters[$fieldPath])) { $catIds = array_filter(explode(',', $catIds)); } - if(count($catIds) > 0) { - $this->addAlias($queryBuilder, $baseAlias); - $queryBuilder->andWhere($queryBuilder->expr()->in('IDENTITY(' . $baseAlias . '.' . $property . ')', $catIds)); + if (count($catIds) > 0) { + $queryBuilder->andWhere($queryBuilder->expr()->in('IDENTITY(' . $this->internalizeFieldExpression($fieldPath, $queryBuilder) . ')', $catIds)); } } } /** * @param QueryBuilder $queryBuilder - * @param $filters - * @param string $fldName + * @param array $filters + * @param string $fieldExpr + * @param string $filterKey */ - protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fldName) { - if (array_key_exists($fldName, $filters) && $value = $filters[$fldName]) { - $fldName = $this->transformAndAddAliasForPathExpression($queryBuilder, $fldName); - $queryBuilder->andWhere($fldName . ' = :val')->setParameter('val', $value); + protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '') { + $filterKey = $filterKey ?: $fieldExpr; + if (array_key_exists($filterKey, $filters) && $value = $filters[$filterKey]) { + $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . ' = :val')->setParameter('val', $value); } } // ================================================================================================================= - // == GETTERS & SETTERS ============================================================================================ - // ================================================================================================================= + // == GETTERS & SETTERS ============================================================================================ + // ================================================================================================================= - /** - * @return array - */ - public function getAliases() { - return $this->aliases; - } + /** + * @return array + */ + public function getAliases() { + return $this->aliases; + } - /** - * @param array $aliases - */ - public function setAliases(array $aliases) { - $this->aliases = $aliases; - $this->reverseAliases = array_flip($aliases); - } + /** + * @param array $aliases + */ + public function setAliases(array $aliases) { + $this->aliases = array(); + array_walk($aliases, function ($val, $key) { + $this->aliases[is_numeric($key) ? 'e' . $key : $key] = $val; + }); + $this->reverseAliases = array_flip($this->aliases); + } - /** - * @param array $joins - */ - public function setJoins(array $joins) { - $this->joins = $joins; - } + /** + * @param array $joins + */ + public function setJoins(array $joins) { + $this->joins = $joins; + } - /** - * @return array - */ - public function getJoins() { - return $this->joins; - } + /** + * @return array + */ + public function getJoins() { + return $this->joins; + } - /** - * @param array $restrictions - */ - public function setRestrictions(array $restrictions) { - $this->restrictions = $restrictions; - } + /** + * @param array $restrictions + */ + public function setRestrictions(array $restrictions) { + $this->restrictions = $restrictions; + } - /** - * @return array - */ - public function getDefaultOrderMapping() { - return $this->defaultOrderMapping; - } + /** + * @return array + */ + public function getDefaultOrderMapping() { + return $this->defaultOrderMapping; + } - /** - * @param array $defaultOrderMapping - */ - public function setDefaultOrderMapping(array $defaultOrderMapping) { - $this->defaultOrderMapping = $defaultOrderMapping; - } + /** + * @param array $defaultOrderMapping + */ + public function setDefaultOrderMapping(array $defaultOrderMapping) { + $this->defaultOrderMapping = $defaultOrderMapping; + } /** * @return array @@ -380,10 +447,12 @@ /** * @param $aggregateFieldName + * @param string $prefix * @return array */ - public function getFieldDisaggregation($aggregateFieldName) { - if(array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { + protected function getFieldDisaggregation($aggregateFieldName, $prefix = '') { + $aggregateFieldName = ($prefix ?: $this->getEntityAlias() . '.') . $aggregateFieldName; + if (array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { return $this->fieldDisaggregations[$aggregateFieldName]; } return array($aggregateFieldName); @@ -462,20 +531,19 @@ */ private $internalFilterableFields; - /** - * @var array - */ - private $internalFilters; +// /** +// * @var array +// */ +// private $internalFilters; /** * @param $wrappedRestrictionHolder * @param $internalFilterableFields - * @param $internalFilters */ - function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields, array $internalFilters) { + function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields/*, array $internalFilters*/) { $this->wrappedRestrictionHolder = $wrappedRestrictionHolder; $this->internalFilterableFields = $internalFilterableFields; - $this->internalFilters = $internalFilters; +// $this->internalFilters = $internalFilters; } /** @@ -496,6 +564,7 @@ * @return array */ public function getFilters() { - return $this->internalFilters; +// return $this->internalFilters; + return $this->wrappedRestrictionHolder->getFilters(); } } \ No newline at end of file Modified: trunk/framework/Bee/Persistence/PaginationBase.php =================================================================== --- trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-03 07:12:13 UTC (rev 295) @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use JsonSerializable; /** * Class BasicListStateHolder @@ -22,7 +23,7 @@ * Implements the pagination aspect of the IOrderAndLimitHolder and embodies generic logic for * @package Bee\Persistence */ -abstract class PaginationBase implements IOrderAndLimitHolder { +abstract class PaginationBase implements IOrderAndLimitHolder, JsonSerializable { /** * @var int @@ -50,7 +51,7 @@ * @param int $pageSize */ public function setPageSize($pageSize) { - $this->pageSize = $pageSize; + $this->pageSize = intval($pageSize); } /** @@ -71,17 +72,17 @@ * @param $currentPage */ public function setCurrentPage($currentPage) { - $currentPage = $currentPage < 0 ? 0 : $currentPage; - $this->currentPage = $currentPage; + $currentPage = intval($currentPage); + $this->currentPage = $currentPage < 0 ? 0 : $currentPage; } /** * @param int $resultCount */ public function setResultCount($resultCount) { - $this->resultCount = $resultCount; + $this->resultCount = intval($resultCount); if($this->getCurrentPage() >= $this->getPageCount()) { - $this->setCurrentPage($this->getPageCount() - 1); + $this->adjustCurrentPageOnOverflow(); } } @@ -99,4 +100,11 @@ protected function adjustCurrentPageOnOverflow() { $this->setCurrentPage($this->getPageCount() - 1); } + + /** + * @return array + */ + function jsonSerialize() { + return array('pageCount' => $this->getPageCount(), 'pageSize' => $this->getPageSize(), 'currentPage' => $this->getCurrentPage(), 'resultCount' => $this->getResultCount()); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-03-01 17:46:23
|
Revision: 294 http://sourceforge.net/p/beeframework/code/294 Author: m_plomer Date: 2015-03-01 17:46:21 +0000 (Sun, 01 Mar 2015) Log Message: ----------- Persistence: - GenericDaoBase: added aggregate field mappings Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-27 21:01:00 UTC (rev 293) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-01 17:46:21 UTC (rev 294) @@ -53,6 +53,11 @@ */ private $defaultOrderMapping = array(); + /** + * @var array + */ + private $fieldDisaggregations = array(); + /** * @param mixed $id * @throws UnexpectedValueException @@ -173,7 +178,7 @@ $internalFilterableFields = array(); if(Strings::hasText($restrictionHolder->getFilterString())) { foreach($restrictionHolder->getFilterableFields() as $field) { - $internalFilterableFields[] = $this->transformAndAddAliasForPathExpression($queryBuilder, $field); + $internalFilterableFields = array_merge($internalFilterableFields, $this->getFieldDisaggregation($this->transformAndAddAliasForPathExpression($queryBuilder, $field))); } } $internalFilters = array(); @@ -189,7 +194,7 @@ if(count($orderAndLimitHolder->getOrderMapping()) > 0) { $internalMapping = array(); foreach($orderAndLimitHolder->getOrderMapping() as $field => $dir) { - $internalMapping[$this->transformAndAddAliasForPathExpression($queryBuilder, $field)] = $dir; + $internalMapping = array_merge($internalMapping, array_fill_keys($this->getFieldDisaggregation($this->transformAndAddAliasForPathExpression($queryBuilder, $field)), $dir)); } $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); @@ -358,6 +363,31 @@ public function setDefaultOrderMapping(array $defaultOrderMapping) { $this->defaultOrderMapping = $defaultOrderMapping; } + + /** + * @return array + */ + public function getFieldDisaggregations() { + return $this->fieldDisaggregations; + } + + /** + * @param array $fieldDisaggregations + */ + public function setFieldDisaggregations($fieldDisaggregations) { + $this->fieldDisaggregations = $fieldDisaggregations; + } + + /** + * @param $aggregateFieldName + * @return array + */ + public function getFieldDisaggregation($aggregateFieldName) { + if(array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { + return $this->fieldDisaggregations[$aggregateFieldName]; + } + return array($aggregateFieldName); + } } class GenericDaoBase_OrderAndLimitWrapper implements IOrderAndLimitHolder { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-27 21:01:02
|
Revision: 293 http://sourceforge.net/p/beeframework/code/293 Author: m_plomer Date: 2015-02-27 21:01:00 +0000 (Fri, 27 Feb 2015) Log Message: ----------- Persistence: - IRestrictionHolder: fixed wrong phpdoc type info - GenericDaoBase: added path expression resolution to addValueRestriction() Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php trunk/framework/Bee/Persistence/IRestrictionHolder.php Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-27 18:23:53 UTC (rev 292) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-27 21:01:00 UTC (rev 293) @@ -297,12 +297,11 @@ * @param QueryBuilder $queryBuilder * @param $filters * @param string $fldName - * @param string $baseAlias */ - protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fldName = 'gender', $baseAlias = 'e') { + protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fldName) { if (array_key_exists($fldName, $filters) && $value = $filters[$fldName]) { - $queryBuilder->andWhere($baseAlias . '.' . $fldName . ' = :val')->setParameter('val', $value); - $this->addAlias($queryBuilder, $baseAlias); + $fldName = $this->transformAndAddAliasForPathExpression($queryBuilder, $fldName); + $queryBuilder->andWhere($fldName . ' = :val')->setParameter('val', $value); } } Modified: trunk/framework/Bee/Persistence/IRestrictionHolder.php =================================================================== --- trunk/framework/Bee/Persistence/IRestrictionHolder.php 2015-02-27 18:23:53 UTC (rev 292) +++ trunk/framework/Bee/Persistence/IRestrictionHolder.php 2015-02-27 21:01:00 UTC (rev 293) @@ -28,7 +28,7 @@ public function getFilterableFields(); /** - * @return array + * @return string */ public function getFilterString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-27 18:24:01
|
Revision: 292 http://sourceforge.net/p/beeframework/code/292 Author: m_plomer Date: 2015-02-27 18:23:53 +0000 (Fri, 27 Feb 2015) Log Message: ----------- Persistence: - IRestrictionHolder: renamed getFieldRestrictions() to getFilters() - added field mapping logic and filter helpers to Dao hierarchy Modified Paths: -------------- trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php trunk/framework/Bee/Persistence/IRestrictionHolder.php Modified: trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-02-26 16:35:33 UTC (rev 291) +++ trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-02-27 18:23:53 UTC (rev 292) @@ -78,7 +78,6 @@ $tokenName = 'filtertoken' . $no; $params[$tokenName] = '%' . $token . '%'; - foreach ($restrictionHolder->getFilterableFields() as $fieldName) { // $fieldName MUST BE A DOCTRINE NAME if (Strings::hasText($andWhereString)) { @@ -87,7 +86,6 @@ $andWhereString .= $fieldName . ' LIKE :' . $tokenName; } - if (Strings::hasText($andWhereString)) { $queryBuilder->andWhere($andWhereString); Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-26 16:35:33 UTC (rev 291) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-27 18:23:53 UTC (rev 292) @@ -112,9 +112,32 @@ return $this->executeListQuery($this->getBaseQuery(), $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping, null); } - /** - * @param string $expr - */ + /** + * @param QueryBuilder $queryBuilder + * @param string $expr + * @return string + */ + protected function transformAndAddAliasForPathExpression(QueryBuilder $queryBuilder, $expr) { + $tokens = explode('.', $expr); + $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, 'No more property path tokens - check your listConfiguration for invalid property paths!'); + $currentAlias = $this->reverseAliases[$field]; + } + + } while(count($tokens) > 0); + + $this->addAliasForExpression($queryBuilder, $field); + return $field; + } + + /** + * @param QueryBuilder $queryBuilder + * @param string $expr + */ protected function addAliasForExpression(QueryBuilder $queryBuilder, $expr) { if(preg_match(self::ALIAS_MATCHER, $expr, $matches)) { $this->addAlias($queryBuilder, $matches[1]); @@ -145,39 +168,28 @@ } public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { + // todo: there is no particular reason to do the path-to-alias transformations in every request... if(!is_null($restrictionHolder)) { + $internalFilterableFields = array(); if(Strings::hasText($restrictionHolder->getFilterString())) { foreach($restrictionHolder->getFilterableFields() as $field) { - $this->addAliasForExpression($queryBuilder, $field); + $internalFilterableFields[] = $this->transformAndAddAliasForPathExpression($queryBuilder, $field); } } - if(count($restrictionHolder->getFieldRestrictions()) > 0) { - foreach($restrictionHolder->getFieldRestrictions() as $field => $value) { - $this->addAliasForExpression($queryBuilder, $field); + $internalFilters = array(); + if(count($restrictionHolder->getFilters()) > 0) { + foreach($restrictionHolder->getFilters() as $field => $value) { + $internalFilters[$this->transformAndAddAliasForPathExpression($queryBuilder, $field)] = $value; } } + $restrictionHolder = new GenericDaoBase_RestrictionWrapper($restrictionHolder, $internalFilterableFields, $internalFilters); } 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; + $internalMapping[$this->transformAndAddAliasForPathExpression($queryBuilder, $field)] = $dir; } $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); @@ -261,7 +273,40 @@ return null; } - // ================================================================================================================= + /** + * @param QueryBuilder $queryBuilder + * @param $filters + * @param $categoryName + * @param string $baseAlias + * @param null $property + */ + protected function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $categoryName, $baseAlias = 'e', $property = null) { + $property = $property ?: $categoryName; + if (array_key_exists($categoryName, $filters)) { + if(!is_array($catIds = $filters[$categoryName])) { + $catIds = array_filter(explode(',', $catIds)); + } + if(count($catIds) > 0) { + $this->addAlias($queryBuilder, $baseAlias); + $queryBuilder->andWhere($queryBuilder->expr()->in('IDENTITY(' . $baseAlias . '.' . $property . ')', $catIds)); + } + } + } + + /** + * @param QueryBuilder $queryBuilder + * @param $filters + * @param string $fldName + * @param string $baseAlias + */ + protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fldName = 'gender', $baseAlias = 'e') { + if (array_key_exists($fldName, $filters) && $value = $filters[$fldName]) { + $queryBuilder->andWhere($baseAlias . '.' . $fldName . ' = :val')->setParameter('val', $value); + $this->addAlias($queryBuilder, $baseAlias); + } + } + + // ================================================================================================================= // == GETTERS & SETTERS ============================================================================================ // ================================================================================================================= @@ -333,7 +378,6 @@ $this->internalOrderMapping = $internalOrderMapping; } - /** * @return array */ @@ -375,4 +419,54 @@ public function setResultCount($resultCount) { $this->wrappedOrderAndLimitHolder->setResultCount($resultCount); } +} + +class GenericDaoBase_RestrictionWrapper implements IRestrictionHolder { + + /** + * @var IRestrictionHolder + */ + private $wrappedRestrictionHolder; + + /** + * @var array + */ + private $internalFilterableFields; + + /** + * @var array + */ + private $internalFilters; + + /** + * @param $wrappedRestrictionHolder + * @param $internalFilterableFields + * @param $internalFilters + */ + function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields, array $internalFilters) { + $this->wrappedRestrictionHolder = $wrappedRestrictionHolder; + $this->internalFilterableFields = $internalFilterableFields; + $this->internalFilters = $internalFilters; + } + + /** + * @return array + */ + public function getFilterableFields() { + return $this->internalFilterableFields; + } + + /** + * @return array + */ + public function getFilterString() { + return $this->wrappedRestrictionHolder->getFilterString(); + } + + /** + * @return array + */ + public function getFilters() { + return $this->internalFilters; + } } \ No newline at end of file Modified: trunk/framework/Bee/Persistence/IRestrictionHolder.php =================================================================== --- trunk/framework/Bee/Persistence/IRestrictionHolder.php 2015-02-26 16:35:33 UTC (rev 291) +++ trunk/framework/Bee/Persistence/IRestrictionHolder.php 2015-02-27 18:23:53 UTC (rev 292) @@ -35,6 +35,6 @@ /** * @return array */ - public function getFieldRestrictions(); + public function getFilters(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <m_p...@us...> - 2015-02-25 11:08:07
|
Revision: 290 http://sourceforge.net/p/beeframework/code/290 Author: m_plomer Date: 2015-02-25 11:08:06 +0000 (Wed, 25 Feb 2015) Log Message: ----------- - fixed wrong class file name Added Paths: ----------- trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumnResultSetExtractor.php Removed Paths: ------------- trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumn.php Deleted: trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumn.php =================================================================== --- trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumn.php 2015-02-25 10:57:59 UTC (rev 289) +++ trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumn.php 2015-02-25 11:08:06 UTC (rev 290) @@ -1,32 +0,0 @@ -<?php -namespace Bee\Persistence\Pdo\ResultSetExtractor; - -/* - * Copyright 2008-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use PDO; -use PDOStatement; - -/** - * Class SingleColumnResultSetExtractor - * @package Bee\Persistence\Pdo\ResultSetExtractor - * - * todo: check feasibility. Remove if usages are scarce enough to replace them with closures - */ -class SingleColumnResultSetExtractor { - public function __invoke(PDOStatement $rs) { - return $rs->fetchAll(PDO::FETCH_COLUMN); - } -} \ No newline at end of file Copied: trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumnResultSetExtractor.php (from rev 289, trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumn.php) =================================================================== --- trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumnResultSetExtractor.php (rev 0) +++ trunk/framework/Bee/Persistence/Pdo/ResultSetExtractor/SingleColumnResultSetExtractor.php 2015-02-25 11:08:06 UTC (rev 290) @@ -0,0 +1,32 @@ +<?php +namespace Bee\Persistence\Pdo\ResultSetExtractor; + +/* + * Copyright 2008-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +use PDO; +use PDOStatement; + +/** + * Class SingleColumnResultSetExtractor + * @package Bee\Persistence\Pdo\ResultSetExtractor + * + * todo: check feasibility. Remove if usages are scarce enough to replace them with closures + */ +class SingleColumnResultSetExtractor { + public function __invoke(PDOStatement $rs) { + return $rs->fetchAll(PDO::FETCH_COLUMN); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-24 13:03:41
|
Revision: 288 http://sourceforge.net/p/beeframework/code/288 Author: m_plomer Date: 2015-02-24 13:03:39 +0000 (Tue, 24 Feb 2015) Log Message: ----------- - introduced TLogged trait into various classes Modified Paths: -------------- trunk/framework/Bee/MVC/Controller/Multiaction/AbstractDelegatingHandlerHolder.php trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php trunk/framework/Bee/MVC/Dispatcher.php trunk/framework/Bee/MVC/SimpleMappingExceptionResolver.php trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php trunk/framework/Bee/Persistence/Doctrine2/EntityManagerHolder.php Modified: trunk/framework/Bee/MVC/Controller/Multiaction/AbstractDelegatingHandlerHolder.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/AbstractDelegatingHandlerHolder.php 2015-02-24 12:56:16 UTC (rev 287) +++ trunk/framework/Bee/MVC/Controller/Multiaction/AbstractDelegatingHandlerHolder.php 2015-02-24 13:03:39 UTC (rev 288) @@ -15,31 +15,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -use Bee\MVC\Controller\MultiActionController; use Bee\MVC\IDelegatingHandler; -use Logger; +use Bee\Utils\TLogged; /** * Class AbstractControllerHolder */ abstract class AbstractDelegatingHandlerHolder { + use TLogged; /** - * @var Logger - */ - protected $log; - - /** - * @return Logger - */ - protected function getLog() { - if (!$this->log) { - $this->log = Logger::getLogger(get_class($this)); - } - return $this->log; - } - - /** * Enter description here... * * @var IDelegatingHandler Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php 2015-02-24 12:56:16 UTC (rev 287) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php 2015-02-24 13:03:39 UTC (rev 288) @@ -19,6 +19,7 @@ use Bee\Beans\PropertyEditor\PropertyEditorRegistry; use Bee\MVC\IHttpRequest; use Bee\Utils\AntPathToRegexTransformer; +use Bee\Utils\TLogged; use Logger; use ReflectionMethod; @@ -27,25 +28,11 @@ * @package Bee\MVC\Controller\Multiaction\HandlerMethodInvocator */ class RegexMappingInvocationResolver implements IInvocationResolver { + use TLogged; const IGNORE_WILDCARD_TRAILING_PATTERN = '\\.[^/]*'; /** - * @var Logger - */ - protected static $log; - - /** - * @return Logger - */ - protected static function getLog() { - if (!self::$log) { - self::$log = Logger::getLogger(get_called_class()); - } - return self::$log; - } - - /** * @var HandlerMethodMetadata[] */ private static $methodMetadataMap = array(); @@ -92,8 +79,8 @@ } } // sort matching patterns - if (self::getLog()->isDebugEnabled()) { - self::getLog()->debug('Found ' . count($matchingPatterns) . ' matching patterns for pathInfo "' . $pathInfo . '", trying to determine most specific match'); + if ($this->getLog()->isDebugEnabled()) { + $this->getLog()->debug('Found ' . count($matchingPatterns) . ' matching patterns for pathInfo "' . $pathInfo . '", trying to determine most specific match'); } uksort($matchingPatterns, function ($patternA, $patternB) use ($matchingPatterns, $pathInfo) { @@ -150,11 +137,11 @@ return strlen($matchA->getAntPathPattern()) - strlen($matchB->getAntPathPattern()); }); - if (self::getLog()->isDebugEnabled()) { + if ($this->getLog()->isDebugEnabled()) { $matchingAntPaths = array_map(function (MethodInvocation $item) { return $item->getAntPathPattern(); }, $matchingPatterns); - self::getLog()->debug('Sorted patterns for pathInfo "' . $pathInfo . '" are ' . "\n" . implode("\n", $matchingAntPaths)); + $this->getLog()->debug('Sorted patterns for pathInfo "' . $pathInfo . '" are ' . "\n" . implode("\n", $matchingAntPaths)); } if (count($matchingPatterns) > 0) { Modified: trunk/framework/Bee/MVC/Dispatcher.php =================================================================== --- trunk/framework/Bee/MVC/Dispatcher.php 2015-02-24 12:56:16 UTC (rev 287) +++ trunk/framework/Bee/MVC/Dispatcher.php 2015-02-24 13:03:39 UTC (rev 288) @@ -21,8 +21,8 @@ use Bee\IContext; use Bee\MVC\Session\DispatcherAdapter; use Bee\Utils\Assert; +use Bee\Utils\TLogged; use Exception; -use Logger; /** * The dispatcher is the main entry point into an Bee MVC application. It acts as a front controller, i.e. it handles incoming @@ -49,6 +49,7 @@ * @author Benjamin Hartmann */ class Dispatcher implements IFilterChain { + use TLogged; const REQUEST_BUILDER_BEAN_NAME = 'requestBuilder'; @@ -61,21 +62,6 @@ const HANDLER_EXCEPTION_RESOLVER_NAME = 'handlerExceptionResolver'; /** - * @var Logger - */ - protected $log; - - /** - * @return Logger - */ - protected function getLog() { - if (!$this->log) { - $this->log = Logger::getLogger(get_class($this)); - } - return $this->log; - } - - /** * The dispatcher responsible for the current request * * @var Dispatcher Modified: trunk/framework/Bee/MVC/SimpleMappingExceptionResolver.php =================================================================== --- trunk/framework/Bee/MVC/SimpleMappingExceptionResolver.php 2015-02-24 12:56:16 UTC (rev 287) +++ trunk/framework/Bee/MVC/SimpleMappingExceptionResolver.php 2015-02-24 13:03:39 UTC (rev 288) @@ -16,29 +16,15 @@ * limitations under the License. */ use Bee\Utils\Strings; +use Bee\Utils\TLogged; use Exception; -use Logger; class SimpleMappingExceptionResolver implements IHandlerExceptionResolver { + use TLogged; const MODEL_HANDLER_EXCEPTION_KEY = 'handler_excpetion'; /** - * @var Logger - */ - protected $log; - - /** - * @return Logger - */ - protected function getLog() { - if (!$this->log) { - $this->log = Logger::getLogger(get_class($this)); - } - return $this->log; - } - - /** * * @var array */ Modified: trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php =================================================================== --- trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php 2015-02-24 12:56:16 UTC (rev 287) +++ trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php 2015-02-24 13:03:39 UTC (rev 288) @@ -22,7 +22,7 @@ use Bee\MVC\IViewResolver; use Bee\MVC\ModelAndView; use Bee\MVC\View\ViewBase; -use Logger; +use Bee\Utils\TLogged; /** * Basic implementation of the IViewResolver interface. Uses a Bee\IContext for view name resolution, looking up @@ -32,23 +32,9 @@ * @author Michael Plomer <mic...@it...> */ class BasicViewResolver implements IViewResolver { + use TLogged; /** - * @var Logger - */ - protected $log; - - /** - * @return Logger - */ - protected function getLog() { - if (!$this->log) { - $this->log = Logger::getLogger(get_class($this)); - } - return $this->log; - } - - /** * Enter description here... * * @var IContext Modified: trunk/framework/Bee/Persistence/Doctrine2/EntityManagerHolder.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/EntityManagerHolder.php 2015-02-24 12:56:16 UTC (rev 287) +++ trunk/framework/Bee/Persistence/Doctrine2/EntityManagerHolder.php 2015-02-24 13:03:39 UTC (rev 288) @@ -15,34 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -use BeeFramework; +use Bee\Utils\TLogged; use \Doctrine\ORM\EntityManager; -use Logger; /** * User: mp * Date: 27.06.13 * Time: 04:17 */ - class EntityManagerHolder { + use TLogged; /** - * @var Logger - */ - protected $log; - - /** - * @return Logger - */ - public function getLog() { - if (!$this->log) { - $this->log = BeeFramework::getLoggerForClass(get_class($this)); - } - return $this->log; - } - - /** * @var EntityManager */ private $entityManager; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-24 12:56:18
|
Revision: 287 http://sourceforge.net/p/beeframework/code/287 Author: m_plomer Date: 2015-02-24 12:56:16 +0000 (Tue, 24 Feb 2015) Log Message: ----------- - moved request-storing view hierarchy to trait base - BeeFramework now requires PHP 5.4!!! Modified Paths: -------------- trunk/framework/Bee/MVC/Model.php trunk/framework/Bee/MVC/View/RequestStoringRedirectView.php trunk/framework/composer.json Added Paths: ----------- trunk/framework/Bee/MVC/View/RequestStoringJsonView.php trunk/framework/Bee/MVC/View/TRequestStoringView.php Modified: trunk/framework/Bee/MVC/Model.php =================================================================== --- trunk/framework/Bee/MVC/Model.php 2015-02-24 12:51:47 UTC (rev 286) +++ trunk/framework/Bee/MVC/Model.php 2015-02-24 12:56:16 UTC (rev 287) @@ -1,6 +1,6 @@ <?php /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ * * @param array $values */ - public static function addValuesToModel(Array $values) { + public static function addValuesToModel(array $values) { self::$modelValues = array_merge(self::$modelValues, $values); } Added: trunk/framework/Bee/MVC/View/RequestStoringJsonView.php =================================================================== --- trunk/framework/Bee/MVC/View/RequestStoringJsonView.php (rev 0) +++ trunk/framework/Bee/MVC/View/RequestStoringJsonView.php 2015-02-24 12:56:16 UTC (rev 287) @@ -0,0 +1,35 @@ +<?php +/* + * Copyright 2008-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +namespace Bee\MVC\View; + +use MODEL; + +/** + * Class RequestStoringJsonView + * @package Bee\MVC\View + */ +class RequestStoringJsonView extends JsonServiceView { + use TRequestStoringView; + + /** + * + */ + protected function renderMergedOutputModel() { + MODEL::addValuesToModel($this->createStoreParams(MODEL::getModel())); + parent::renderMergedOutputModel(); + } +} \ No newline at end of file Modified: trunk/framework/Bee/MVC/View/RequestStoringRedirectView.php =================================================================== --- trunk/framework/Bee/MVC/View/RequestStoringRedirectView.php 2015-02-24 12:51:47 UTC (rev 286) +++ trunk/framework/Bee/MVC/View/RequestStoringRedirectView.php 2015-02-24 12:56:16 UTC (rev 287) @@ -1,7 +1,7 @@ <?php namespace Bee\MVC\View; /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,70 +15,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -use Bee\MVC\Redirect\AbstractRedirectStorage; /** * Class RequestStoringRedirectView * @package Bee\MVC\View */ class RequestStoringRedirectView extends RedirectView { + use TRequestStoringView; - /** - * @var string - */ - private $requestIdParamName = 'requestId'; - - /** - * @var AbstractRedirectStorage[] - */ - private $stores = array(); - - /** - * @param string $requestIdParamName - */ - public function setRequestIdParamName($requestIdParamName) { - $this->requestIdParamName = $requestIdParamName; - } - - /** - * @return string - */ - public function getRequestIdParamName() { - return $this->requestIdParamName; - } - - /** - * @param array $stores - */ - public function setStores(array $stores) { - $this->stores = $stores; - } - - /** - * @return array - */ - public function getStores() { - return $this->stores; - } - - /** - * @param array $model - */ - public function render(array $model = array()) { - $this->augmentModel($model); - $getParams = array_key_exists(self::MODEL_KEY_GET_PARAMS, $model) ? $model[self::MODEL_KEY_GET_PARAMS] : array(); - foreach($this->stores as $paramName => $store) { - $getParams[$paramName] = $store->storeData($model); - } - $model[self::MODEL_KEY_GET_PARAMS] = $getParams; - parent::render($model); - } - - /** - * Extension point for subclasses - * @param array $model - */ - protected function augmentModel(array &$model) { - // do nothing by default - } + /** + * @param array $model + */ + public function render(array $model = array()) { + $getParams = array_key_exists(RedirectView::MODEL_KEY_GET_PARAMS, $model) ? $model[RedirectView::MODEL_KEY_GET_PARAMS] : array(); + $model[RedirectView::MODEL_KEY_GET_PARAMS] = array_merge($getParams, $this->createStoreParams($model)); + parent::render($model); + } } \ No newline at end of file Added: trunk/framework/Bee/MVC/View/TRequestStoringView.php =================================================================== --- trunk/framework/Bee/MVC/View/TRequestStoringView.php (rev 0) +++ trunk/framework/Bee/MVC/View/TRequestStoringView.php 2015-02-24 12:56:16 UTC (rev 287) @@ -0,0 +1,90 @@ +<?php +/* + * Copyright 2008-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +namespace Bee\MVC\View; + + +use Bee\MVC\Redirect\AbstractRedirectStorage; + +/** + * Class TRequestStoringView + * @package Bee\MVC\View + */ +trait TRequestStoringView { + + /** + * @var string + */ + private $requestIdParamName = 'requestId'; + + /** + * @var AbstractRedirectStorage[] + */ + private $stores = array(); + + /** + * @param $model + * @return array + */ + protected function createStoreParams($model) { + $this->augmentModel($model); + $storeParams = array(); + foreach($this->stores as $paramName => $store) { + $storeParams[$paramName] = $store->storeData($model); + } + return $storeParams; + } + + /** + * Extension point for subclasses + * @param array $model + */ + protected function augmentModel(array &$model) { + // do nothing by default + } + + // ================================================================================================================= + // == GETTERS & SETTERS ============================================================================================ + // ================================================================================================================= + + /** + * @param string $requestIdParamName + */ + public function setRequestIdParamName($requestIdParamName) { + $this->requestIdParamName = $requestIdParamName; + } + + /** + * @return string + */ + public function getRequestIdParamName() { + return $this->requestIdParamName; + } + + /** + * @param array $stores + */ + public function setStores(array $stores) { + $this->stores = $stores; + } + + /** + * @return array + */ + public function getStores() { + return $this->stores; + } +} \ No newline at end of file Modified: trunk/framework/composer.json =================================================================== --- trunk/framework/composer.json 2015-02-24 12:51:47 UTC (rev 286) +++ trunk/framework/composer.json 2015-02-24 12:56:16 UTC (rev 287) @@ -21,7 +21,7 @@ } ], "require": { - "php": ">=5.3", + "php": ">=5.4", "niktux/addendum": "0.4.1", "apache/log4php": "~2.3@stable" }, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-24 12:51:54
|
Revision: 286 http://sourceforge.net/p/beeframework/code/286 Author: m_plomer Date: 2015-02-24 12:51:47 +0000 (Tue, 24 Feb 2015) Log Message: ----------- PHP 5.3 branch Added Paths: ----------- branches/0.9.9-dev/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-18 15:06:49
|
Revision: 285 http://sourceforge.net/p/beeframework/code/285 Author: m_plomer Date: 2015-02-18 15:06:42 +0000 (Wed, 18 Feb 2015) Log Message: ----------- - added some traits Added Paths: ----------- trunk/framework/Bee/Context/Config/TContextAware.php trunk/framework/Bee/Utils/TLogged.php Added: trunk/framework/Bee/Context/Config/TContextAware.php =================================================================== --- trunk/framework/Bee/Context/Config/TContextAware.php (rev 0) +++ trunk/framework/Bee/Context/Config/TContextAware.php 2015-02-18 15:06:42 UTC (rev 285) @@ -0,0 +1,24 @@ +<?php +namespace Bee\Context\Config; + +use Bee\IContext; + +/** + * Class TContextAware + * @package Bee\Context\Config + */ +trait TContextAware { + + /** + * @var IContext + */ + protected $context; + + /** + * @param IContext $context + */ + public function setBeeContext(IContext $context) { + $this->context = $context; + } + +} \ No newline at end of file Added: trunk/framework/Bee/Utils/TLogged.php =================================================================== --- trunk/framework/Bee/Utils/TLogged.php (rev 0) +++ trunk/framework/Bee/Utils/TLogged.php 2015-02-18 15:06:42 UTC (rev 285) @@ -0,0 +1,27 @@ +<?php +namespace Bee\Utils; + +use Bee\Framework; +use Logger; + +/** + * Class TLogged + * @package Bee\Utils + */ +trait TLogged { + + /** + * @var Logger + */ + protected $log; + + /** + * @return Logger + */ + public function getLog() { + if (!$this->log) { + $this->log = Framework::getLoggerForClass(get_class($this)); + } + return $this->log; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-16 19:34:33
|
Revision: 284 http://sourceforge.net/p/beeframework/code/284 Author: m_plomer Date: 2015-02-16 19:34:26 +0000 (Mon, 16 Feb 2015) Log Message: ----------- - added some traits Modified Paths: -------------- trunk/framework/Bee/Cache/Manager.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php Modified: trunk/framework/Bee/Cache/Manager.php =================================================================== --- trunk/framework/Bee/Cache/Manager.php 2015-02-16 08:43:54 UTC (rev 283) +++ trunk/framework/Bee/Cache/Manager.php 2015-02-16 19:34:26 UTC (rev 284) @@ -218,6 +218,81 @@ return $data; } + /** + * Enter description here... + * + * @param string $key + * @param callback $contentCreator + * @param int $lastModified + * @param bool $returnInfoArray + * @return mixed + */ + public static function &retrieveCachableClosure($key, $contentCreator, $lastModified = 0, $returnInfoArray = false) { + if(is_null(self::$provider)) { + // no cache provider found, no caching or unsupported cache type installed + $data =& $contentCreator(); + $result = $returnInfoArray ? array(self::INFO_NO_CACHE_KEY => true, self::INFO_CACHE_HIT_KEY => false, self::INFO_IN_CACHE_SINCE_KEY => false, self::INFO_DATA_KEY => &$data) : $data; + return $result; + } + + // caching supported, check if in cache and not stale + $key = self::getQualifiedKey($key); + $ctimeKey = $key . self::CTIME_KEY_SUFFIX; + + try { + $inCacheSince = self::$provider->retrieve($ctimeKey); + $inCacheSince = $inCacheSince === false ? -1 : $inCacheSince; + + } catch (Exception $e) { + $inCacheSince = -1; + } + + $mtime = $lastModified; + + if($inCacheSince < $mtime) { + // @todo: provide logging + // resource not found in cache or stale, re-create and store in cache + + $etime = 0; + $data =& $contentCreator($etime); + + self::$provider->store($ctimeKey, $mtime, $etime); + self::$provider->store($key, $data, $etime); + + $cacheHit = false; + } else { + // @todo: provide logging + // resource in cache is current, fetch from cache + try { + $data = self::$provider->retrieve($key); + $cacheHit = true; + + } catch (Exception $e) { + // ACHTUNG!!!!!!!! + // ACHTUNG!!!!!!!! + // ACHTUNG!!!!!!!! + // ACHTUNG!!!!!!!! + // + // hier habe ich einfach ein stück code aus dem if ... zweig dupliziert + // + // @todo: provide logging + // resource not found in cache or stale, re-create and store in cache + $etime = 0; + $data =& $contentCreator($etime); + + self::$provider->store($ctimeKey, $mtime, $etime); + self::$provider->store($key, $data, $etime); + + $cacheHit = false; + } + } + + if($returnInfoArray) { + $data = array(self::INFO_CACHE_HIT_KEY => $cacheHit, self::INFO_IN_CACHE_SINCE_KEY => $inCacheSince, self::INFO_DATA_KEY => &$data); + } + return $data; + } + public static function retrieve($key) { return self::$provider->retrieve(self::getQualifiedKey($key)); } Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-16 08:43:54 UTC (rev 283) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-02-16 19:34:26 UTC (rev 284) @@ -163,15 +163,17 @@ return parent::executeListQuery($queryBuilder, $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); } - /** - * @return QueryBuilder - */ - protected function getBaseQuery() { + /** + * @param null $entity + * @return QueryBuilder + */ + protected function getBaseQuery($entity = null) { $baseEntityAlias = $this->getEntityAlias(); + $entity = $entity ?: $this->getEntity(); // $indexBy = count($this->getIdFieldName()) > 1 ? null : $baseEntityAlias . '.' . $this->getIdFieldName(); // return $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias) // ->from($this->getEntity(), $baseEntityAlias, $indexBy); - $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($this->getEntity(), $baseEntityAlias, $this->getIndexBy()); + $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); $this->addJoinsToBaseQuery($qb); $this->addRestrictionsToBaseQuery($qb); return $qb; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-16 08:43:56
|
Revision: 283 http://sourceforge.net/p/beeframework/code/283 Author: m_plomer Date: 2015-02-16 08:43:54 +0000 (Mon, 16 Feb 2015) Log Message: ----------- - Security/Acl: fixed regressions from namespace refactoring - Security/Vote: namespace refactoring Modified Paths: -------------- trunk/framework/Bee/Security/Config/Utils.php trunk/framework/Bee/Security/Vote/AclEntryVoter.php trunk/framework/acl-default.xml Modified: trunk/framework/Bee/Security/Config/Utils.php =================================================================== --- trunk/framework/Bee/Security/Config/Utils.php 2015-02-16 08:02:59 UTC (rev 282) +++ trunk/framework/Bee/Security/Config/Utils.php 2015-02-16 08:43:54 UTC (rev 283) @@ -34,7 +34,7 @@ $roleVoter->setBeanClassName('Bee\Security\Vote\RoleVoter'); // $authenticatedVoter = new GenericBeanDefinition(); -// $authenticatedVoter->setBeanClassName('Bee_Security_Vote_AuthenticatedVoter'); // todo: implement... +// $authenticatedVoter->setBeanClassName('Bee\Security\Vote\AuthenticatedVoter'); // todo: implement... $defaultVoters = array( $roleVoter/*, Modified: trunk/framework/Bee/Security/Vote/AclEntryVoter.php =================================================================== --- trunk/framework/Bee/Security/Vote/AclEntryVoter.php 2015-02-16 08:02:59 UTC (rev 282) +++ trunk/framework/Bee/Security/Vote/AclEntryVoter.php 2015-02-16 08:43:54 UTC (rev 283) @@ -38,7 +38,7 @@ * To change this template use File | Settings | File Templates. */ -class Bee_Security_Vote_AclEntryVoter extends AbstractAclVoter { +class AclEntryVoter extends AbstractAclVoter { /** * @var Logger Modified: trunk/framework/acl-default.xml =================================================================== --- trunk/framework/acl-default.xml 2015-02-16 08:02:59 UTC (rev 282) +++ trunk/framework/acl-default.xml 2015-02-16 08:43:54 UTC (rev 283) @@ -67,7 +67,7 @@ <constructor-arg index="0" ref="defaultAclService" /> </bean> - <bean id="aclVoterRead" class="Bee_Security_Vote_AclEntryVoter" parent="aclVoterTemplate"> + <bean id="aclVoterRead" class="Bee\Security\Vote\AclEntryVoter" parent="aclVoterTemplate"> <constructor-arg index="1" value="ACL_OBJECT_READ" /> <constructor-arg index="2"> <array> @@ -76,7 +76,7 @@ </constructor-arg> </bean> - <bean id="aclVoterWrite" class="Bee_Security_Vote_AclEntryVoter" parent="aclVoterTemplate"> + <bean id="aclVoterWrite" class="Bee\Security\Vote\AclEntryVoter" parent="aclVoterTemplate"> <constructor-arg index="1" value="ACL_OBJECT_WRITE" /> <constructor-arg index="2"> <array> @@ -85,7 +85,7 @@ </constructor-arg> </bean> - <bean id="aclVoterCreate" class="Bee_Security_Vote_AclEntryVoter" parent="aclVoterTemplate"> + <bean id="aclVoterCreate" class="Bee\Security\Vote\AclEntryVoter" parent="aclVoterTemplate"> <constructor-arg index="1" value="ACL_OBJECT_CREATE" /> <constructor-arg index="2"> <array> @@ -94,7 +94,7 @@ </constructor-arg> </bean> - <bean id="aclVoterDelete" class="Bee_Security_Vote_AclEntryVoter" parent="aclVoterTemplate"> + <bean id="aclVoterDelete" class="Bee\Security\Vote\AclEntryVoter" parent="aclVoterTemplate"> <constructor-arg index="1" value="ACL_OBJECT_DELETE" /> <constructor-arg index="2"> <array> @@ -103,7 +103,7 @@ </constructor-arg> </bean> - <bean id="aclVoterModify" class="Bee_Security_Vote_AclEntryVoter" parent="aclVoterTemplate"> + <bean id="aclVoterModify" class="Bee\Security\Vote\AclEntryVoter" parent="aclVoterTemplate"> <constructor-arg index="1" value="ACL_OBJECT_MODIFY" /> <constructor-arg index="2"> <array> @@ -114,7 +114,7 @@ </constructor-arg> </bean> - <bean id="aclVoterAdministration" class="Bee_Security_Vote_AclEntryVoter" parent="aclVoterTemplate"> + <bean id="aclVoterAdministration" class="Bee\Security\Vote\AclEntryVoter" parent="aclVoterTemplate"> <constructor-arg index="1" value="ACL_OBJECT_ADMINISTRATION" /> <constructor-arg index="2"> <array> @@ -126,7 +126,7 @@ <bean id="accessDecisionManager" class="Bee\Security\Vote\AffirmativeBased"> <property name="decisionVoters"> <array> - <bean class="Bee\Security\Vote\RoleVoter"/> + <bean class="BeeSecurity\Vote\RoleVoter"/> <ref bean="aclVoterRead" /> <ref bean="aclVoterWrite" /> <ref bean="aclVoterCreate" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <m_p...@us...> - 2015-02-16 08:03:02
|
Revision: 282 http://sourceforge.net/p/beeframework/code/282 Author: m_plomer Date: 2015-02-16 08:02:59 +0000 (Mon, 16 Feb 2015) Log Message: ----------- - Security/Acl: fixed regressions from namespace refactoring - Security/Vote: namespace refactoring Modified Paths: -------------- trunk/framework/Bee/MVC/Controller/Multiaction/AbstractAnnotationBasedResolver.php trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php trunk/framework/Bee/Security/Acls/Pdo/AclService.php trunk/framework/Bee/Security/Acls/Pdo/BasicLookupStrategy.php trunk/framework/Bee/Security/Config/Utils.php trunk/framework/Bee/Security/ConfigAttributeDefinition.php trunk/framework/Bee/Security/Transactions/Interceptor/DefaultTransactionAttribute.php trunk/framework/Bee/Security/Transactions/Interceptor/DelegatingTransactionAttribute.php trunk/framework/Bee/Security/Vote/AbstractAclVoter.php trunk/framework/Bee/Security/Vote/AbstractDecisionManager.php trunk/framework/Bee/Security/Vote/AclEntryVoter.php trunk/framework/Bee/Security/Vote/AffirmativeBased.php trunk/framework/Bee/Security/Vote/IAccessDecisionVoter.php trunk/framework/Bee/Security/Vote/RoleVoter.php trunk/framework/acl-default.xml Modified: trunk/framework/Bee/MVC/Controller/Multiaction/AbstractAnnotationBasedResolver.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/AbstractAnnotationBasedResolver.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/MVC/Controller/Multiaction/AbstractAnnotationBasedResolver.php 2015-02-16 08:02:59 UTC (rev 282) @@ -134,7 +134,7 @@ $annotations = $method->getAllAnnotations('Bee_MVC_Controller_Multiaction_RequestHandler'); foreach ($annotations as $annotation) { $requestTypeKey = $this->getMethodNameKey($annotation->httpMethod) . - $this->getAjaxTypeKey(filter_var($annotation->ajax, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); + $this->getAjaxTypeKey(is_null($annotation->ajax) ? null : filter_var($annotation->ajax, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); if (!array_key_exists($requestTypeKey, $mappings)) { $mappings[$requestTypeKey] = array(); } Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2015-02-16 08:02:59 UTC (rev 282) @@ -86,7 +86,6 @@ public function invokeHandlerMethod(IHttpRequest $request, array $fixedParams = array()) { /** @var MethodInvocation $resolvedMethod */ $resolvedMethod = $this->resolveMethodForRequest($request); - if (is_null($resolvedMethod)) { $resolvedMethod = $this->getDefaultMethodInvocation(); } Modified: trunk/framework/Bee/Security/Acls/Pdo/AclService.php =================================================================== --- trunk/framework/Bee/Security/Acls/Pdo/AclService.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Acls/Pdo/AclService.php 2015-02-16 08:02:59 UTC (rev 282) @@ -167,7 +167,7 @@ // Retrieve the ACL via superclass (ensures cache registration, proper retrieval etc) $acl = $this->readAclForOid($objectIdentity); - Assert::isInstanceOf('IMutableAcl', $acl, "MutableAcl should have been returned"); + Assert::isInstanceOf('Bee\Security\Acls\IMutableAcl', $acl, "MutableAcl should have been returned"); return $acl; Modified: trunk/framework/Bee/Security/Acls/Pdo/BasicLookupStrategy.php =================================================================== --- trunk/framework/Bee/Security/Acls/Pdo/BasicLookupStrategy.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Acls/Pdo/BasicLookupStrategy.php 2015-02-16 08:02:59 UTC (rev 282) @@ -264,7 +264,7 @@ $resultMap = array(); foreach ($acls as $inputAcl) { - Assert::isInstanceOf('Acl', $inputAcl, 'Map should have contained an AclImpl'); + Assert::isInstanceOf('Bee\Security\Acls\Impl\Acl', $inputAcl, 'Map should have contained an AclImpl'); $result = $this->convert($acls, $inputAcl->getId()); $resultMap[$result->getObjectIdentity()->getIdentifierString()] = $result; Modified: trunk/framework/Bee/Security/Config/Utils.php =================================================================== --- trunk/framework/Bee/Security/Config/Utils.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Config/Utils.php 2015-02-16 08:02:59 UTC (rev 282) @@ -31,7 +31,7 @@ if (!$parserContext->getRegistry()->containsBeanDefinition(Bee_Security_Config_IBeanIds::ACCESS_MANAGER)) { $roleVoter = new GenericBeanDefinition(); - $roleVoter->setBeanClassName('Bee_Security_Vote_RoleVoter'); + $roleVoter->setBeanClassName('Bee\Security\Vote\RoleVoter'); // $authenticatedVoter = new GenericBeanDefinition(); // $authenticatedVoter->setBeanClassName('Bee_Security_Vote_AuthenticatedVoter'); // todo: implement... @@ -41,7 +41,7 @@ $authenticatedVoter*/ ); - $accessMgrBuilder = BeanDefinitionBuilder::rootBeanDefinition('Bee_Security_Vote_AffirmativeBased'); + $accessMgrBuilder = BeanDefinitionBuilder::rootBeanDefinition('Bee\Security\Vote\AffirmativeBased'); $accessMgrBuilder->addPropertyValue('decisionVoters', $defaultVoters); $parserContext->getRegistry()->registerBeanDefinition(Bee_Security_Config_IBeanIds::ACCESS_MANAGER, $accessMgrBuilder->getBeanDefinition()); } Modified: trunk/framework/Bee/Security/ConfigAttributeDefinition.php =================================================================== --- trunk/framework/Bee/Security/ConfigAttributeDefinition.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/ConfigAttributeDefinition.php 2015-02-16 08:02:59 UTC (rev 282) @@ -44,7 +44,7 @@ if(is_string($attr)) { $newList[] = new ConfigAttribute($attr); } else { - Assert::isInstanceOf('IConfigAttribute', $attr, 'List entries must be of type ConfigAttribute'); + Assert::isInstanceOf('Bee\Security\IConfigAttribute', $attr, 'List entries must be of type ConfigAttribute'); $newList[] = $attr; } } Modified: trunk/framework/Bee/Security/Transactions/Interceptor/DefaultTransactionAttribute.php =================================================================== --- trunk/framework/Bee/Security/Transactions/Interceptor/DefaultTransactionAttribute.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Transactions/Interceptor/DefaultTransactionAttribute.php 2015-02-16 08:02:59 UTC (rev 282) @@ -38,4 +38,3 @@ return ($ex instanceof RuntimeException); } } -?> \ No newline at end of file Modified: trunk/framework/Bee/Security/Transactions/Interceptor/DelegatingTransactionAttribute.php =================================================================== --- trunk/framework/Bee/Security/Transactions/Interceptor/DelegatingTransactionAttribute.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Transactions/Interceptor/DelegatingTransactionAttribute.php 2015-02-16 08:02:59 UTC (rev 282) @@ -65,5 +65,4 @@ } -} -?> \ No newline at end of file +} \ No newline at end of file Modified: trunk/framework/Bee/Security/Vote/AbstractAclVoter.php =================================================================== --- trunk/framework/Bee/Security/Vote/AbstractAclVoter.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Vote/AbstractAclVoter.php 2015-02-16 08:02:59 UTC (rev 282) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Vote; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +18,20 @@ use Bee\Utils\Assert; /** - * Created by IntelliJ IDEA. - * User: mp - * Date: Mar 19, 2010 - * Time: 5:30:14 PM - * To change this template use File | Settings | File Templates. + * Class AbstractAclVoter + * @package Bee\Security\Vote */ +abstract class AbstractAclVoter implements IAccessDecisionVoter { -abstract class Bee_Security_Vote_AbstractAclVoter implements Bee_Security_Vote_IAccessDecisionVoter { - /** * @var string */ private $processDomainObjectClass; + /** + * @param $secureObject + * @return mixed + */ protected function getDomainObjectInstance($secureObject) { // Object[] args; // Class[] params; @@ -57,6 +58,9 @@ // + " did not provide any argument of type: " + processDomainObjectClass); } + /** + * @return string + */ public function getProcessDomainObjectClass() { return $this->processDomainObjectClass; } Modified: trunk/framework/Bee/Security/Vote/AbstractDecisionManager.php =================================================================== --- trunk/framework/Bee/Security/Vote/AbstractDecisionManager.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Vote/AbstractDecisionManager.php 2015-02-16 08:02:59 UTC (rev 282) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Vote; /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +21,15 @@ use Bee\Security\IConfigAttribute; use Bee\Utils\Assert; -abstract class Bee_Security_Vote_AbstractDecisionManager implements IAccessDecisionManager, IInitializingBean { +/** + * Class AbstractDecisionManager + * @package Bee\Security\Vote + */ +abstract class AbstractDecisionManager implements IAccessDecisionManager, IInitializingBean { /** * - * @var Bee_Security_Vote_IAccessDecisionVoter[] + * @var IAccessDecisionVoter[] */ private $decisionVoters; @@ -34,10 +39,16 @@ */ private $allowIfAllAbstainDecisions; + /** + * + */ public function afterPropertiesSet() { Assert::isTrue(count($this->decisionVoters) > 0, 'A list of AccessDecisionVoters is required'); } + /** + * @throws AccessDeniedException + */ protected final function checkAllowIfAllAbstainDecisions() { if (!$this->isAllowIfAllAbstainDecisions()) { throw new AccessDeniedException('access_denied'); // @todo: message source @@ -61,17 +72,27 @@ $this->allowIfAllAbstainDecisions = $allowIfAllAbstainDecisions; } + /** + * @return IAccessDecisionVoter[] + */ public function getDecisionVoters() { return $this->decisionVoters; } + /** + * @param IAccessDecisionVoter[]|array $decisionVoters + */ public function setDecisionVoters(array $decisionVoters) { foreach($decisionVoters as $voter) { - Assert::isInstanceOf('Bee_Security_Vote_IAccessDecisionVoter', $voter, 'AccessDecisionVoter ' . get_class($voter) . ' must implement Bee_Security_Vote_IAccessDecisionVoter'); + Assert::isInstanceOf('Bee\Security\Vote\IAccessDecisionVoter', $voter, 'AccessDecisionVoter ' . get_class($voter) . ' must implement Bee\Security\Vote\IAccessDecisionVoter'); } $this->decisionVoters = $decisionVoters; } + /** + * @param IConfigAttribute $configAttribute + * @return bool + */ public function supports(IConfigAttribute $configAttribute) { foreach($this->decisionVoters as $voter) { if($voter->supports($configAttribute)) { @@ -81,6 +102,10 @@ return false; } + /** + * @param string $className + * @return bool + */ public function supportsClass($className) { foreach($this->decisionVoters as $voter) { if(!$voter->supportsClass($className)) { Modified: trunk/framework/Bee/Security/Vote/AclEntryVoter.php =================================================================== --- trunk/framework/Bee/Security/Vote/AclEntryVoter.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Vote/AclEntryVoter.php 2015-02-16 08:02:59 UTC (rev 282) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Vote; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +28,7 @@ use Bee\Security\IAuthentication; use Bee\Security\IConfigAttribute; use Bee\Utils\Strings; +use Logger; /** * Created by IntelliJ IDEA. @@ -36,7 +38,7 @@ * To change this template use File | Settings | File Templates. */ -class Bee_Security_Vote_AclEntryVoter extends Bee_Security_Vote_AbstractAclVoter { +class Bee_Security_Vote_AclEntryVoter extends AbstractAclVoter { /** * @var Logger @@ -83,6 +85,11 @@ */ private $requirePermission; + /** + * @param IAclService $aclService + * @param $processConfigAttribute + * @param array $requirePermission + */ public function __construct(IAclService $aclService, $processConfigAttribute, array $requirePermission) { @@ -135,13 +142,22 @@ $this->sidRetrievalStrategy = $sidIdentityRetrievalStrategy; } + /** + * @param IConfigAttribute $configAttribute + * @return bool + */ public function supports(IConfigAttribute $configAttribute) { return $configAttribute->getAttribute() == $this->getProcessConfigAttribute(); } + /** + * @param IAuthentication $authentication + * @param mixed $object + * @param ConfigAttributeDefinition $config + * @return int + * @throws GenericSecurityException + */ public function vote(IAuthentication $authentication, $object, ConfigAttributeDefinition $config) { - - foreach($config->getConfigAttributes() as $attr) { if (!$this->supports($attr)) { @@ -216,6 +232,5 @@ // No configuration attribute matched, so abstain return self::ACCESS_ABSTAIN; - } } \ No newline at end of file Modified: trunk/framework/Bee/Security/Vote/AffirmativeBased.php =================================================================== --- trunk/framework/Bee/Security/Vote/AffirmativeBased.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Vote/AffirmativeBased.php 2015-02-16 08:02:59 UTC (rev 282) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Vote; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +19,20 @@ use Bee\Security\ConfigAttributeDefinition; use Bee\Security\Exception\AccessDeniedException; use Bee\Security\IAuthentication; +use Bee\Security\Vote\IAccessDecisionVoter; -class Bee_Security_Vote_AffirmativeBased extends Bee_Security_Vote_AbstractDecisionManager { +/** + * Class AffirmativeBased + * @package Bee\Security\Vote + */ +class AffirmativeBased extends AbstractDecisionManager { + + /** + * @param IAuthentication $authentication + * @param mixed $object + * @param ConfigAttributeDefinition $configAttributes + * @throws AccessDeniedException + */ public function decide(IAuthentication $authentication, $object, ConfigAttributeDefinition $configAttributes) { $deny = 0; @@ -27,9 +40,9 @@ $result = $voter->vote($authentication, $object, $configAttributes); switch($result) { - case Bee_Security_Vote_IAccessDecisionVoter::ACCESS_GRANTED: + case IAccessDecisionVoter::ACCESS_GRANTED: return; - case Bee_Security_Vote_IAccessDecisionVoter::ACCESS_DENIED: + case IAccessDecisionVoter::ACCESS_DENIED: $deny++; break; default: Modified: trunk/framework/Bee/Security/Vote/IAccessDecisionVoter.php =================================================================== --- trunk/framework/Bee/Security/Vote/IAccessDecisionVoter.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Vote/IAccessDecisionVoter.php 2015-02-16 08:02:59 UTC (rev 282) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Vote; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +29,7 @@ * </p> * */ -interface Bee_Security_Vote_IAccessDecisionVoter { +interface IAccessDecisionVoter { const ACCESS_GRANTED = 1; const ACCESS_ABSTAIN = 0; Modified: trunk/framework/Bee/Security/Vote/RoleVoter.php =================================================================== --- trunk/framework/Bee/Security/Vote/RoleVoter.php 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/Bee/Security/Vote/RoleVoter.php 2015-02-16 08:02:59 UTC (rev 282) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Vote; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +45,7 @@ * All comparisons and prefixes are case sensitive. * */ -class Bee_Security_Vote_RoleVoter implements Bee_Security_Vote_IAccessDecisionVoter { +class RoleVoter implements IAccessDecisionVoter { private $rolePrefix = "ROLE_"; @@ -65,14 +66,28 @@ $this->rolePrefix = $rolePrefix; } + /** + * @param IConfigAttribute $configAttribute + * @return bool + */ public function supports(IConfigAttribute $configAttribute) { return Strings::startsWith($configAttribute->getAttribute(), $this->rolePrefix); } + /** + * @param $className + * @return bool + */ public function supportsClass($className) { return true; } + /** + * @param IAuthentication $authentication + * @param mixed $object + * @param ConfigAttributeDefinition $config + * @return int + */ public function vote(IAuthentication $authentication, $object, ConfigAttributeDefinition $config) { $result = self::ACCESS_ABSTAIN; @@ -89,7 +104,11 @@ return $result; } - + + /** + * @param IAuthentication $authentication + * @return string[] + */ protected function extractAuthorities(IAuthentication $authentication) { return $authentication->getAuthorities(); } Modified: trunk/framework/acl-default.xml =================================================================== --- trunk/framework/acl-default.xml 2015-02-12 09:08:08 UTC (rev 281) +++ trunk/framework/acl-default.xml 2015-02-16 08:02:59 UTC (rev 282) @@ -123,10 +123,10 @@ </constructor-arg> </bean> - <bean id="accessDecisionManager" class="Bee_Security_Vote_AffirmativeBased"> + <bean id="accessDecisionManager" class="Bee\Security\Vote\AffirmativeBased"> <property name="decisionVoters"> <array> - <bean class="Bee_Security_Vote_RoleVoter"/> + <bean class="Bee\Security\Vote\RoleVoter"/> <ref bean="aclVoterRead" /> <ref bean="aclVoterWrite" /> <ref bean="aclVoterCreate" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |