Parcourir la source

ZF-11715: remove use of create_function in preference to explicit method

- Added static method resolveElementId() to Zend_Form_Element
- Modified loadDefaultDecorators() to remove usage of create_function
  and instead pass a callback referencing resolveElementId()
- Updated HtmlTag decorator to use call_user_func() to allow any type of
  callback

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24427 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew il y a 14 ans
Parent
commit
d104742bd1
2 fichiers modifiés avec 20 ajouts et 7 suppressions
  1. 3 2
      library/Zend/Form/Decorator/HtmlTag.php
  2. 17 5
      library/Zend/Form/Element.php

+ 3 - 2
library/Zend/Form/Decorator/HtmlTag.php

@@ -85,8 +85,9 @@ class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
             $key = htmlspecialchars($key, ENT_COMPAT, $enc);
             if (is_array($val)) {
                 if (array_key_exists('callback', $val)
-                    && is_callable($val['callback'])) {
-                    $val = $val['callback']($this);
+                    && is_callable($val['callback'])
+                ) {
+                    $val = call_user_func($val['callback'], $this);
                 } else {
                     $val = implode(' ', $val);
                 }

+ 17 - 5
library/Zend/Form/Element.php

@@ -315,20 +315,32 @@ class Zend_Form_Element implements Zend_Validate_Interface
 
         $decorators = $this->getDecorators();
         if (empty($decorators)) {
-            $getId = create_function('$decorator',
-                                     'return $decorator->getElement()->getId()
-                                             . "-element";');
             $this->addDecorator('ViewHelper')
                  ->addDecorator('Errors')
                  ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
-                 ->addDecorator('HtmlTag', array('tag' => 'dd',
-                                                 'id'  => array('callback' => $getId)))
+                 ->addDecorator('HtmlTag', array(
+                     'tag' => 'dd',
+                     'id'  => array('callback' => array(get_class($this), 'resolveElementId'))
+                 ))
                  ->addDecorator('Label', array('tag' => 'dt'));
         }
         return $this;
     }
 
     /**
+     * Used to resolve and return an element ID
+     *
+     * Passed to the HtmlTag decorator as a callback in order to provide an ID.
+     * 
+     * @param  Zend_Form_Decorator_Interface $decorator 
+     * @return string
+     */
+    public static function resolveElementId(Zend_Form_Decorator_Interface $decorator)
+    {
+        return $decorator->getElement()->getId() . '-element';
+    }
+
+    /**
      * Set object state from options array
      *
      * @param  array $options