Closed giuscris closed 1 year ago
This PR changes how Formwork handles data classes, using traits and interfaces to add and enforce behavior.
All the new traits enforce a $data as:
$data
protected array $data = [];
Arrayable
ArraySerializable
fromArray()
Formwork\Parsers\PHP
DataArrayable
toArray()
DataCountable
count()
\Countable
DataIterator
\Iterator
DataCountableIterator
DataGetter
has()
get()
DataSetter
set()
remove()
DataMultipleGetter
hasMultiple()
getMultiple()
DataMultipleSetter
setMultiple()
removeMultiple()
This PR changes how Formwork handles data classes, using traits and interfaces to add and enforce behavior.
All the new traits enforce a
$data
as:New interfaces
Arrayable
used in classes that export data to arraysArraySerializable
enforces a static methodfromArray()
to generate class instances, will be used in future inFormwork\Parsers\PHP
New traits
DataArrayable
implementstoArray()
method returning$data
as an array, required byArrayable
DataCountable
implements acount()
method returning the count of$data
, required by\Countable
interface (see https://www.php.net/manual/en/class.countable.php)DataIterator
implements an iterator on$data
elements, required by\Iterator
interface (see https://www.php.net/manual/en/class.iterator.php)DataCountableIterator
is a composition ofDataCountable
andDataIterator
DataGetter
implementshas()
andget()
methodsDataSetter
implementsset()
andremove()
methodsDataMultipleGetter
implementshasMultiple()
andgetMultiple()
extendingDataGetter
DataMultipleSetter
implementssetMultiple()
andremoveMultiple()
extendingDataSetter