CollectionTrait

trait atk4\core\CollectionTrait
This trait makes it possible for you to add child objects
into your object, but unlike “ContainerTrait” you can use
multiple collections stored as different array properties.
This class does not offer automatic naming, so if you try
to add another element with same name, it will result in
exception.
Source:vendor/atk4/core/src/CollectionTrait.php#14

Methods

public atk4\core\CollectionTrait::_addIntoCollection($name, $object, $collection)
Use this method trait like this:.
function addField($name, $definition) {
$field = $this->factory($definition, [], ‘\atk4\data\Field’);

return $this->_addIntoCollection($name, $field, ‘fields’);
}
Source:

vendor/atk4/core/src/CollectionTrait.php#33

Parameters:
  • $name (string) Name that can be used to reference object
  • $object (object) New element to add
  • $collection (string) string String corresponding to the name of the property
Throws:

\atk4\core\Exception

Returns:

object | mixed $obect

public atk4\core\CollectionTrait::_removeFromCollection($name, $collection)
Removes element from specified collection.
Source:

vendor/atk4/core/src/CollectionTrait.php#98

Parameters:
  • $name (string)
  • $collection (string)
Throws:

\atk4\core\Exception

public atk4\core\CollectionTrait::_cloneCollection($collection)
Call this on collections after cloning object. This will clone all collection
elements (which are objects).
Source:

vendor/atk4/core/src/CollectionTrait.php#117

Parameters:
  • $collection (string) to be cloned
public atk4\core\CollectionTrait::_hasInCollection($name, $collection)
Returns object from collection or false if object is not found.
Source:

vendor/atk4/core/src/CollectionTrait.php#135

Parameters:
  • $name (string)
  • $collection (string)
Returns:

object | bool

public atk4\core\CollectionTrait::_getFromCollection($name, $collection)
Source:

vendor/atk4/core/src/CollectionTrait.php#148

Parameters:
  • $name (string)
  • $collection (string)
Throws:

\atk4\core\Exception

Returns:

object

protected atk4\core\CollectionTrait::_shorten_ml($desired)
Method used internally for shortening object names
Identical implementation to ContainerTrait::_shortern.
Source:

vendor/atk4/core/src/CollectionTrait.php#171

Parameters:
  • $desired (string) Desired name of new object.
Returns:

string Shortened name of new object.