From 7f40d0314c724d2aead9472f3a61bf5e5c3b1a2e Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@afi-sa.fr> Date: Fri, 7 Apr 2017 10:09:29 +0200 Subject: [PATCH] dev #48349 : fix rt --- library/ZendAfi/Form.php | 30 +------------ library/ZendAfi/Form/VersionHelper.php | 58 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 library/ZendAfi/Form/VersionHelper.php diff --git a/library/ZendAfi/Form.php b/library/ZendAfi/Form.php index 44c84e6b96f..da66f1ebe83 100644 --- a/library/ZendAfi/Form.php +++ b/library/ZendAfi/Form.php @@ -226,39 +226,11 @@ class ZendAfi_Form extends Zend_Form { public function beVersionCompare($datas) { - foreach($this->getElements() as $element) - $element->setDecorators([$this->_versionCompareDecoratorFor($element, $datas)]); - + (new ZendAfi_Form_VersionHelper())->prepare($this, $datas); return $this; } - protected function _versionCompareDecoratorFor($element, $datas) { - $class_name = $this->_specificClassFor($element, - 'ZendAfi_Form_Decorator_VersionCompare'); - return new $class_name(['datas' => $datas]); - } - - - protected function _specificClassFor($element, $base_class) { - try { - $specific = $base_class . '_' . $this->_getElementType($element); - Zend_Loader::loadClass($specific); - $base_class = $specific; - } catch(Exception $e) { - // couldn't load, will default to generic class name - } - - return $base_class; - } - - - protected function _getElementType($element) { - $parts = explode('_', get_class($element)); - return end($parts); - } - - public static function keepValueParamName($id='') { return 'keepValueOf_'.$id; } diff --git a/library/ZendAfi/Form/VersionHelper.php b/library/ZendAfi/Form/VersionHelper.php new file mode 100644 index 00000000000..3706198c754 --- /dev/null +++ b/library/ZendAfi/Form/VersionHelper.php @@ -0,0 +1,58 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Form_VersionHelper { + public function prepare($form, $datas) { + foreach($form->getElements() as $element) + $this->_prepareElement($element, $datas); + } + + + protected function _prepareElement($element, $datas) { + $element->setDecorators([$this->_decoratorFor($element, $datas)]); + } + + + protected function _decoratorFor($element, $datas) { + $class_name = $this->_classFor($element, 'ZendAfi_Form_Decorator_VersionCompare'); + return new $class_name(['datas' => $datas]); + } + + + protected function _ClassFor($element, $base_class) { + try { + $specific = $base_class . '_' . $this->_getElementType($element); + Zend_Loader::loadClass($specific); + $base_class = $specific; + } catch(Exception $e) { + // couldn't load, will default to generic class name + } + + return $base_class; + } + + + protected function _getElementType($element) { + $parts = explode('_', get_class($element)); + return end($parts); + } +} -- GitLab