-
Notifications
You must be signed in to change notification settings - Fork 0
ZF 3.0 Backwards Compatibility Breaks
This page should be used for listing all of the known backwards compatibility breaks being introduced in ZF3. As each change is introduced in a PR, it should be added to this page so that we can eventually make a comprehensive ZF2->ZF3 migration guide.
- InputFilter component were rewrite with performance in mind and to clean the massive amount of code that was added through the time.
- InputFilter class have been renamed to InputCollection to better reflect its purpose.
- InputCollection now just extends Input, so they can have validators and filters attached.
- Validation groups are now completely decoupled from the input collection. For instance, if you want to create an array validation group (previous default behaviour):
$inputCollection = new InputCollection();
$validationGroup = new ArrayFilterIterator($inputCollection, array('field1', 'field2'));
$inputCollection->setValidationGroupFilter($validationGroup);
This requires a bit more typing but is much more efficient and flexible. ZF3 comes with several built-in validation group filter iterators: NoOpFilterIterator, ArrayFilterIterator, CallableFilterIterator and RegexFilterIterator.
- Input and InputCollection are now completely stateless. This has several implications. First of all, the same input collection or input can be reused multiple times, hence reducing the need to have shared instances. Validation result and filtered value are wrapped around an "InputFilterResult" object, that defines the isValid, getRawData, getData and getErrorMessages methods:
// ... create the input collection
$inputFilterResult = $inputCollection->runAgainst(array('field1' => 'value1'));
if ($inputFilterResult->isValid()) {
$values = $inputFilterResult->getData(); // or getRawData();
} else {
$error = $inputFilterResult->getErrorMessages();
}
InputFilterResult is serializable and also implement PHP 5.4 JsonSerializable interface, so you can do: json_encode($inputFilterResult), and it will automatically serialize the error messages.
-
The InputCollection now does less things and has lost some minor functionalities. However, as the new architecture is much more flexible and decoupled, it should be easier to create your own logic without touching the codebase.
-
The InputFilterPluginManager has various factories for Input and InputCollection.
-
TODO: check code for complex uses cases
-
TODO: write tests
-
TODO: backport FileInput
-
TODO: add a "FallbackValue" filter to replace the fallback feature that was (wrongly) in Input class.
-
TODO: check architecture, if we can optimize some things or if some very important features are missing.
-
All filters are now Callable (they implement __invoke()) method.
-
Various options now are underscore_separated, like other part of framework.
-
Some filters were rewritten to reduce code and improve performance.
-
Tar and Gz filters: the method "setMode"/"getMode" were renamed "setCompressionMode"/"getCompressionMode" for clarity.
-
Rename filter has been removed in favour of the more featured "RenameUpload" filter.
-
StripTags filter: setTagsAllowed has been renamed to setAllowedTags. setAttributesAllowed has been renamed to setAllowedAttributes.
-
Encrypt/decrypt filters no longer compress/decompress. You should add another filter for that.
-
Encrypt/decrypt filters have been moved to the Zend\Crypt namespace.
-
TODO: rewrite some complex filters like Inflector.
-
TODO: more integration with plugin managers.
- Validators are now stateless.
- All options now follow the ZF2 convention and are underscore_separated (so "messageTemplates" become "message_templates").
- Validators no longer have a "isValid" method. Instead, you must call "validate" method on each validator, that returns a ValidationResult object. This object is serializable, translatable, and offers a "isValid" method.
- Validators no longer offer an option to set the minimum length of messages. This should be handled by a view helper.
- DateStep validator no longer extends Date validator.
- CreditCard validation: option "type" has been renamed to "allowed_types" to better reflect what it does
- propagationIsStopped method has been renamed to isPropagationStopped.
- StaticEventManager has been removed.
- You cannot any longer emulate triggerUntil with trigger method. Use triggerUntil only if you need a callback.
- "attach" method no longer accepts a ListenerAggregateInterface. Use the attachAggregate method instead.
- Rbac and Role no longer implements RecursiveIterator. Instead, RoleInterface implements the simpler and much more efficient IteratorAggregate interface. But it's only internal changes, should not affect anyone. As a side effect, the AbstractIterator class no longer exists.
- AbstractRole no longer accept a string for the "addRole" method: you must give a RoleInterface (previously, it created a Role object automatically if role was a string, but it introduced a curious thing where the abstract class created a children object). However, adding role using a string directly in the Rbac container is still supported. So this change is pretty minor.