Zend Framework 3 BC-breaks

  • 发布时间 2015-02-03
  • 分类 php

BC-breaks => Backwards Compatibility Breaks => 向后兼容性的破坏

Input Filters

[php] $inputCollection = new InputCollection(); $validationGroup = new ArrayFilterIterator($inputCollection, ['field1', 'field2']); $inputCollection->setValidationGroupFilter($validationGroup); [/php] 虽然代码需要多打一些,但更高效,灵活。ZF3自带的几个内置的验证组过滤迭代器:NoOpFilterIterator,ArrayFilterIterator,CallableFilterIterator和RegexFilterIterator

[php] // ... create the input collection $inputFilterResult = $inputCollection->runAgainst(['field1' => 'value1']); if ($inputFilterResult->isValid()) { $values = $inputFilterResult->getData(); // 或者使用 getRawData(); } else { $error = $inputFilterResult->getErrorMessages(); } [/php] InputFilterResult是可序列化,也实现PHP 5.4 JsonSerializable接口,所以你可以json_encode($inputFilterResult),它会自动序列化的错误消息。

Filters(过滤器)

Validators(验证)

Event manager(事件管理器)

RBAC

Hydrators

Forms

Service manager

Module manager