Skip to content
Browse files

Merge branch 'hotfix/zf2-512' into develop

Forward port #2276
  • Loading branch information...
2 parents 8d6b054 + e3ba6ea commit 8faecee9bee6e9c525c9b2d4bcc9238850e686bb @weierophinney weierophinney committed Sep 20, 2012
View
15 library/Zend/Filter/FilterChain.php
@@ -228,11 +228,22 @@ public function filter($value)
/**
* Clone filters
- *
- * @return void
*/
public function __clone()
{
$this->filters = clone $this->filters;
}
+
+ /**
+ * Prepare filter chain for serialization
+ *
+ * Plugin manager (property 'plugins') cannot
+ * be serialized. On wakeup the property remains unset
+ * and next invokation to getPluginManager() sets
+ * the default plugin manager instance (FilterPluginManager).
+ */
+ public function __sleep()
+ {
+ return array('filters');
+ }
}
View
9 library/Zend/Validator/ValidatorChain.php
@@ -234,14 +234,15 @@ public function __invoke($value)
/**
* Prepare validator chain for serialization
*
- * ValidatorPluginManager cannot be serialized, as it contains Traits. For
- * this reason property 'plugins' is excluded and thus serialized
- * filter chain is not necessarily equal to current chain.
+ * Plugin manager (property 'plugins') cannot
+ * be serialized. On wakeup the property remains unset
+ * and next invokation to getPluginManager() sets
+ * the default plugin manager instance (ValidatorPluginManager).
*
* @return array
*/
public function __sleep()
{
- return array('validators', 'messages');
+ return array('validators','messages');
}
}
View
15 tests/ZendTest/Filter/FilterChainTest.php
@@ -168,6 +168,21 @@ public function testClone()
$this->assertCount(0, $clone);
}
+
+ public function testCanSerializeFilterChain()
+ {
+ $chain = new FilterChain();
+ $chain->attach(new LowerCase())
+ ->attach(new StripUpperCase());
+ $serialized = serialize($chain);
+
+ $unserialized = unserialize($serialized);
+ $this->assertInstanceOf('Zend\Filter\FilterChain', $unserialized);
+ $this->assertEquals(2, count($unserialized));
+ $value = 'AbC';
+ $valueExpected = 'abc';
+ $this->assertEquals($valueExpected, $unserialized->filter($value));
+ }
}
View
12 tests/ZendTest/Validator/ValidatorChainTest.php
@@ -274,4 +274,16 @@ public function testCanAttachMultipleValidatorsOfTheSameTypeAsDiscreteInstances(
}
$this->assertTrue($found);
}
+
+
+ public function testCanSerializeValidatorChain()
+ {
+ $this->populateValidatorChain();
+ $serialized = serialize($this->validator);
+
+ $unserialized = unserialize($serialized);
+ $this->assertInstanceOf('Zend\Validator\ValidatorChain', $unserialized);
+ $this->assertEquals(2, count($unserialized));
+ $this->assertFalse($unserialized->isValid(''));
+ }
}

0 comments on commit 8faecee

Please sign in to comment.
Something went wrong with that request. Please try again.