Zend Framework: Migrating from 1.8 to 1.9

I just updated tine20 to use the latest stable Zend Framework version (1.9.1). Similarly to upgrading from 1.6 to 1.8 the upgrade from 1.8.4 to 1.9.1 went pretty painless except some validation problems:

Zend_Validate_NotEmpty regards objects as empty values

In Revision 15951 the Zend_Validate_NotEmpty validator was changed in order to fix http://framework.zend.com/issues/browse/ZF-4352.

Now validation fails if the validated value is neither a float, string, or integer. So objects are treated like empty values and therefore do not pass the NotEmpty validation. However, I think objects should be OK, too. So I patched the Zend_Validate_NotEmpty validator class:

Index: tine20/library/Zend/Validate/NotEmpty.php
===================================================================
--- tine20/library/Zend/Validate/NotEmpty.php    (revision 10030)
+++ tine20/library/Zend/Validate/NotEmpty.php    (working copy)
@@ -40,7 +40,7 @@
*/
protected $_messageTemplates = array(
self::IS_EMPTY => "Value is required and can't be empty",
-  self::INVALID  => "Invalid type given, value should be float, string, or integer",
+  self::INVALID  => "Invalid type given, value should be float, string, integer or an object",
);

/**
@@ -53,7 +53,7 @@
*/
public function isValid($value)
{
-  if (!is_string($value) && !is_int($value) && !is_float($value) && !is_bool($value)) {
+  if (!is_string($value) && !is_int($value) && !is_float($value) && !is_bool($value) && !is_object($value)) {
$this->_error(self::INVALID);
return false;
}

UPDATE:
Note that in Zend Framework version 1.9.2 the NotEmpty Validator was adjusted and now allows arrays but it is said that objects do intentionally not pass the NotEmpty validator: http://framework.zend.com/issues/browse/ZF-7631

So it looks like we have to adjust our source code to not validate objects using the Zend_Validate_NotEmpty class.

Zend_Validate_Digits

Zend_Validate_Digits now also checks the type of the value to validate and only accepts strings, integers and floats. Before Zend Framework 1.9 the datatype was implicitly cast string and therefore you could also validate objects like SimpleXMLElements. To get the tine20 setup working again I had to explicitly cast the SimpleXMLElements to the desired datatype (i.e. string) before passing them to the validator.

Zend_Locale: Deprecated translation methods

See http://framework.zend.com/manual/en/zend.locale.migration.html#zend.locale.migration.fromoneeighttoonenine.

Helpful links::

Tags: ,

Leave a Reply