cscfa_tool_division/collections

This bundle provide collections class and method to store data

V1.0.1 2016-11-29 06:52 UTC

This package is not auto-updated.

Last update: 2024-11-08 22:54:28 UTC


README

This bundle provide a set of collection class to abstract the usage of the array and provide advanced inheritance and logic.

Structure of a collection

The collections of this bundle are created from the following architecture :

  • Interface
  • Method traits
  • Abstract class
  • Concrete class

The Interface are childs of the CollectionInterface and defined the public methods of the collections.

The method trait define the logic of the collections. They need a 'content' property to be used. So the functionnal storage property of a collection must be named 'content' and be an array.

The Abstract class is a container for the traits and define the 'content' property.

The Concrete class is usable 'as it'.

Available collections

Abstract collection

Value collection

Map collection

Container collection

Value set

The collection helper

The collection helper take care of the advanced behaviour of the collection logic. It allow to merge, cut, traverse and create collections from array. This helper is a service and can be getted by it's id 'collection.helper.std'.

You will be able to use the following methods :

To work fine, the collection helper need a array caster that support the given collection. If you create your own collection and want to use it into the helper, you must create an array caster for your collection. Note the existing casters support the MapCollectionInterface childs and ValueCollectionInterfaceChilds.

Create an array caster

The array caster need to implement the ArrayCasterInterface. It define two methods :

  • support($class) : check if the given class name is supported by the array caster. It must return true or false.
  • toCollection(array $array, $class) : create a collection of the given class with the content of the array as content.

After your caster created, you must register it at a service, with the 'collection.helper.caster' tag. The bundle will automatically register it into the array caster manager of the helpers.

A note of quality check

SensioLabsInsight

✅ phpcs tested

✅ phpmd tested (full rules)

✅ phpdcd tested

✅ phpcpd tested

✅ phpunit tested (code coverage done)

See the doc :