Skip to content

Version 2.1: Added IsClassCollectionType and more

Choose a tag to compare

@FireMidge FireMidge released this 16 Jul 00:02
· 6 commits to master since this release
1cf9066

What's new?

Feature: Added the following methods to all the array types (IsArrayEnumType, IsCollectionType, IsIntArrayEnumType, IsStringArrayEnumType, IsClassCollectionType):

  • count: Returns the number of elements inside the array value object.
  • isEmpty: Whether the value object contains any elements.
  • isNotEmpty: The opposite of isEmpty.
  • isEqualTo: Whether the value object's elements are equal to the argument. The argument can be another class (with a toArray method), an array, or an object with public properties.
  • isNotEqualTo: The opposite of isEqualTo.
  • empty: A factory method to create a new instance with no elements.

Feature: Added a new value type: IsClassCollectionType.
This adds on to IsCollectionType and makes it easier to create a collection holding an array of objects. It validates whether the items are of a specific class. By default, it does not allow duplicate values, however this can be overridden.

Feature: Added a small helper trait CanBeConvertedToStringArray, which can convert an array type into an array of scalar string values. Useful when using IsClassCollectionType with a class implementing the __toString method.

What's changed?

Feature: Adding duplicate values can now be ignored, by overriding the protected static function ignoreDuplicateValues() : bool method and returning true. To be backwards-compatible, it returns false by default.
When this method returns true, then any duplicate values will be ignored and simply not added to the collection; without throwing an exception.

Dev: Separate exception for duplicate values: DuplicateValue.
It is backwards compatible as it extends from InvalidValue, but it does now allow developers to catch this exception separately.